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


var xmlhttpObj; //for CoverageNRoaming v4

var xmlHttp;
var xmlHttp2;
var xmlHttp3;

function HighlightPhone() {

	// 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 addPhone(obj) {
	
	// ------------- [Background of TR] --------------
	var TRnumber = obj.value;
	
	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 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() { 
	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 stateChanged() { 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		//TESTING
	 	//document.getElementById("displayCompareArray").innerHTML = xmlHttp.responseText;
		//document.getElementById("phoneCount").innerHTML = xmlHttp.responseText;
		//PhoneComparisons = 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>';
	
	}

	// Uncheck AS
	for(var i=0; i < compareForm.compare.length; i++) {
		compareForm.compare[i].checked = false;
	}
	
	document.getElementById("compare_icons").innerHTML = phonesHTML;

}

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
}

function popi(type, sel_val){
	
	loadXMLDoc();
	url = "../coverage_and_roaming_v4/phone.php?type="+type

	if (type == "model"){
		url += "&make="+sel_val;
	}

	if (xmlhttpObj!=null){
		xmlhttpObj.onreadystatechange=function(){
										if (xmlhttpObj.readyState == "Ready" || xmlhttpObj.readyState == "4"){
											document.getElementById(type+"_td").innerHTML = xmlhttpObj.responseText;
										}
										};
	
		xmlhttpObj.open("GET", url, true);
		xmlhttpObj.send(null);
	
	}else{
  		alert("Your browser does not support XMLHTTP.");
  	}
}

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














