var phpScript = '../include/query_db.php?';
function $(id) { return document.getElementById(id); }
//---------------------------------------------------------------------------------------------------------------------------------
function getXMLHttpObj()
{
	var xhr = null;
	if(window.XMLHttpRequest)
	{
		xhr = new XMLHttpRequest();
	}
	else 
	{
		if(window.ActiveXObject)
		{
			try{ xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e){ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		}
	}
	return xhr;
}
//---------------------------------------------------------------------------------------------------------------------------------
/* given a parameter that is to be used in url and the list_id this function fills the list with the data from server by calling the 
   fillList method defined below this function */
function getData(url, list_id)
{
	var url = phpScript + url;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function(){ fillList(xhr, list_id); }
	xhr.open("GET", url, true);
	xhr.send(null);
}
//---------------------------------------------------------------------------------------------------------------------------------
/* fills a combobox with the response from the server. This function is usually used in filling comboboxes like StateSelect, CitySelect etc */
function fillList(xhr, list_id)
{
	var child_cb = $(list_id);
	child_cb.disabled = true;
	
	if(xhr.readyState == 4 && xhr.status == 200)
	{
		while(child_cb.options.length > 1)												// remove all existing elements
			child_cb.remove(1);
		
		/*if(list_id == "ExchangecodeSelect" && xhr.responseText == "")					// if there is no optional exchange code then just add the did with areacode only
		{
			addRowToTempOrders('../include/query_db.php?callFunction=addRowToTempOrders&inWhichSection=signup_step_1');
			return;
		}*/
		
		var a = xhr.responseText.split(",");
		for(var i=0; i<a.length; i++)
		{
			var element = document.createElement("option");
			if(a[i].indexOf("___") != -1)
			{
				element.value = a[i].substring(0, a[i].indexOf("___"));
				element.text = a[i].substring(a[i].indexOf("___")+3);
			}
			else
				element.text = a[i];
				
			try
			{ child_cb.add(element, null); }
			catch(e){ child_cb.add(element, -1); }
		}
		
		child_cb.disabled = false;
		
		switch(list_id)
		{
			case "StateSelect":
				var selectedState_id = $("StateSelect").options[0].value;
				getData(phpScript + "state_id="+selectedState_id, "CitySelect");
			break;
			case "CitySelect":
				var selectedCity_id = $("CitySelect").options[0].value;
				getData(phpScript + "city_id="+selectedCity_id, "AreacodeSelect");
			break;
			case "AreacodeSelect":
				var selectedAreacode_id = $("AreacodeSelect").options[0].value;
				getData(phpScript + "areacode_id="+selectedAreacode_id, "ExchangecodeSelect");
			break;
			//-------------------------------------------------------------------------------	For shopping assistant
			case "StateSelect_sa":
				var selectedState_id = $("StateSelect_sa").options[0].value;
				getData(phpScript + "state_id="+selectedState_id, "CitySelect_sa");
			break;
			case "CitySelect_sa":
				var selectedCity_id = $("CitySelect_sa").options[0].value;
				getData(phpScript + "city_id="+selectedCity_id, "AreacodeSelect_sa");
			break;
			case "AreacodeSelect_sa":
				var selectedAreacode_id = $("AreacodeSelect_sa").options[0].value;
				getData(phpScript + "areacode_id="+selectedAreacode_id, "ExchangecodeSelect_sa");
			break;	
		}
	}
	//checkLocation();																			// show 911 info based on the shipping country selected
}
//----------------------------------------------------- For SIGNUP FORM - 1 ----------------------------------------------
function validateCoupon()
{
	var currentPath = window.location.pathname;
	var currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1);
	$("couponResponseDiv").innerHTML = "<img src='../images/loader.gif' />";
	var url = '../include/query_db.php?callFunction=checkCoupon' + 
	                                 '&b=' + $('buyAtStoreCoupon').value +
									 '&r=' + $('referFriendCoupon').value +
									 '&p=' + $('promotionalCoupon').value;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			var responseArray = xhr.responseText.split("*****");
			var b = responseArray[0];
			var r = responseArray[1];
			var p = responseArray[2];
			var couponType = null;
			var discountPrice = null;
			var productId = null;
			var productName = null;
			var mac = null;
			
			if(b)
			{
				var response = b.split("___");
				couponType = response[0];
				discountPrice = response[1];
				productId = response[2];
				productName = response[3];
				mac = response[4];
				if($("couponResponseDiv"))
				{
					$("couponResponseDiv").innerHTML = "<br/> - Congratulations you earned a discount of <b>$" + discountPrice + "</b> on our <b>" + couponType + "</b> package.<br/>" + 
										   "It seems that you have already bought our product <b>" + productName + "</b>, so you dont have to buy a product in this signup.";
				}
				
				if(currentPage == "signup2.php")
				{
					// show it in signup2 page so that user cannot select product
					$('productDiv').innerHTML = "From the coupon number you entered it seems that you have already bought our product <b>" + productName + "</b>, so you dont have to buy a product in this signup.";
				}
				else
				{
					showSelectedProduct(productId);
					$('selectProduct').disabled = true;							// disable selection of products
				}
			}
			else
			{
				if($("couponResponseDiv"))
				{
					$("couponResponseDiv").innerHTML = "";
					$("couponResponseDiv").innerHTML += "<br/> - Invalid Buy at Store Coupon";
				}
			}
			
			if(r)
			{
				var response = r.split("___");
				couponType = response[0];
				discountPrice = response[1];
				if($("couponResponseDiv"))
					$("couponResponseDiv").innerHTML += "<br/> - Congratulations you earned a discount of <b>$" + discountPrice + "</b> on our <b>" + couponType + "</b> package.";
			}
			else
			{
				if($("couponResponseDiv"))
					$("couponResponseDiv").innerHTML += "<br/> - Invalid Refer a Friend Coupon";
			}
			
			if(p)
			{
				var response = p.split("___");
				couponType = response[0];
				discountPrice = response[1];
				if($("couponResponseDiv"))
					$("couponResponseDiv").innerHTML += "<br/> - Congratulations you earned a discount of <b>$" + discountPrice + "</b> on our <b>" + couponType + "</b> package.";
			}
			else
			{
				if($("couponResponseDiv"))
					$("couponResponseDiv").innerHTML += "<br/> - Invalid Promotional Coupon";
			}
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function showTempOrdersTable(url)
{
	var url = phpScript + url;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv").innerHTML = xhr.responseText.split("-*-*-")[0];				// the html table
			$("oneTimeTotal").innerHTML = "$" + xhr.responseText.split("-*-*-")[1];			// the price
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function addRowToTempOrders()
{
	$("selectedNoDiv").innerHTML = "<img src='../images/loader.gif' />";
	
	var selectedLoc = $("CountrySelect").options[$("CountrySelect").selectedIndex].text + " - " +
					  $("StateSelect").options[$("StateSelect").selectedIndex].text + " - " +
					  $("CitySelect").options[$("CitySelect").selectedIndex].text;
	var countryId = $("CountrySelect").options[$("CountrySelect").selectedIndex].value;
	var areacode = $("AreacodeSelect").options[$("AreacodeSelect").selectedIndex].text;
	var exchangeId = $("ExchangecodeSelect").options[$("ExchangecodeSelect").selectedIndex].value;
	var exchangeCode = ($("ExchangecodeSelect").selectedIndex != 0)?($("ExchangecodeSelect").options[$("ExchangecodeSelect").selectedIndex].text):'';

	var inWhichSection = null;
	if(location.href.indexOf("/map") != -1) 
		inWhichSection = "map_page";
	else 
	if(location.href.indexOf("/ctrpanel") != -1)
		inWhichSection = "addons_section";
	else
	if(location.href.indexOf("signup2") != -1)
		inWhichSection = "signup_step_2";
	else
		inWhichSection = "signup_step_1";
	
	var url = phpScript + "callFunction=addRowToTempOrders&inWhichSection=" + inWhichSection +
	          "&selectedLoc="+ selectedLoc +
			  "&countryId=" + countryId + 
			  "&areacode=" + areacode + 
			  "&exchangeId=" + exchangeId +
			  "&exchangeCode=" + exchangeCode;
	
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv").innerHTML = xhr.responseText.split("-*-*-")[0];
			$("oneTimeTotal").innerHTML = "$" + xhr.responseText.split("-*-*-")[1];
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function addTollFreeToTempOrders(url)
{
	$("selectedNoDiv").innerHTML = "<img src='../images/loader.gif' />";
	
	var selectedLoc = $("CountrySelect").options[$("CountrySelect").selectedIndex].text;
	var countryId = $("CountrySelect").options[$("CountrySelect").selectedIndex].value;
	var tollPrefix = $("tollPrefixes").options[$("tollPrefixes").selectedIndex].text;
	
	var url = url + "&countryId=" + countryId +
				"&selectedLoc=" + selectedLoc +
	           "&tollPrefix=" + tollPrefix; 

	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv").innerHTML = xhr.responseText;
			//$("totalPriceDiv").innerHTML = xhr.responseText.split("Price___")[1];
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function deleteRowFromTempOrders(url)
{
	$("selectedNoDiv").innerHTML = "<img src='../images/loader.gif' />";

	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv").innerHTML = xhr.responseText.split("-*-*-")[0];
			$("oneTimeTotal").innerHTML = "$" + xhr.responseText.split("-*-*-")[1];
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//**************************************************** SING UP STEP - 2 **************************************************
function showComboboxes(rowId, mode)
{
	$("comboBoxesDiv").style.display = "block";
	if(mode == "edit")
		$("ExchangecodeSelect").onchange = function() { editRowInTempOrders(rowId); }
	else
		$("ExchangecodeSelect").onchange = function() { addRowToTempOrders(); }		
}
//------------------------------------------------------------------------------------------------------------------------
function editRowInTempOrders(rowId)
{
	var selectedLoc = $("CountrySelect").options[$("CountrySelect").selectedIndex].text + " - " +
					  $("StateSelect").options[$("StateSelect").selectedIndex].text + " - " +
					  $("CitySelect").options[$("CitySelect").selectedIndex].text;
	var countryId = $("CountrySelect").options[$("CountrySelect").selectedIndex].value;
	var areacode = $("AreacodeSelect").options[$("AreacodeSelect").selectedIndex].text;
	var exchangeId = $("ExchangecodeSelect").options[$("ExchangecodeSelect").selectedIndex].value;
	var exchangeCode = $("ExchangecodeSelect").options[$("ExchangecodeSelect").selectedIndex].text;
	
	var url = "../include/query_db.php?callFunction=editRowInTempOrders&rowId=" + rowId + 
			  "&selectedLoc="+ selectedLoc +
			  "&countryId=" + countryId +
	          "&areacode=" + areacode + 
			  "&exchangeId=" + exchangeId +
			  "&exchangeCode=" + exchangeCode;
	  
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv").innerHTML = xhr.responseText.split("Price___")[0];
			$("totalPriceDiv").innerHTML = xhr.responseText.split("Price___")[1];
			$("comboBoxesDiv").style.display = "none";
			showTotalsTable();
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//-------------------------------------------------------------------------------------------------------------------
function setSelectedValues(controls, values)								// for loading comboboxes with user's selected values
{
	for(var i=0; i<controls.length; i++)
	{
		$(controls[i]).value = values[i];
	}
}
//------------------------------------------------------------------------------------------------------------------------
//************************************************** SHOPPING ASSISTANT **************************************************
//------------------------------------------------------------------------------------------------------------------------
function showTempOrdersTable_inSA()
{
	var url = "include/query_db.php?callFunction=showTempOrdersTable_inSA";
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv_sa").innerHTML = xhr.responseText.split("Price___")[0];
			$("totalPriceDiv_sa").innerHTML = xhr.responseText.split("Price___")[1];
			/*$("selectedNoDiv_sa").style.overflow = "auto";
			$("selectedNoDiv_sa").style.width = "600px";
			$("selectedNoDiv_sa").style.height = "50px";*/
			//showTotalsTable();
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function addRowToTempOrders_inSA()
{
	$("selectedNoDiv_sa").innerHTML = "<img src='" + "images/loader.gif' />";
	
	var selectedLoc = $("CountrySelect_sa").options[$("CountrySelect_sa").selectedIndex].text + " - " +
					  $("StateSelect_sa").options[$("StateSelect_sa").selectedIndex].text + " - " +
					  $("CitySelect_sa").options[$("CitySelect_sa").selectedIndex].text;
	var countryId = $("CountrySelect_sa").options[$("CountrySelect_sa").selectedIndex].value;
	var areacode = $("AreacodeSelect_sa").options[$("AreacodeSelect_sa").selectedIndex].text;
	var exchangeId = $("ExchangecodeSelect_sa").options[$("ExchangecodeSelect_sa").selectedIndex].value;
	var exchangeCode = $("ExchangecodeSelect_sa").options[$("ExchangecodeSelect_sa").selectedIndex].text;

	var url = "include/query_db.php?callFunction=addRowToTempOrders_inSA&selectedLoc="+ selectedLoc +
			  "&countryId=" + countryId + 
	          "&areacode=" + areacode + 
			  "&exchangeId=" + exchangeId +
			  "&exchangeCode=" + exchangeCode;
	
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$("selectedNoDiv_sa").innerHTML = xhr.responseText.split("Price___")[0];
			$("totalPriceDiv_sa").innerHTML = xhr.responseText.split("Price___")[1];
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function deleteRowFromTempOrders_inSA(rowId)
{
	$("selectedNoDiv_sa").innerHTML = "<img src='" + "images/loader.gif' />";

	var url = "include/query_db.php?callFunction=deleteRowFromTempOrders_inSA&rowId="+ rowId;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			
			$("selectedNoDiv_sa").innerHTML = xhr.responseText.split("Price___")[0];
			$("totalPriceDiv_sa").innerHTML = xhr.responseText.split("Price___")[1];
			//showTotalsTable();
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function showSelectedProduct(productId)
{
	var url = "../include/query_db.php?callFunction=showSelectedProduct&productId=" + productId;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			$('selectedProductDiv').innerHTML = xhr.responseText;
			//showTotalsTable();
		}
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//---------------------------------------------------------------------------------------------------------------------------------
function showTotalsTable()
{
	if($("divTotals"))
		$("divTotals").innerHTML = "<img src='../images/loader.gif' />";
	
	var url = "../include/query_db.php?callFunction=showTotalsTable";
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
			$("divTotals").innerHTML = xhr.responseText;
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}
//------------------------------------------------------------------------------------------------------------------------
function acc2billinfo()
{	
	if($('billCheckBox').checked==true)
	{
		$('billFirstName').value=$('accFirstName').value;
		$('billLastName').value=$('accLastName').value;
	}
	else{
		$('billFirstName').value="";
		$('billLastName').value="";
	}
}

function acc2shipinfo()
{
	if($('shipCheckBox').checked==true){
		$('shipFirstName').value=$('billFirstName').value;
		$('shipLastName').value=$('billLastName').value;
		$('shipAddress1').value=$('billAddress1').value;
		$('shipAddress2').value=$('billAddress2').value;
		$('shipCity').value=$('billCity').value;
		$('shipState').value=$('billState').value;
		$('shipZip').value=$('billZip').value;
		$('shipCountry').value=$('billCountry').value;
	}
	else{
		$('shipFirstName').value="";
		$('shipLastName').value="";
		$('shipAddress1').value="";
		$('shipAddress2').value="";
		$('shipCity').value="";
		$('shipState').value="";
		$('shipZip').value="";
		$('shipCountry').value="";
	}
	checkLocation();
}
//----------------------------------------------------------------------------------------------------------------------
//this function displays the 911 or 999 info table in step 1 of signup
function checkLocation()
{
	if($('shipCountry') && ($('shipCountry').value=="United States" || $('shipCountry').value=="Canada"))
		$('div911').style.display="block";
	else
		$('div911').style.display="none";		

	/*if($('billCountry') && ($('billCountry').value=="United Kingdom" || $('shipCountry').value=="United Kingdom"))
		$('div999').style.display="block";
	else
		$('div999').style.display="none";*/
}
//this function displays the 911 or 999 info table in step 2 of signup
function checkLocation2()
{
	if($('shipCountry').value=="United States")
	{
		$('div911_titleBar').style.display="block";
		$('div911_body').style.display="block";
		loadContent("div911", "show911Form");
	}
	else
	{
		$('div911_titleBar').style.display="none";
		$('div911_body').style.display="none";
	}

	/*if($('billCountry').value=="United Kingdom" || $('shipCountry').value=="United Kingdom"){
		$('div999_titleBar').style.display="block";
		$('div999_body').style.display="block";
		loadContent("div999","show999Info");
	}else{
		$('div999_titleBar').style.display="none";
		$('div999_body').style.display="none";
	}*/
}
//-----------------------------------------------------------------------------------------------------------------------
function validateSignup()										  		//traverses all fields in the signup form and validates them
{
	var controlsArray = document.form1.elements;
	for(var i=0; i<controlsArray.length; i++)
	{
		switch(controlsArray[i].type)
		{
			case "radio":
				var uncheckedName = null;
				var groupChecked = false;
				var radioGroup = controlsArray[controlsArray[i].name];	//put the radio buttons of same name in a group
				for(j=0; j<radioGroup.length; j++)
				{
					if(radioGroup[j].checked == true)
						groupChecked = true;
					else
						uncheckedName = controlsArray[i].name;
				}
				if(!groupChecked)
				{
					switch(uncheckedName)
					{
						case "planRB":
							alert("Please select a Plan");
						break;
					}
					return false;
				}
			break;
			case "select-one":
				if(controlsArray[i].selectedIndex == -1 || (controlsArray[i].selectedIndex == 0 && controlsArray[i].name != "selectProduct"))
				{
					switch(controlsArray[i].name)
					{
						case "CountrySelect":
							alert("Please select a Country in the 'Select Your Phone Number' section");
						break;
						case "StateSelect":
							alert("Please select a State in the 'Select Your Phone Number' section");
						break;
						case "CitySelect":
							alert("Please select a City in the 'Select Your Phone Number' section");
						break;
						case "AreacodeSelect":
							alert("Please select an Area Code in the 'Select Your Phone Number' section");
						break;
						case "billCountry":
							alert("Please select a country in the 'Billing Information' section");
						break;
						case "billCardType":
							alert("Please select a card type in the 'Billing Information' section");
						break;
						case "shipCountry":
							alert("Please select a country in the 'Shipping Information' section");
						break;
						case "shipShippingOption":
							alert("Please select a shipping option in the 'Shipping Information' section");
						break;
					}
					return false;
				}
			break;
			case "text":
				if(controlsArray[i].text == "")
				{
					alert("Please fill all required fields.");
					return false;
				}
				else
				{
					switch(controlsArray[i].name)
					{
						case "accEmail":
						case "accReEmail":
							var email_regex = /^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/;
							if(!email_regex.test(controlsArray[i].value))
							{
								alert("Please provide an appropriate email address!!!");
								return false;
							}
						break;
						case "billCardNumber":
							//credit card no format will be xxxx-xxxx-xxxx-xxxx OR xxxx xxxx xxxx xxxx OR xxxxxxxxxxxxxxxx
							var creditCard_regex = /^((\d{4}[- ]?){3}\d{4})$/;
							if(!creditCard_regex.test(controlsArray[i].value))
							{
								alert("The credit card number you entered is not in the right format");
								return false;
							}
						break;
					}
				}
			case "password":
				switch(controlsArray[i].name)
				{
					case "accPassword":
					case "accRePassword":
						if(controlsArray[i].value == "" || controlsArray[i].value.length < 6)
						{
							alert("Password should be atleast 6 characters in length.");
							return false;
						}
					break;
				}
			break;
		}
	}
	
	if($('accEmail').value.toLowerCase() != $('accReEmail').value.toLowerCase())
	{
		alert("The email you entered in the Email and Retype Email fields doesn't match with each other");
		return false;
	}
	if($('accPassword').value != $('accRePassword').value)
	{
		alert("The password you entered in the Password and Retype Password fields doesn't match with each other");
		return false;
	}
		
	return true;
}
//-------------------------------------------------------------------------------------------------------------------
function continueProcess()
{
	if($('Agree').checked==true)
	{
		//if(validateSignup())
			document.form1.submit();
	}
	else
	{
		alert("You cannot continue without accepting Avia Phone Terms of Services !!!"); 
		return 0;
	}
}
//-------------------------------------------------------------------------------------------------------------------
function loadContent1(targetDiv,remoteFunc)
{
	//$(targetDiv).innerHTML = "<img src='../images/loader.gif' />";
	
	var url = 'processOrderPage.php?mode=' + remoteFunc;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		$(targetDiv).innerHTML = xhr.responseText.split("//---")[0];
		eval(xhr.responseText.split("//---")[1]);
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}

/*this function will be called when edit or save button will be pressed in the signup_form2. So it gets the values and shows them
in the signup_form2 page */
function loadContent(targetDiv, remoteFunc)	
{
	//$(targetDiv).innerHTML = "<img src='../images/loader.gif' />";
	
	var url = '';
	var allTags = document.body.getElementsByTagName('*');
	for(var i=0; i<allTags.length; i++)
	{
		var tag = allTags[i];
		if(tag.id && tag.name) 
		{
			url += $(tag.id).name + "=" + $(tag.id).value + "&";
		}
	}
	
	url = 'processOrderPage.php?mode=' + remoteFunc + '&' + url;
	var xhr = getXMLHttpObj();
	xhr.onreadystatechange = function()
	{
		$(targetDiv).innerHTML = xhr.responseText.split("//---")[0];
		eval(xhr.responseText.split("//---")[1]);
	}
	xhr.open("GET", url, true);
	xhr.send(null);
}