
/*----------   [General Functions] ------------------*/
var PhoneComparisons = 0;
var PCno;


var xmlhttpObj; //for CoverageNRoaming v4

var xmlHttp;
var xmlHttp2;
var xmlHttp3;


function addPhone(obj) {
	//This is called as the user selects individual phones
	//for comparison
	//(1) Phone ID is added to SESSIONS
	//(2) Top banner (TDitem_phonetopborder_X) is highlighted RED
	
	// ------------- [Background of TR] --------------
	var TRnumber = obj.value;
	
	//Top Red Border
	var TDlineID = "TDitem_phonetopborder_" + TRnumber;
	var TDlineObj = document.getElementById(TDlineID);

	var TRitemID = "TRitem_phone_" + TRnumber;
	var TRitemObj = document.getElementById(TRitemID);
	
	var checkboxID = "add2compare_" + TRnumber;
	var checkboxObj = document.getElementById(checkboxID);
	var checkboxPhID = checkboxObj.value;
	
	var PhoneID = obj.value;
	// ------------- [Background of TR] --------------

	// Call on the GetXmlHttpObject function to create an XMLHTTP object, 
	xmlHttp=GetXmlHttpObject();
	
	var url="/phones/compare_storevals.php";

	url=url+"?pid="+PhoneID;

	if (checkboxObj.checked) {
		url=url+"&operation=push";
		TDlineObj.className = 'TDitem_phonetopborder_comON';
		TRitemObj.className = 'TRitem_phone_comON';
	}else{
		url=url+"&operation=pop";
		TDlineObj.className = 'TDitem_phonetopborder_comOFF';
		TRitemObj.className = 'TRitem_phone_comOFF';
	}

	url=url+"&sid="+Math.random();
	
	//Tell the xmlHttp object to execute a function called stateChanged when a change is triggered
	xmlHttp.onreadystatechange = stateChanged;
	
	//Open the XMLHTTP object with the url compare_storevals.php.
	xmlHttp.open("GET",url, true);
	
	//Send the HTTP request to the server (compare_storevals.php) - response goes back to stateChanged xmlHttp.responseText
	xmlHttp.send(null);

}

function stateChanged() { 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		//TESTING
	 	//document.getElementById("displayCompareArray").innerHTML = xmlHttp.responseText;
		//document.getElementById("phoneCount").innerHTML = xmlHttp.responseText;
		//PhoneComparisons = xmlHttp.responseText;
		
		document.getElementById("show_test_output").innerHTML = xmlHttp.responseText;
		
	} 
	
}

function clearSession() {
	// Call on the GetXmlHttpObject function to create an XMLHTTP object, 
	xmlHttp3 = GetXmlHttpObject();
	
	var url="/phones/compare_clear_v4.php";
	
	//url=url+"?sid="+Math.random();
	
	//Tell the xmlHttp object to execute a function called stateChanged when a change is triggered
	xmlHttp3.onreadystatechange = stateChanged3;
	 
	//Open the XMLHTTP object with the url compare_storevals.php.
	xmlHttp3.open("GET", url, true);
	
	//Send the HTTP request to the server (compare_storevals.php) - response goes back to stateChanged xmlHttp.responseText
	xmlHttp3.send(null);
}

function stateChanged3() { 
	
	var phonesHTML='';
	var compareForm = document.compareForm;

	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete") { 

		/*phonesHTML = phonesHTML + '<div id="ci_phone1" class="ci_phone_off" ></div>';
		phonesHTML = phonesHTML + '<div id="ci_phone2" class="ci_phone_off" ></div>';
		phonesHTML = phonesHTML + '<div id="ci_phone3" class="ci_phone_off" ></div>';
		phonesHTML = phonesHTML + '<div id="ci_phone4" class="ci_phone_off" ></div>';
		phonesHTML = phonesHTML + '<div class=\"clear\"></div>';*/
		
		/*var elem;
		for (var iCount=0; compareForm.compare.length; iCount++) {
			elem = 'compare' + '[' + iCount + ']';
			if (!compareForm.elements[elem]) break;
			
			compareForm.elements[elem].checked = false;
			
			//alert ("elem - " + compareForm.elements[elem]);
		}*/
		
		//alert(compareForm.compare.length)
		for(var i=0; i < compareForm.compare.length; i++) {
			
			//Uncheck checkboxes
			compareForm.compare[i].checked = false;

		}
	}

	// Uncheck AS
	//for(var i=0; i < compareForm.compare.length; i++) {
		//compareForm.compare[i].checked = false;
	//}
	

	//document.getElementById("compare_icons").innerHTML = phonesHTML;

}




