<!--//
//start jquery ->
$(document).ready(function() {
//VALIDATION CHECKS
//	$('#eChk').blur(function() {
//	  validate('Email', 'email', 'eChk','errors');
//	});
//	$('#pChk').blur(function() {
//	  validate('Password', 'pword', 'pChk','errors');
//	});
//FULL FORM VALIDATIONS	
	$('#regForm').submit(function() {
	  return verify();
	});
	$('#addUser').submit(function() {
	  return chkFld();
	});
//BUTTON ACTIONS
	$('#btnCan').click(function() {
		history.go(-1);
	});
	$('.back').click(function() {
		history.go(-1); return false;
	});
	$('.switch').bind('change', function() {
		if (this.value) {$(document).location='/dataroom/?n1=dataroom&amp;c=' + this.value;}
	});
	
	
//ASSET ADMIN ONLY - OPEN NEW FILE FIELD TO ENABLE UPLOAD OF REPLACEMENT ASSET
	$('#editAsset').find('#newFile').hide().end().find('#btnRep').click(function() {
 		var addFile = $('#editAsset').find('#newFile');
         if (addFile.is(':visible')) {
 			$('#editAsset').find('#btnRep').attr("value","Replace");
            addFile.slideUp(100);
        } else {
			$('#editAsset').find('#btnRep').attr("value","Cancel");
            addFile.slideDown(100);
         }
     });
//SITE SPECIFIC FUNCTION - HIDE/SHOW CONTAINER FOR BUILDING SPECIFICATION LISTS
	$('#specList').find('div.form-container').hide().end().find('div.user-container').click(function() {
 		var answer = $(this).next();
         if (answer.is(':visible')) {
             answer.slideUp(100);
        } else {
 			$("div.form-container:visible").slideUp(100).end();
           answer.slideDown(100);
         }
     });
}); //end jquery

function validate(id,f1,f2,msgr) {
	var messenger = document.getElementById(msgr);
	var field1 = document.getElementById(f1);
	var field2 = document.getElementById(f2);
	
	if (field1.value != field2.value) {
		messenger.innerHTML = "<p><em>The " + id + " fields do not match.<br />Please correct this before continuing.</em></p>";
		messenger.className = 'errors';
		field1.className = 'error';
		field2.className = 'error';
		}
	else {
		messenger.innerHTML = ""
		messenger.className = 'ok';
		field1.className = '';
		field2.className = '';
	}
} //end validate()

function chkFld() {
	var formOK = true;
	var theErrors = "";

	if (document.forms[0].email.value != document.forms[0].eChk.value){
		theErrors = theErrors + " - The Email fields do not match.<br />";
		document.forms[0].email.className = 'error';
		formOK = false;
	}
	else {
		if (( document.forms[0].email.value.length < 1 ) || ( document.forms[0].email.value.length > 1 )){//check the Email is valid
			var AtSym = document.forms[0].email.value.indexOf('@');
			var Period = document.forms[0].email.value.lastIndexOf('.');
			var Space = document.forms[0].email.value.indexOf(' ');
			var Length = document.forms[0].email.value.length -1;
			if((AtSym < 1) || (Period <= AtSym+1) || (Period == Length) || (Space != -1)){
				theErrors = theErrors + " - Valid email is required<br />";
				document.forms[0].email.className = 'error';
				formOK = false;
			}
		}
	}
	
	
	if (formOK == true){ //submit the form 
		document.getElementById('errors').className = 'ok'; 
		return true;
	}
	else { //there are errors alert the user:
		document.getElementById('errors').innerHTML = "<p><em>" + theErrors + "</em></p>"; 
		document.getElementById('errors').className = 'errors'; 
		return false; 
 	}
}//end chkFld()

function chkCats(opt){
	

}//end chkCats()

function verify() {
	var formOK = true;
	var theErrors = "";

	if ( document.forms[0].fname.value == '' ){ //check the First Name Value
		theErrors = theErrors + " - First Name is required<br />"; 
		document.forms[0].fname.className = 'error';
		formOK = false; 
	}
	if ( document.forms[0].lname.value == '' ){ //check the Last Name Value
		theErrors = theErrors + " - Last Name is required<br />"; 
		document.forms[0].lname.className = 'error';
		formOK =  false; 
	}
	if (( document.forms[0].email.value.length < 1 ) || ( document.forms[0].email.value.length > 1 )){//check the Email is valid
		var AtSym = document.forms[0].email.value.indexOf('@');
		var Period = document.forms[0].email.value.lastIndexOf('.');
		var Space = document.forms[0].email.value.indexOf(' ');
		var Length = document.forms[0].email.value.length -1;
		if((AtSym < 1) || (Period <= AtSym+1) || (Period == Length) || (Space != -1)){
			theErrors = theErrors + " - Valid email is required<br />";
			document.forms[0].email.className = 'error';
			formOK = false;
		}
	}

	if (document.forms[0].pword.value != document.forms[0].pChk.value){
		theErrors = theErrors + " - The Password fields do not match.<br />";
		document.forms[0].pword.className = 'error';
		formOK = false;
	}
	
	if ( document.forms[0].pword.value == '' ){ //check the Password Value
		theErrors = theErrors + " - Password is required<br />"; 
		document.forms[0].pword.className = 'error';
		formOK = false; 
	}

	if ( document.forms[0].company.value == '' ){ //check the Company Value
		theErrors = theErrors + " - Company is required<br />"; 
		document.forms[0].company.className = 'error';
		formOK = false; 
	}
	if ( document.forms[0].country.selectedIndex < 1 ){ //check the Country has been selected
		theErrors = theErrors + " - Country is required<br />"; 
		document.forms[0].country.className = 'error';
		formOK = false; 
	}
	if ( document.forms[0].type.selectedIndex < 0 ){ //check the Type of Account has been selected
		theErrors = theErrors + " - Type of Account is required<br />"; 
		document.forms[0].type.className = 'error';
		formOK = false; 
	}
	if ( document.forms[0].status.checked != true ){ //check the User Status is set
		theErrors = theErrors + " - User Status is required<br />"; 
		document.forms[0].status.className = 'error';
		formOK = false; 
	}
	if (formOK == true){ //submit the form 
		document.getElementById('errors').className = 'ok'; 
		return true;
	}
	else { //there are errors alert the user:
		document.getElementById('errors').innerHTML = "<p><em>" + theErrors + "<br />Please correct this before continuing.<br /></em></p>"; 
		document.getElementById('errors').className = 'errors'; 
		return false; 
 	}
}//end verify()

//-->
