//tracking pages
 function homeIndex(){
 	var hoIn = window.open("index.html?PID=" + getURLParam('PID'), "_self");
 }
 function internet(){
 	var inter = window.open("internet.html?PID=" + getURLParam('PID'), "_self");
 }
  function voice(){
 	var voi = window.open("voice.html?PID=" + getURLParam('PID'), "_self");
 }
  function cable(){
 	var cab = window.open("cable.html?PID=" + getURLParam('PID'), "_self");
 }
 
 //split test
  function homeIndex2(){
 	var hoIn = window.open("index2.html?PID=" + getURLParam('PID'), "_self");
 }
 function internet2(){
 	var inter = window.open("internet2.html?PID=" + getURLParam('PID'), "_self");
 }
  function voice2(){
 	var voi = window.open("voice2.html?PID=" + getURLParam('PID'), "_self");
 }
  function cable2(){
 	var cab = window.open("cable2.html?PID=" + getURLParam('PID'), "_self");
 }
 
  function hdtv(){
 	var ht = window.open("http://www.yourhdexperience.com/index.php?PID=" + getURLParam('PID'), "_blank");
 }
  function gaming(){
 	var game = window.open("http://www.yourgamingexperience.com/index.html?PID=" + getURLParam('PID'), "_blank");
 }
  function acer(){
 	var ht = window.open("http://www.acerspecial.com/index.php?PID=" + getURLParam('PID'), "_blank");
 }
 
  function linkage(thelink, windowopen, specialprop){
	   if(specialprop == "true"){
		   var tl = window.open(thelink + "?PID=" + getURLParam('PID'), windowopen, 'top=10,left=20,scrollbars=yes,width=575,height=480,menubar=no,toolbar=no,status=no,location=no;resizable=yes;');
	   }
	   else{
		   if(windowopen == null){
			if(getURLParam('adused') != ''){
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID') + "&adused=" + getURLParam('adused'), '_self');
			}
			else if(getURLParam('AdID') != ''){
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID') + "&adused=" + getURLParam('AdID'), '_self');
			}
			else{
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID'), '_self');
			}
			exit = false;
		   }
		   else{
			if(getURLParam('adused') != ''){
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID') + "&adused=" + getURLParam('adused'), windowopen);
			}
			else if(getURLParam('AdID') != ''){
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID') + "&adused=" + getURLParam('AdID'), windowopen);
			}
			else{
				var t2 = window.open(thelink + "?PID=" + getURLParam('PID'), windowopen);
			} 
		   }
	   }
 }
 
//radio buttons
function checkradioHome()
{
	document.form1.rbhome.checked=true
	document.form1.rbbusiness.checked=false
	document.getElementById('hidethis').style.display = '';
	document.getElementById('hidethis2').style.display = '';
	document.getElementById('hidethis3').style.display = '';
	document.getElementById('require').style.display = '';
	document.getElementById('contactstuff').style.display = 'none';
	document.getElementById('contactstuff2').style.display = 'none';
	document.form1.email.style.fontWeight = 'bold';
}

function checkradioBusiness()
{
	document.form1.rbhome.checked=false
	document.form1.rbbusiness.checked=true
	document.getElementById('hidethis').style.display = 'none';
	document.getElementById('hidethis2').style.display = 'none';
	document.getElementById('hidethis3').style.display = 'none';
	document.getElementById('require').style.display = 'none';
	document.getElementById('contactstuff').style.display = '';
	document.getElementById('contactstuff2').style.display = '';
	document.form1.email.style.fontWeight = '';
}