function HighlightPhone() {
	//Not used since 
	//4 phone display was taken out
	
	// Call on the GetXmlHttpObject function to create an XMLHTTP object, 
	xmlHttp2 = GetXmlHttpObject();
	
	var url="../phones/compare_getNo_v4.php";
	
	url=url+"?sid="+Math.random();
	
	//Tell the xmlHttp object to execute a function called stateChanged when a change is triggered
	xmlHttp2.onreadystatechange = stateChanged2;
	 
	//Open the XMLHTTP object with the url compare_storevals.php.
	xmlHttp2.open("GET",url, true);
	
	//Send the HTTP request to the server (compare_storevals.php) - response goes back to stateChanged xmlHttp.responseText
	xmlHttp2.send(null);
}

/*function getPN() {
	
	// Call on the GetXmlHttpObject function to create an XMLHTTP object, 
	xmlHttp2 = GetXmlHttpObject();
	
	var url="../phones/compare_getNo_v4.php";
	
	url=url+"?sid="+Math.random();
	
	//Tell the xmlHttp object to execute a function called stateChanged when a change is triggered
	xmlHttp2.onreadystatechange = stateChanged2;
	 
	//Open the XMLHTTP object with the url compare_storevals.php.
	xmlHttp2.open("GET",url, true);
	
	//Send the HTTP request to the server (compare_storevals.php) - response goes back to stateChanged xmlHttp.responseText
	xmlHttp2.send(null);
}*/


function stateChanged2() { 

	//Used with HighlightPhone() - not used since 
	//4 phone display was taken out
	
	var phonesHTML='';
	var num;
	
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") { 

	num = xmlHttp2.responseText;
	
	if (num >= 1) {
		phonesHTML = phonesHTML + '<div id="ci_phone1" class="ci_phone_on" ></div>';
	}else{
		phonesHTML = phonesHTML + '<div id="ci_phone1" class="ci_phone_off" ></div>';
	}
	
	if (num >= 2) {
		phonesHTML = phonesHTML + '<div id="ci_phone2" class="ci_phone_on" ></div>';
	}else{
		phonesHTML = phonesHTML + '<div id="ci_phone2" class="ci_phone_off" ></div>';
	}
	
	if (num >= 3) {
		phonesHTML = phonesHTML + '<div id="ci_phone3" class="ci_phone_on" ></div>';
	}else{
		phonesHTML = phonesHTML + '<div id="ci_phone3" class="ci_phone_off" ></div>';
	}
	
	if (num >= 4) {
		phonesHTML = phonesHTML + '<div id="ci_phone4" class="ci_phone_on" ></div>';
	}else{
		phonesHTML = phonesHTML + '<div id="ci_phone4" class="ci_phone_off" ></div>';
	}
	
	phonesHTML = phonesHTML + '<div class="clear"></div>';

	//document.getElementById("compare_icons").innerHTML = phonesHTML;
	
	} //xmlHttp.readyState COMPLETE
	
}



function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}catch (e){
 		
		// Internet Explorer
	 	try {
  		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}catch (e) {
 		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	
	return xmlHttp;
}


function arePhonesSel() {
	
	//compare;
	var compareForm = document.compareForm;
	var total = 0;
	
	for(var i=0; i < compareForm.compare.length; i++) {
		if (compareForm.compare[i].checked) {
			//total += compareForm.compare[i].value + "\n";
			total = total + 1;
		}
	}

	if(total<2) {
		return false;
	}else{
		//compareForm.submit();
		return true;
	}

} 


/* Hide search value on focus*/
function hide_value(el)
{
	if(el.V) {
	if (el.value == el.V) {
	el.value = '';
	}
	} else {
	el.V = el.value;
	el.value = '';
	}
}


/*----------------[START Coverage N Romading V4] -------------*/

function validateForm()
{
	valid = true;
	
	if (document.travelForm.make.selectedIndex == 0) {
		alert ("Please select the manufacturer of your phone");
		valid = false;
	}else if (document.travelForm.model.selectedIndex == 0) {
		alert ("Please select the model of your phone");
		valid = false;
	}else if (document.travelForm.plan.selectedIndex == 0) {
		alert ("Please select the plan of the phone your using to roam");
		valid = false;
	}else if (document.travelForm.country.selectedIndex == 0) {
		alert ("Please select the country you wish to roam in");
		valid = false;
	}
	
	return valid;
}

function showpg(fname,width,height) {  	
   var features="width="+width+",height="+height+",scrollbars=1"   
   window.open(fname,"",features)
}

function loadXMLDoc() {
	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
  		xmlhttp=new XMLHttpRequest();
  	}
	
	// code for IE
	else if (window.ActiveXObject){
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
 	xmlhttpObj = xmlhttp
}
/*----------------[END Coverage N Romading V4] -------------*/














