//CHECK PASSWORDS
function verifyPasswords(password, verifypassword){
	if(password != verifypassword){
		alert("Password and Password verification do not match!");
		return false;
	}else{
		return true;
	}
}
function returnTrueOrFalse(passwd, verifypass,email, theform){
	var error;
	if(passwd && verifypass){
		if(verifyPasswords (passwd, verifypass) == false){
			return false;
		}
	}
	if(email){
		if(emailCheck (email) == false){
			return false;
		}
	}
	if(checkThisForm('', theform) == false){
		return false;
	}else{
		return true;
	}

}
function checkEmailAndRequired(email, theformname){
	var numofforms = document.forms.length;
	var fn; //form number
	for(x=0;x<numofforms;x++){
		if(document.forms[x].name == theformname){
			fn = x;
		}		
	}
	if(checkThisForm(fn) == false){
		alert("Information needs to be entered to continue.");
		return false;
	}
	if(email){
		if(emailCheck (email) == false){
			alert("Please verify email address.");
			return false;
		}else{

		}
	}else{
			alert("Please verify email address.");
			return false;
	}

}
function checkRequired(f, theformname){
	var error = 0;
	var x;
	var theform;
	var numofforms = document.forms.length;
	//alert(numofforms);
	if(theformname){
		var f; //form number
		for(x=0;x<numofforms;x++){
			if(document.forms[x].name == theformname){
				f = x;
			}		
		}
	}
	if(f == ''){
		f = "NOTHING";
	}
	//alert(f);
	if(isNaN(f)){
		theform = document.signupform;
	}else{
		theform = document.forms[f];
	}
	if(theform){
		var i = theform.elements.length;
	
		//CHECK THE ENTIRE FORM FOR MISSING INFORMATION 
		//(PLACE THIS CODE AT THE END OF YOUR INC FILE TO CHECK THE FORM AT LOAD TIME)
		for(x=0;x<i;x++){
			if(theform.elements[x].id == 'REQ'){
				var e = theform.elements[x];
				e.onblur = function() { 
					checkRequired(f);  
				}
				if(theform.elements[x].value!=""){
					//alert("test");
				}
				if(theform.elements[x].value==""){
				if(x==0){
					//alert("test");
				}
					theform.elements[x].style.backgroundColor = '#FFFACD';
					//error++;
				}else{
					theform.elements[x].style.backgroundColor = '#FFFFFF';
				}
			}
		}
	}
}
function checkThisForm(f, theformname){
	var error = 0;
	var x;
	var theform;
	var pass;
	var message = "ATTENTION: Some required fields are missing information.";
	var numofforms = document.forms.length;
	var labelid = new Array();
	//alert(theformname);
	if(theformname){
		var f; //form number
		for(x=0;x<numofforms;x++){
			if(document.forms[x].name == theformname){
				f = x;
			}		
		}
	}
	
	if(f == '0'){
		f=0;
	}else if(f==''){
		f = "NOTHING";
	}
	
	if(isNaN(f)){
		theform = document.signupform;
	}else{
		theform = document.forms[f];
	}
	
	if(theform){
		var i = theform.elements.length;
		var thevalue;
		//CHECK THE ENTIRE FORM FOR MISSING INFORMATION 
		//(PLACE THIS CODE AT THE END OF YOUR INC FILE TO CHECK THE FORM AT LOAD TIME)
		for(x=0;x<i;x++){

			if(theform.elements[x].id == "REQ"){
				
				if(theform.elements[x].selectedIndex == 0){
					thevalue = theform.elements[x][theform.elements[x].selectedIndex].value;
					notselecttype=0;
				}else{
					thevalue = theform.elements[x].value;
					notselecttype=1;
					
				}
				
				if(thevalue == ""){
					theform.elements[x].style.backgroundColor = '#FFFACD';
					error++;
				}else{
					theform.elements[x].style.backgroundColor = '#FFFFFF';
				}
				
			}
		}
	    if(error > 0) {
			if(document.getElementById("message")){
				alert(message);
				document.getElementById("message").style.color = '#FF0000';
				if(pass == 1){
					document.getElementById("message").innerHTML = "ATTENTION: Password Verify does not match!";
				}else{
					document.getElementById("message").innerHTML = message;
				}
			}
			if(document.getElementById("messagepart2")){
				document.getElementById("messagepart2").style.color = '#FF0000';
				document.getElementById("messagepart2").innerHTML = message;
			}
			return false;
		}
		return true;
	}else{
		return true;
	}
}
/********************************************************************
1. CREATE A CASCADING STYLE SHEET WITH THE ELEMENTS THAT ARE REQUIRED
Example:
SELECT.required{
	background-color: #F5DEB3;
}
INPUT.required{
	background-color: #F5DEB3;
}
2. INSERT AN ID="REQ" INTO THE FIELDS THAT ARE REQUIRED
*********************************************************************/

//THIS DEFINES THE NAME OF THE STYLE SHEET CALLS
function colorChange(){
	if(this.value == ''){
		return 'required';
	}else{
		return 'white';
	}
}

