String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");};
String.prototype.startsWith = function(str){return this.substring(0,str.length)==str;};
String.prototype.endsWith = function(str){return this.lastIndexOf(str)==this.length-str.length;};
String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
}

function opnWin(pagename, wid, hght){
	var myRef ;
	myRef = window.open(pagename,'mywin', 'left=20,top=20,width=' + wid + ',height=' + hght + ',toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=no');
	myRef.focus();
}

function alltrim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function isEmail(mailvalue) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mailvalue))
	{
		return (true);
	}
	return (false);
}

function IsNumeric(sText){
	var i = 0;
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
        }
	}
	return IsNumber;
}

function isEmpty(str) {
  return ( typeof(str) != "string" || str.trim().length == 0 );
}

/* kitbuilder scripts */
function showdetails(item) {
	show = "show_"+item;
	item = "info_"+item;	
	if(document.getElementById(item).style.display == "none") {
		document.getElementById(item).style.display = "block";
		document.getElementById(show).innerHTML = "Hide Details";
	}
	else {
		document.getElementById(item).style.display = "none";
		document.getElementById(show).innerHTML = "Show More Info";
	}
}
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;
}

var xmlHttp = GetXmlHttpObject();

function addtokit(i) {
	document.getElementById("loading_"+i).style.display = "inline";
	var sku = document.getElementById("addkit"+i).sku.value;
	var xcatid = document.getElementById("addkit"+i).xcatid.value;
	var params = "";
	var url = "/addtokit.asp";
	params += "sku="+ encodeURI(sku);
	params += "&xcatid="+encodeURI(xcatid);
	timestamp = new Date();
	tim1 = (timestamp.getTime());
	sec1 = timestamp.getSeconds();
	ms1 = timestamp.getMilliseconds();
	thetime = tim1+sec1+ms1;
	params += "&rand="+thetime;
	//alert(params);
	xmlHttp.open('post',url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.lengt);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.setRequestHeader('If-Modified-Since','Tue, 04 Apr 2006 00:00:00 GMT');
	xmlHttp.onreadystatechange = function(){ 
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {			
				result = xmlHttp.responseText;					
				document.getElementById("kititems").innerHTML = result;			
				document.getElementById("loading_"+i).style.display = "none";
			}
			else {			
				alert("error with request");
				document.getElementById("loading_"+i).style.display = "none";
			}
		}
	};
	xmlHttp.send(params);
}

function removekit(xtype,xaccessories){
	var params = "";
	var url = "/removekit.asp";
	var xcatid = document.getElementById("addkit1").xcatid.value;
	params += "type="+ encodeURI(xtype);
	params += "&xcatid="+encodeURI(xcatid);
	params += "&sku="+ encodeURI(xaccessories);
	timestamp = new Date();
	tim1 = (timestamp.getTime());
	sec1 = timestamp.getSeconds();
	ms1 = timestamp.getMilliseconds();
	thetime = tim1+sec1+ms1;
	params += "&rand="+thetime;
	xmlHttp.open('post',url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.lengt);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.setRequestHeader('If-Modified-Since','Tue, 04 Apr 2006 00:00:00 GMT');
	xmlHttp.onreadystatechange = function(){ 
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {			
				result = xmlHttp.responseText;					
				document.getElementById("kititems").innerHTML = result;							
			}
			else {			
				alert("error with request");				
			}
		}
	};
	xmlHttp.send(params);
}

function kitpop(sku, cartid) {
	window.open('/kitpop.asp?sku='+sku, "mywindow","menubar=0,status=0,resizable=1,scrollbars=1,width=450,height=375");
}

function kblk(catid) {
	if (catid != -1)
	{
		document.getElementById("kittocart").action= "category.asp?cat="+catid+"&sub=sub34";
		document.getElementById("kittocart").method = "post";
		document.getElementById("kittocart").submit();
	}
}

function checkSearchform(frm) {
	if (isEmpty(frm.keyword.value))
	{
		alert("Please enter search keyword.")
		frm.keyword.focus()
		return false
	}
}

function checkSignNewsLetter(f) {
	if (isEmpty(f.email.value))
	{
		alert("Please enter your email address.")
		f.email.focus()
		f.email.select()
		return false
	}
	if (isEmail(f.email.value)  != true)
	{
		alert("Your email is invalid.");
		f.email.focus()
		f.email.select()
		return false;
	}
	return true
}

function view(n){
	document.getElementById("page").value = n;
	document.ViewPage.submit();
}

