function get(x){return document.getElementById(x)}

function checkKey(x)
{
	if(window.event && window.event.keyCode == x)
		return true
	else
		return false
}
//------------- left & right functions -------------------

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

//---------------- trim functions -------------------
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//-----AJAX Form Post Builder-----
function submitForm(url){

// Creates a querystring on any form on a page to be used with AJAX  
var theForm = document.forms[0]
var postData = ""

   for(i=0; i<theForm.elements.length; i++){
	  if(theForm.elements[i].disabled != true)
	  {
			//alert(theForm.elements[i].name + " = " + theForm.elements[i].type)
		  if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "hidden" || theForm.elements[i].type == "password"){
		  postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&"
		  }
		  else if(theForm.elements[i].type == "checkbox"){
		  postData += theForm.elements[i].name + "=" + theForm.elements[i].checked + "&"
		  }
		  else if(theForm.elements[i].type == "radio"){
			if (theForm.elements[i].checked)
					postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&"
		  }
		  else if(theForm.elements[i].type == "select-one"){
		  postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].options[theForm.elements[i].selectedIndex].value) + "&"
		  }
	  }
   }

	postData = left(postData,postData.length - 1) //(left() function required to get rid of extra &)

	if (url != null)
   		postData = url + "?" + postData
		
    return postData
} 

function submitForm2(url, form){

// Creates a querystring on any form on a page to be used with AJAX  
var theForm = document.forms[form]
var postData = ""

   for(i=0; i<theForm.elements.length; i++){
	  if(theForm.elements[i].disabled != true)
	  {
			//alert(theForm.elements[i].name + " = " + theForm.elements[i].type)
		  if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "hidden" || theForm.elements[i].type == "password"){
		  postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&"
		  }
		  else if(theForm.elements[i].type == "checkbox"){
		  postData += theForm.elements[i].name + "=" + theForm.elements[i].checked + "&"
		  }
		  else if(theForm.elements[i].type == "radio"){
			if (theForm.elements[i].checked)
					postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&"
		  }
		  else if(theForm.elements[i].type == "select-one"){
		  postData += theForm.elements[i].name + "=" + escape(theForm.elements[i].options[theForm.elements[i].selectedIndex].value) + "&"
		  }
	  }
   }

	postData = left(postData,postData.length - 1) //(left() function required to get rid of extra &)

	if (url != null)
   		postData = url + "?" + postData
		
    return postData
} 

function AJAX(url,method,qs)
{
		
	var http = new ActiveXObject("Microsoft.XMLHTTP") 
			
		 http.open("POST", url, false);
		 http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 

		 http.onreadystatechange=function() {
			
		  if (http.readyState==4) 
		  	{
				var str= http.responseText
				str = str.replace(/_/g,"\n")
				if (str == "OK")
					window.location = "checkout.asp?page=payment"
				else
					alert(str)
			}

		}

	http.send(qs);

} 

function loadContent(url)
{
	
var http = new ActiveXObject("Microsoft.XMLHTTP") 
	
		  http.open("GET",url,true);
		 http.onreadystatechange=function() {
			
		  if (http.readyState==4) 
			{
				get('content').innerHTML = http.responseText
				setListeners();
		  	}
		}
 		http.send()
	
}
