function redirect(www)
{
	window.location = www;
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function createAccount(theForm)
{
	redirect('index.php?page=create&go');
}

function checkPass()
{
	passOne = document.getElementById("pw1").value;
	passTwo = document.getElementById("pw2").value;
	passBox = document.getElementById("checkPassImg");
	
	if(passOne != passTwo)
	{
		passBox.innerHTML = '<img src="images/bad.png">';
	}else{
		passBox.innerHTML = '<img src="images/good.png">';
	}
}

function checkUser()
{
	userText= document.getElementById("username").value;
	userBox = document.getElementById("checkUserImg");
	
	xmlhttp = new GetXmlHttpObject();;
	xmlhttp.open('GET', 'db.php?username='+userText, false);
	xmlhttp.send(null);
	
	if (xmlhttp.readyState==4)
	{
		userBox.innerHTML = xmlhttp.responseText;
	}
}

function checkEmail()
{
	email = document.getElementById("email");
	emailBox = document.getElementById("checkEmail");
	
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value))
	{
		emailBox.innerHTML = '<img src="images/bad.png">';
	}else{
		emailBox.innerHTML = '<img src="images/good.png">';
	}
}

function goSearch(e)
{
	var terms = document.getElementById("mainSearch").value;
	if(terms != "" && terms != "Type in your search term here. Example (Rims, Auto Auctions, Tires)")
	{
		var key;

		 if(window.event)
		 {
			  key = window.event.keyCode;
		 }else{
			  key = e.which;
		}

		if (key == 13)
		{
			window.location = "index.php?page=search&terms=" + terms;
		}
	}
}

function goSearchSMPP(e)
{
	var terms = document.getElementById("smppSearch").value;
	if(terms != "" && terms != "Enter a specialty manufacturer or product. Example (Cables, Bulldog Security)")
	{
		var key;

		 if(window.event)
		 {
			  key = window.event.keyCode;
		 }else{
			  key = e.which;
		}

		if (key == 13)
		{
			window.location = "index.php?page=smpp&terms=" + terms;
		}
	}
}

function buttonSearch(boxid)
{
	var terms = document.getElementById(boxid);
	
	if(terms.id == "mainSearch")
	{
		if(terms.value != "" && terms.value != "Type in your search term here. Example (Rims, Auto Auctions, Tires)")
		{
			window.location = "index.php?page=search&terms=" + terms.value;
		}
	}
	
	if(terms.id == "smppSearch")
	{
		var category = document.getElementById("smpp_category");
		if(terms.value != "" && terms.value != "Enter a specialty manufacturer or product. Example (Cables, Bulldog Security)")
		{
			window.location = "index.php?page=smpp&terms=" + terms.value;
		}
	}
}

function conf_chg(url)
{
	var selectedState = document.getElementById("theState");
	var getOption = selectedState.options[selectedState.selectedIndex].value;
	redirect(url + "&selState=" + getOption);
}

function clearText(boxid)
{
	var terms = document.getElementById(boxid);
	if(terms.value == "Type in your search term here. Example (Rims, Auto Auctions, Tires)")
	{
		terms.value = "";
		terms.style.color = "#252525";
		return;
	}
	if(terms.value == "Enter a specialty manufacturer or product. Example (Cables, Bulldog Security)")
	{
		terms.value = "";
		return;
	}
}

function searchText(boxid)
{
	var terms = document.getElementById(boxid);
	if(terms.id == "mainSearch")
	{
		if(terms.value == "Type in your search term here. Example (Rims, Auto Auctions, Tires)")
		{
			terms.value = "";
		}
		
		if(terms.value == "")
		{
			terms.value = "Type in your search term here. Example (Rims, Auto Auctions, Tires)";
			terms.style.color = "#666";
		}
		return;
	}
	
	if(terms.id == "smppSearch")
	{
		if(terms.value == "Enter a specialty manufacturer or product. Example (Cables, Bulldog Security)")
		{
			terms.value = "";
		}
		
		if(terms.value == "")
		{
			terms.value = "Enter a specialty manufacturer or product. Example (Cables, Bulldog Security)";
			terms.style.color = "#666";
		}
		return;
	}
}

function submitform(theform)
{
    document.forms[theform].submit();
}