function checkFromEmail(f){
	if (isEmpty(f.yourname.value))
	{
		alert("Please enter your name.")
		f.yourname.focus()
		return false
	}
	if (isEmpty(f.youremail.value))
	{
		alert("Please enter your email address.")
		f.youremail.focus()
		return false
	} else
	{	if (isEmail(f.youremail.value)  != true)
		{
			alert("Please enter a valid email address.");
			f.youremail.focus()
			return false;
		}
	}
	if (isEmpty(f.friendname.value))
	{
		alert("Please enter your friend's name.")
		f.friendname.focus()
		return false
	}
	
	if (isEmpty(f.friendemail.value))
	{
		alert("Please enter your friend email address.")
		f.friendemail.focus()
		return false
	} else
	{	if (isEmail(f.friendemail.value)  != true)
		{
			alert("Your friend email is invalid.");
			f.friendemail.focus()
			return false;
		}
	}
	return true
}

function popModels(parentCat){
	var catID = "206" + parentCat
	var url = "/ajax/popModels.asp?catid=" + catID;
	xmlHttp.open('GET',url,true);
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById("modelopts").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.send(null);
}

function seeCategory(catID){
	cururl = '/category.asp?cat=' + catID; 
	window.location.assign( cururl ); 
}

function clearMsg(){
	if (document.getElementById('sli_search_2')) {
		if (document.getElementById('sli_search_2').value == '-Enter Search Term Here-')
		{
			document.getElementById('sli_search_2').value = '';
			document.getElementById('sli_search_2').style.textAlign = 'left';
			document.getElementById('sli_search_2').style.color = '#000';
			document.getElementById('sli_search_2').style.fontStyle = 'normal';
		}
	}
}

function checkMsg(){
	if (document.getElementById('sli_search_2')) {
		if (document.getElementById('sli_search_2').value == '')
		{
			document.getElementById('sli_search_2').value = '-Enter Search Term Here-';
			document.getElementById('sli_search_2').style.textAlign = 'center';
			document.getElementById('sli_search_2').style.color = '#ccc';
			document.getElementById('sli_search_2').style.fontStyle = 'italic';
		}
	}
}

function _ReadReview(itemno){
	var myRef ;
	var wid =500 ;
	var hght =500 ;
	myRef = window.open('/Read_Product_Review?itemno=' + itemno,'myreview', 'width=' + wid + ',height=' + hght + ',toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=no');
	myRef.focus();
}

function _WriteReview(itemno){
	var myRef ;
	var wid =500 ;
	var hght =500;
	myRef = window.open('/Write_Product_Review?itemno=' + itemno,'myreview', 'width=' + wid + ',height=' + hght + ',toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=no');
	myRef.focus();
}

function _GoRegister(){
	if (window.opener && !window.opener.closed)
	{
		window.opener.document.location.href = "/newCustomer"
		window.close()
		window.opener.focus()
	}
}

function ajaxsearchsubmit(form){ 
	var search = escape(form.w.value); 
	var asug = escape(form.asug.value); 
	window.location="http://golf-carts.buggiesunlimited.com/search#w="+search+"&asug="+asug; 
	return false;
}



/* BEGIN menus related functions */

var toptimeout	= 500;
var topclosetimer = 0;
var topddmenuitem = 0;
var topddsubmenuitem = 0;

function showTopDropDown(tab) {
	//topmcancelclosetime();
	if(topddmenuitem) topddmenuitem.style.visibility = 'hidden';
	if (document.getElementById('topdropdown' + tab)){
		topddmenuitem = document.getElementById('topdropdown' + tab);
		topddmenuitem.style.visibility = 'visible';
	}
}
function hideTopDropDowns() {
	if(topddmenuitem) topddmenuitem.style.visibility = 'hidden';
}

/*
function topmclosetime(){
	topclosetimer = window.setTimeout(topmclose, toptimeout);
}
function topmcancelclosetime(){
	if(topclosetimer){
		window.clearTimeout(topclosetimer);
		topclosetimer = null;
	}
}
*/

var timeout	= 500;
var closetimer = 0;
var ddmenuitem = [];

function showDropDown(tab, level) {
	if (!level) level = 1;
	if (closetimer){window.clearTimeout(closetimer); closetimer = 0;}
	hideDropDowns(level, true);
	
	if (typeof(tab)=="string"){
		var mnu = document.getElementById((level==1 ? "dropdown" : "subdropdown") + tab);
		if (mnu){
			mnu.style.visibility = 'visible';
			ddmenuitem.push(mnu);
		}
	}
}
function showSubDropDown(tab) { showDropDown(tab, 2); }

function hideDropDowns(level, t) {
	if (ddmenuitem.length){
		if (t===true){	//bool type true
			for (var i=ddmenuitem.length; i>level-1; i--){
				var mnu = ddmenuitem.pop();
				if(mnu) mnu.style.visibility = 'hidden';
			}
		} else {
			if (closetimer) window.clearTimeout(closetimer);
			closetimer = window.setTimeout("hideDropDowns("+ level +", true);", timeout);
		}
	}
}

function showSubCat(CatID) {
	if (document.getElementById(CatID).style.display == "none"){
		document.getElementById(CatID).style.display = "block";
	}else{
		document.getElementById(CatID).style.display = "none";
	}
}

/* ^ END menus related functions */