//THIS IS A FUNCTION USED TO DIRECTLY CHANGE THE BACKGROUND COLOR OF A FIELD
function correctColor(acolor){
	if(acolor){
		this.thing.style.backgroundColor = acolor;
	}else{
		this.thing.style.backgroundColor ='#FFFFFF';
	}
}

//THIS IS AN OBJECT WHICH CALLS ALL OF THE FUNCTIONS
function RequiredFields(theelement){
	this.thing = theelement;
	this.value = theelement.value;
	this.color = colorChange;
	this.changeColor = correctColor;
}

function reloadPage(url){
   location.replace(url);
}
function warn_on_submit(job) {
   var msg = "\nAre you sure you want to delete " + job + "?";
	if(confirm(msg)){
	   //form.submit();
	   return true;
	}else{
	   return false;
	}
	 
}

function openNewWindow(passurl, passwidth, passheight) {
  var url = passurl;
  var newwidth = passwidth;
  var newheight = passheight;

  popupWin = window.open(url, '','scrollbars=yes,resizable,dependent,width=' + newwidth + ', height=' + newheight + ',left=0,top=0');
  //document.view.submit();
}
function verifyOther(f){
	if(!f){
		var theform = document.signupform;
	}else{
		var theform = document.forms[f];
	}
	var i = theform.state.selectedIndex;
	if(theform.state[i].value == 'OT'){
		theform.state_other.disabled = false;
		theform.state_other.style.backgroundColor = '#F5DEB3';
		theform.state_other.id = "REQ";
	}else{
		theform.state_other.style.backgroundColor = '#FFFFFF';
		theform.state_other.value='';
		theform.state_other.disabled = true;
		theform.state_other.id = "";
	}
}
function headerDisplay(num){ 
	var headerBox, visible, hidden;
	if((IE || NS)){
        if (document.layers){
			visible = 'show';
			hidden = 'hide';
			headerBox = document.layers['headerInfo'];
	    }else if (document.all){
			visible = 'visible';
			hidden = 'hidden';
			headerBox = document.all('headerInfo').style;
	    }else if (document.getElementById){
			visible = 'visible';
			hidden = 'hidden';
			headerBox = document.getElementById('headerInfo').style;
		}
		if(num==1){
			headerBox.display = 'block';
		}else{
			headerBox.display = 'none';
		}
	}
	return;
}
function multiHeaderDisplay(elementname, elementnum, num, numimages,hide){ 
	var headerBox, visible, hidden, x, imageclassname;
	if((IE || NS)){
        if (document.layers){
			if(num==1){
				for(x=0; x < numimages ; x++){
					imageclassname=document.layers[elementname+x].display = 'none';
				}
			}
			headerBox = document.layers[elementname+elementnum].display = 'block';
			if(hide==1){
				headerBox = document.layers[elementname+elementnum].display = 'none';
			}
			
	    }else if (document.all){
			if(num==1){
				for(x=0; x < numimages ; x++){
					imageclassname=document.all(elementname+x).style.display = 'none';
				}
				
			}
			imageclassname=document.all(elementname+elementnum).style.display = 'block';
			if(hide==1){
				imageclassname=document.all(elementname+elementnum).style.display = 'none';
			}
	    }else if (document.getElementById){
			//alert(elementname+elementnum);
			if(num==1){
				for(x=0; x < numimages ; x++){
					imageclassname=document.getElementById(elementname+x).style.display = 'none';
				}
				
			}
			headerBox = document.getElementById(elementname+elementnum).style.display = 'block';
			if(hide==1){
				headerBox = document.getElementById(elementname+elementnum).style.display = 'none';
			}
		}
	}
	return;
}
function checkRequiredElementsOnAllForms(){
	var error = 0;
	var x;
	var theform;
	var numofforms = document.forms.length;
	
	var f; //form number
	for(x=0;x<numofforms;x++){
		theform = document.forms[x];
		var j = theform.elements.length;
		
		//CHECK THE ENTIRE FORM FOR MISSING INFORMATION 
		//(PLACE THIS CODE AT THE END OF YOUR INC FILE TO CHECK THE FORM AT LOAD TIME)
		for(i=0;i<j;i++){
			if(theform.elements[i].id == 'REQ'){
				var e = theform.elements[i];
				e.onblur = function() { 
					checkRequired(f);  
				}
				if(theform.elements[i].value==""){
					theform.elements[i].style.backgroundColor = '#F5DEB3';
				}else{
					theform.elements[i].style.backgroundColor = '#FFFFFF';
				}
			}
		}
	}
}
function gotoSelection(formnumber){
	var theform = document.forms[formnumber];
	var server = theform.servername.value;
	var category = theform.category_id.value;
	location.href = server + "/category/" + category;
}

function CopyToClipboard(){
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
}
function HighlightAll(theField) {
	var tempval=eval("document."+theField)
	tempval.focus()
	tempval.select()
	if (document.all&&copytoclip==1){
		therange=tempval.createTextRange()
		therange.execCommand("Copy")
		window.status="Contents highlighted and copied to clipboard!"
		setTimeout("window.status=''",1800)
	}
}

