function validEmail(email) {
			var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
			return re.test(email); 
		}

function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/5/07
	switch(elm.type){
	case "text":
		if (elm.value == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (elm.value == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (elm.value == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

function validateform(formname){
	//last updated by Sol on 6/06/07
	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		  if (x.elements[i].className == "required" ) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = "yellow"; 
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = ""; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}

function logina(formname) {
	if(validateform(formname)){
		validatelogin(formname);
	}
}
	
function validatelogin(formname){
	var xmlHttpObj;
    xmlHttpObj = CreateXmlHttpRequestObject();
    if (xmlHttpObj)
    {	
		var url="/ajax/userexists.asp";
		xmlHttpObj.open('POST',url, true);
		var parameters;
		parameters = '';
		var formlength = document.forms[formname].elements.length
		for(i=0; i < formlength; i++)
		{
			parameters += document.forms[formname].elements[i].name + "=" + encodeURI(document.forms[formname].elements[i].value)
			if (i != formlength){
				parameters +=  "&";
			}
		}
        xmlHttpObj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xmlHttpObj.onreadystatechange = function() { 
            if ( xmlHttpObj.readyState == 4 )
            {
			var response = xmlHttpObj.responseText;
			//alert (response);
			//return false;
				if (response=='true'){
					location.href = "/login.asp"
				} else{
					document.getElementById("validatemessage").innerHTML = "Invalid User Name or Password.<br/><br/>"
					Effect.Appear('validatemessage','blind');
				}
            }
        }
         xmlHttpObj.send(parameters);
    }
}

function emailpassworda(formname,validateid){
	//VALIDATE REQUIRED
	if(validateform(formname)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("passwordemail").value;
		if(!validEmail(email)){
			document.getElementById("passwordemail").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = '<br>Invalid Email<br><br>';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			
			//AJAX POST
			new Ajax.Request('/ajax/emailpassword.asp', {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) { 
			document.getElementById(validateid).innerHTML = transport.responseText;
			
			Effect.Appear(validateid,'blind');
			
			}//-onSuccess
			}//-request arguments
			);// new ajax request	
			}
	}
}

function newaccount(formname,validateid){
	//VALIDATE REQUIRED
	if(validateform(formname)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = '<br>Invalid Email<br><br>';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {
				
			//PASSWORDS	MATCH?
			var condition1 = document.getElementById("passworda").value;
			var condition2 = document.getElementById("passworda2").value;
			if (!arethesame(condition1,condition2)){
			    document.getElementById(validateid).innerHTML = '<br>Your Password Don\'t Match<br><br>';
				document.getElementById("passworda").style.background = "yellow"; 
				document.getElementById("passworda2").style.background = "yellow"; 
				} else
				
			//AJAX POST
			new Ajax.Request('/ajax/newaccount.asp', {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) { 
			document.getElementById(validateid).innerHTML = transport.responseText;
			
			Effect.Appear(validateid,'blind');
			
			}//-onSuccess
			}//-request arguments
			);// new ajax request	
			}
	}
}

	

function validEmail(email) {
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return re.test(email); 
	}

function arethesame(condition1,condition2){
	if (condition1 == condition2) {
			return true;
			} else {
			return false;
			}
}

function CreateXmlHttpRequestObject()
{
    var xmlObj;
    if (window.ActiveXObject)
    {
        try
        {
           xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e)
        {
           xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    else
        xmlObj = new XMLHttpRequest();
    return xmlObj;
}

//ROLLOVER
function setupRollover(thisImage) {
	var a = thisImage.src.split("/");
	var a_length = a.length-1;
	aa = a[a_length];
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.src = "/gl_images/nav/on/" + aa ;
	thisImage.onmouseover = rollOver;	
}

//ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].getAttribute('name') == "rollover") {			
			setupRollover(document.images[i]);
		}
	}
}

//ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

function productrollover(){
	
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++)
  	{
	//alert('a');
	if (x[i].id.indexOf("productrow")>-1){
		
		var element = document.getElementById(x[i].id);
		element.style.padding = '6px 12px 6px 0px';
		element.style.width = '500px';
		element.style.borderTop = '1px #cccccc solid';
		element.style.cssFloat = 'left';
		element.style.background = 'white';
		element.onmouseover = rollover2;
		element.onmouseout  = rollout2;
		element.onclick = clickme2;
	}
  	}
}

function clickme2(){
	var messageid = this.id.replace('productrow','');
	var linkid = 'link' + messageid
	var thelink = document.getElementById(linkid).href;
	window.location.href = thelink;
}

function rollover2(){
	this.style.backgroundColor='#F9F9F9';
	this.style.cursor = 'pointer';
}

function rollout2(){
	this.style.backgroundColor='white';
}

window.onload = masterloader;

function masterloader(){
	rolloverInit();
	productrollover();
}