//PID stuffies
function getURLParam( name ){

  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function staticLoadScript(url)
{
   document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}

function SetPartnerID(str)
{
	var partner_id
    if ( getURLParam('id') != '' ){
	    partner_id = getURLParam('id');
    }
    else{
	    partner_id = str;
    }
    if ( getURLParam('PID') != '' ){
	    if (partner_id.indexOf("-") > -1) {
	        partner_id = partner_id + ':' + getURLParam('PID')
        }
        else
        {
	        partner_id = partner_id + '-' + getURLParam('PID')
        }
    }
    return partner_id
}

function checkVal1(newPID){
	var pidSplit = newPID.split(':');

	return pidSplit[1];
}

function checkVal2(newPID){
	var pidSplit = newPID.split(':');

	return pidSplit[0];
}

function checkVal3(newPID){
	var pidSplit = newPID.split(':');

	return pidSplit[2];
}

function checkVal4(newPID){
	var pidSplit = newPID.split(':');

	return pidSplit[3];
}

//Get Referring URL Domain
function GetRefDomain()
{  
  var referrer = GetReferringPage();
  if (!referrer) {
    return false;
  }
  
  var dashLoc = referrer.indexOf('.');                    //grab the engine from the URL
  var dashLoc2;
  var front;                                                    
  var rest;
  var refDir;
  var len = referrer.length;
  if (dashLoc > 0){
	front = referrer.substr(0, dashLoc);
	rest = referrer.substr(dashLoc + 1, len);
	dashLoc2 = rest.indexOf('.');
	if (dashLoc2 > 0){
		refDir = rest.substr(0, dashLoc2);
	}
  }                                                      //end of said grabbing
  
  /*var queryPrefix = DeterminPreFix(referrer);
  alert("referrer is: " + referrer + "\nqueryPrefix is: " + queryPrefix);
  if (!queryPrefix)
  {
  	return false;
  }
  
  var startPos = referrer.toLowerCase().indexOf(queryPrefix);
  if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
    return false;
  }
  
  var endPos = referrer.indexOf("&", startPos);
  if (endPos < 0) {
    endPos = referrer.length;
  }
  
  var queryString = referrer.substring(startPos + queryPrefix.length, endPos);

  queryString = queryString.replace(/(%22)(.*?)(%22)/gi, function(x,y,z) {return z.replace(/\+/gi," ")});
  queryString = queryString.replace(/(\")(.*?)(\")/gi, function(x,y,z) {return z.replace(/\+/gi," ")});
  
  queryString = queryString.replace(/%20/gi, ", ");
  queryString = queryString.replace(/\+/gi, ", ");

  queryString = queryString.replace(/%22/gi, "");
  queryString = queryString.replace(/\"/gi, "");
  
  queryString = queryString.replace(/%28/gi, "");
  queryString = queryString.replace(/\(/gi, "");
  
  queryString = queryString.replace(/%29/gi, "");
  queryString = queryString.replace(/\)/gi, "");*/
  
  return refDir;
}

/*function DeterminPreFix(referrerString)
{
      
  if (!referrerString) {
  	return false;
  }
  // used by google, Live (msn), Ask (google), altavista (yahoo), iwon (google)
  else if (referrerString.indexOf("q=") >= 0) 
  {
  	return "q=";
  }
  // used by yahoo,
  else if (referrerString.indexOf("p=") >= 0) 
  {
  	return "p=";
  }
  // used by AOL (google), Netscape (google), Lycos (google)
  else if (referrerString.indexOf("query=") >= 0) 
  {
  	return "query=";
  }
  // dmoz (google)
  else if (referrerString.indexOf("search=") >= 0) 
  {
  	return "search=";
  }
  else
  {
  	return false;
  }
}*/


function DeterminReferringDomain()
{
  var referrerString = GetReferringPage();

  if (!referrerString) {
    return false;
  }
  
  var strSplit = referrerString.split("/");
  
  if (strSplit[2].length == 0) 
  {
  	return "Unknown";
  }
  else
  {
  	return strSplit[2];
  }
  
}

function GetReferringPage()
{
  var referrerString = document.referrer.toLowerCase();

  // Test Values:
  //var referrerString = "http://www.complaints.com/directory/2006/march/21/23.htm";

  return referrerString;
}

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
	//create UserGUID in lead database
	$(document).ready(function(){
		$.post("js/proxy2.php?proxy_url=http://www.bandwidthnational.com/cw/api/lead_api_create.php", {}, function(text){
			
			/*if(text.xml) {
				text=(text.xml);   // XML to String  for IE
			}else{
				text=(new XMLSerializer().serializeToString(text));  // XML to String for Firefox,etc browsers
			}*/
			//alert(text);
			createCookie("UserGUID", text, 1); 	
			uGUID = readCookie("UserGUID");
			document.IndexForm.userId.value = text;					
		});
	});
   //return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*var uGUID = readCookie("UserGUID");
if (uGUID == null){
	guid();
}
else{
	
	//use GUID to return previous lead info, if exists	
	$(document).ready(function(){
		$.post("js/proxy2.php?proxy_url=http://www.bandwidthnational.com/cw/api/lead_api_fetch.php", {UserID: uGUID}, function(text){
			//alert(text);
			var splitText = text.split(";");
			
			if(splitText.length != 0){
				document.IndexForm.txtHomeStreetAddress1.value = splitText[1];
				document.IndexForm.txtHomeStreetAddress2.value = splitText[2];
				if(splitText[3] == 0){
					
				}
				else{
					document.IndexForm.txtHomeZip.value = splitText[3];
				}
				document.IndexForm.txtHomeEmailId.value = splitText[4];
				if(splitText[5] != 0){
					document.IndexForm.txtHomePhone1.value = splitText[5];
					document.IndexForm.txtHomePhone2.value = splitText[6];
					document.IndexForm.txtHomePhone3.value = splitText[7];
				}
				//add phone...split phone fields up
			}
			else{
				//alert("Empty array.");	
			}
			
			document.IndexForm.userId.value = uGUID;
		});
	});
}*/