
var gShow; //variable holding the id where feedback will be sent to.
var sUrl = "update.php?valcode=";//url is the page which will be processing all of the information.  it is important to make sure validationtype is ajax
var gErrors = 0; //number of errors is set to none to begin with
var http = getHTTPObject();//don't worry about this



function doChange()
{
	var form = document.getElementById('formpwd') 

	alert(form.oldpass.value);
}




/*validateMe is the function called with onblur each time the user leaves the input box
passed into it is the value entered, the rules (which you could create your own), and the id of the area the results will show in*/

function validateUser(user) {
	if(user==""){
		document.getElementById("uservalid").innerHTML = "<font color=\"red\">Field cannot be empty</font>";
	
	}else{
		gShow = "uservalid";
		var url="validate.php?username="+user;
		url=url+"&sid="+Math.random();
		http.open("GET", url, true);  
		http.onreadystatechange = handleHttpResponse2; 	// handle what to do with the feedback 
		http.send(null);
	}
}

function validateEmail1(email) {
	if(email==""){
		document.getElementById("emailvalid").innerHTML = "<font color=red>Field cannot be empty</font>";
		
	}else{
		gShow = "emailvalid"; 
		http.open("GET", "validate.php?email=" + email, true);  
		http.onreadystatechange = handleHttpResponse2; 	// handle what to do with the feedback 
		http.send(null);
		
	}
}
function validatePwd(pwd) {
	if(pwd==""){
		document.getElementById("pwdvalid").innerHTML = "<font color=red>Field cannot be empty</font>";
		
	}else{
		if(pwd.length < 3) {
			document.getElementById("pwdvalid").innerHTML = "<font color=red>Password must be 4 or more characters</font>";
		}else{
			document.getElementById("pwdvalid").innerHTML = "<font color=green>ok</font>";
		}
	}
}
function validatePwd2(pwd2, pswd) {
	//alert(pswd);
	if(pwd2==""){
		document.getElementById("pwd2valid").innerHTML = "<font color=red>Field cannot be empty</font>";
	}else{
		if(pwd2 != pswd) {
			document.getElementById("pwd2valid").innerHTML = "<font color=red>Password and password confirmation do not match.</font>";
		}else{
			document.getElementById("pwd2valid").innerHTML = "<font color=green>ok</font>";
		}
	}
}
function validatePwdUpdate(pwd2, pswd) {
	//alert(pswd);
	if(pwd2==""){
		document.getElementById("pwd2valid").innerHTML = "<font color=red>Field cannot be empty</font>";
	}else{
		if(pwd2 != pswd) {
			document.getElementById("pwd2valid").innerHTML = "<font color=red>Password and password confirmation do not match.</font>";
		}else{
			document.getElementById("pwd2valid").innerHTML = "<font color=green>ok</font>";
		}
	}
}
function validateName(name1) {
	if(name1==""){
		document.getElementById("namevalid").innerHTML = "<font color=red>Field cannot be empty</font>";
	}else{
		if(name1.length < 5) {
			document.getElementById("namevalid").innerHTML = "<font color=red>Name must be 6 or more characters</font>";
		}else{
			document.getElementById("namevalid").innerHTML = "<font color=green>ok</font>";
		}
	}
}

function validateEmpty(name1,id) {
    var name = id;
	if(name1==""){
		document.getElementById(name).innerHTML = "<font color=red>Field cannot be empty</font>";
		return false;
	}else{
		
		document.getElementById(name).innerHTML = "<font color=green>ok</font>";
		return true;
	}
}



 function handleHttpResponse2() {

	if(http.readyState==1 || http.readyState=="loading") {
	var throbberVal = '<img border="0" src="imgs/throbber.gif"> loading...';
	document.getElementById(gShow).innerHTML=throbberVal;
	}else if(http.readyState == 4 || http.readyState == "complete") {
	document.getElementById(gShow).innerHTML = http.responseText;
	document.getElementById(gShow).appendChild(document.createTextNode(sResults[0]));
	}
}




function validate()
{
var tables; 

tables = document.getElementsByTagName('td')

	for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "tablebg2")
		{
			//if there is a thank you or its blank then it passes
			if (tables[i].innerHTML == 'ok' || tables[i].innerHTML == '' )
			{
				tables[i].style.color = '#000000';//the color is changed to black or stays black
			}
			else
			{
				gErrors = gErrors + 1; //the error count increases by 1
				tables[i].style.color = '#ff0000';//error messages are changed to red
			}
		}
	}
		
	if (gErrors > 0)
	{
		//if there are any errors give a message
		alert ("Please make sure all fields are properly completed.  Errors are marked in red!");
		gErrors = 0;// reset errors to 0
		return false;
	}
	else return true;

}

function validateall()
{
    
    var fname = document.getElementById('fnamevalid');
	var lname = document.getElementById('lnamevalid');
	var address = document.getElementById('addressvalid');
	var country = document.getElementById('countryvalid');
	var postcode = document.getElementById('zipvalid');
	var mobile = document.getElementById('mobilevalid');
	var email = document.getElementById('emailvalid');
	var username = document.getElementById('uservalid');
	var password = document.getElementById('pwdvalid');
	var ack = document.getElementById('ackvalid');
	
	var oktag = '<font color="green">ok</font>';

	
	if(fname.innerHTML =='' && mobile.innerHTML =='' && email.innerHTML =='' && username.innerHTML =='' && password.innerHTML =='' && address.innerHTML =='' && country.innerHTML =='' && postcode.innerHTML =='' && ack.innerHTML ==''){
		gErrors = gErrors + 1; //the error count increases by 1
		
	}
	if (fname.innerHTML == oktag && mobile.innerHTML == oktag && email.innerHTML == oktag && username.innerHTML == oktag && password.innerHTML == oktag  && address.innerHTML == oktag && country.innerHTML == oktag && postcode.innerHTML == oktag && ack.innerHTML == oktag )
	{

		gErrors = 0;
	}
    
	else
	{
		gErrors = gErrors + 1; //the error count increases by 1
		
	}
		
	
		
	if (gErrors > 0)
	{
		//if there are any errors give a message
		alert ("Please make sure all fields are properly completed.");
		gErrors = 0;// reset errors to 0
		return false;
	}
	else return true;

}


function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
		xmlhttp = false;
		}
	}
	return xmlhttp;
}