function checkform()
{
	if (!document.f.shopfor[0].checked && !document.f.shopfor[1].checked && !document.f.shopfor[2].checked) {
		alert("please select one for shopping!");
		return false;
	}
	return true;
}

function listOptions() {
	var thisForm = document.forms["f"];
	var selected = new Array();
	var element = '';
	var counter = 0;

	for (i = 0; i < thisForm.elements.length; i++){
		element = thisForm.elements[i];
		if(element.type == "radio" && element.name.indexOf("shopfor") != -1 && element.checked){
			counter = counter + 1;
			selected.push(element.value);
		}
	}

	document.getElementById('phone').style.display = (selected == 'phone') ? '' : 'none';
	document.getElementById('provider').style.display = (selected == 'provider') ? '' : 'none';
	document.getElementById('plan').style.display = (selected == 'plan') ? '' : 'none';
}

function toggleIt(id) {
	var el = document.getElementById(id);
	el.style.display = (el.style.display == 'none' ? '' : 'none');
}

function popup(url) {
	newwindow = window.open(url,'name','height=700,width=600');
	if (window.focus) {newwindow.focus()}
	return false;
}

function openURL(el,thisCurQuery,thisZip,thisURL){ 
	var nameOfObj = el.name;
	var selInd = eval("document.theForm." + nameOfObj + ".selectedIndex"); 
	var dataValue = eval("document.theForm." + nameOfObj + ".options[selInd].value");
	var newAddedItem = nameOfObj + "=" + escape(dataValue);
	var newQueryString = '';
	var queryArray = new Array();
	
	queryArray = thisCurQuery.split("&")
	for(i = 0; i < queryArray.length; i++){
	
		var subQueryA = new Array();
		subQueryA = queryArray[i].split("=");
		if (subQueryA[0] == nameOfObj){
			queryArray.splice(i,1);
		}
	}
	
	for(i = 0; i < queryArray.length; i++){
		var foundPage = queryArray[i].search("page");
		if(foundPage != -1){
			queryArray.splice(i,1);
		} 	
	}	
	
	for(i = 0; i < queryArray.length; i++){
		var foundPage = queryArray[i].search("zip");
		if(foundPage != -1){
			queryArray.splice(i,1);
		} 	
	}		

	newQueryString = queryArray.join('&');
	if (newQueryString == ''){
		newQueryString += newAddedItem;
	} else {
		newQueryString += "&" + newAddedItem;
	}
	
	if (thisZip != '') {
		newQueryString += '&zip=' + thisZip;
	}
	
	goURL = thisURL + "?" + newQueryString;
	top.location.href = goURL;
}


function handlePhoneCompare(thisSID,thisZip,thisExtension){
	var thisForm = document.forms["pcform"];
	var error = 'Please select from 2 to 6 phones to compare';
	var selected = new Array();
	var element = '';
	var counter = 0;
	var submitURL = "cellular_phones_compare" + thisExtension;
	
	for (i = 0; i < thisForm.elements.length; i++){
		element = thisForm.elements[i];
		if(element.type == "checkbox" && element.name.indexOf("this_") != -1 && element.checked){
			counter = counter + 1;
			selected.push(element.value);
		}
	}	
	
	if(counter < 2 || counter > 6){
		alert(error);
		return;
	} else {
		submitURL = submitURL + '?pid=' + selected;
	}

	if (thisSID != ''){
		submitURL += '&sid=' + thisSID;
	}
		
	if (thisZip != ''){
		submitURL += '&zip=' + thisZip;
	}
	
	top.location.href = submitURL;
}

function handlePlanCompare(thisPID,thisZip,thisExtension){
	var thisForm = document.forms["pcform"];
	var error = 'Please select from 2 to 4 plans to compare';
	var selected = new Array();
	var element = '';
	var counter = 0;
	var submitURL = "cellular_service_plans_compare" + thisExtension;

	for (i = 0; i < thisForm.elements.length; i++){
		element = thisForm.elements[i];
		if(element.type == "checkbox" && element.name.indexOf("this_") != -1 && element.checked){
			counter = counter + 1;
			selected.push(element.value);
		}
	}	
	
	if(counter < 2 || counter > 4){
		alert(error);
		return;
	} else {
		submitURL = submitURL + '?sid=' + selected;
	}

	if (thisPID != ''){
		submitURL += '&pid=' + thisPID;
	}
	
	if (thisZip != ''){
		submitURL += '&zip=' + thisZip;
	}	
	
	top.location.href = submitURL;
}

var xmlHttp;
function showFeature(id,thisExtension){
	var el = document.getElementById(id);
	el.style.display = (el.style.display == 'none' ? '' : 'none');
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null){
		alert ("Browser does not support HTTP Request");
		return false;
	}

	var url = "cellular_phone_features" + thisExtension;
	url = url + "?productid=" + id;
	
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){ 
			el.innerHTML = xmlHttp.responseText;
		} 	
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function GetXmlHttpObject(){
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
} 