
function changeProp(objId,x,theProp,theValue) {
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
function MDLpreloadImages() {
  var d=document; if(d.images){ if(!d.MDLp) d.MDLp=new Array();
    var i,j=d.MDLp.length,a=MDLpreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MDLp[j]=new Image; d.MDLp[j++].src=a[i];}}
}
function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

<!-- //begin xitpop code -->
var exit=true;
function xitpop()
{
if (exit)
open('msg_modal.cfm<cfif isdefined("url.rep_id") and isdefined("url.m_id")>?rep_id=#url.rep_id#&m_id=#url.m_id#</cfif>','','toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0,toolbar=0,location=0,directories=0,height=420,width=620');
}
// end xitpop code -->


<!-- //begin privacy_pop code -->
function privacy_pop(x){
	if(x==1){
	open ('privacy-policy-check.cfm','','toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0,toolbar=0,location=0,directories=0,height=300,width=400');
	}
	if(x==2){
	open ('privacy-policy.cfm','','toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,toolbar=0,location=0,directories=0,height=1000,width=900');
	}
}
function open_win(theURL,winName,features) { 
   
  var mainWin = self;
		if( window.winName == null )      // If the window has never been opened
			winName=window.open(theURL, winName, features);
		else {
		if( window.winName.closed )    // If the window was open but has been closed
			winName=window.open(theURL,  winName, features);
		else                                                                       // The window is already open
			winName.location.href = theURL;
		}
		winName.opener = mainWin;
		winName.focus();
  
}


///-------------------Conference Validation-----------///
function conference_valid() {
	//Initialization
	var docs = document.forms.posting;
	var message = "";

	if ((docs.title.value.length == 0) || (docs.title.value.indexOf(" ") == 0)) {
		message += "Missing Title\n";
	}
	if ((docs.url.value.length == 0) || (docs.url.value == "http://") || (docs.url.value.indexOf(" ") == 0)) {
		message += "Missing URL Address\n";
	}		
	//these lines are required to actually get the text correctly ...
	var temp_rich_text = ColdFusion.RichText.getEditorObject('body'); 
	docs.body.value = temp_rich_text.GetXHTML(true);
	if (docs.body.value.length == 0) {
		message += "Missing Body\n";
	}
	if (docs.body.value.length > 2000) { 					
		message += "Over 2000 Character Limit ("+docs.body.value.length+") For Body";
	}
	if ((docs.email.value.length == 0) || (docs.email.value.indexOf(" ") == 0)) {
		message += "Missing Email Address\n";
	}
	if (docs.start_dt.value.length == 0) {
		message += "Missing State Date\n";	
	}
	if (docs.end_dt.value.length == 0) {
		message += "Missing End Date\n";	
	}

	//Inappropiate Characters for Email Names
	s = docs.email.value;
	var characters = " ,/<>?!`';:#$%^&*()+|{}[]" + '"' + "\\\t\n";
	if (s.length > 0) {

		for (var i=0; i < characters.length; i++) {
			for (var j=0; j < s.length; j++) { 
				if (s.charAt(j) == characters.charAt(i)) {
					var unit = characters.charAt(i);
					if (unit == " ") {
						unit = "[empty space]";
					};				
					message += "Inappropiate Character " + unit + " for Email Name\n";
				};
			};
		};
	};	
	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;
	
	// look for @
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}
	
	if ((i >= sLength) || (s.charAt(i) != "@")) {
		message += "Invalid E-mail Address - No @\n";
	} else {
		i += 2;
	};

	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}
	
	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		message += "Invalid E-mail Address - No .\n";
	};
	
	if ((docs.city.value.length == 0) || (docs.city.value.indexOf(" ") == 0)) {
		message += "Missing City\n";
	};			
	if (docs.state_cd.value == "" && docs.country.value == "USA") {
		message += "Missing State\n";
	};		
	if (docs.country.value == "") {
		message += "Missing Country\n";
	};		
	if (((docs.zip.value.length == 0) || (docs.zip.value.indexOf(" ") == 0)) && docs.country.value == "USA") {
		message += "Missing Zip Code\n";
	};		
	return message;	
};

//Form Submission
function conference_checkform() {
	var error_message = conference_valid();
	if (error_message != "") {
		alert(error_message);
		return false;
	} else {
		return true;
	};
};	
//-----------------End of Conference validation------------///

//-----------------Registration ------------///

$(document).ready(function(){
	//global vars
	var form = $("#customForm");
	var fname = $("#fname");
	var lname = $("#lname");
	var fnameInfo = $("#fnameInfo");
	var lnameInfo = $("#lnameInfo");
	var email = $("#email");
	var emailInfo = $("#emailInfo");
	var email2 = $("#email2");
	var email2Info = $("#email2Info");
	var password = $("#password");
	var passwordInfo = $("#passwordInfo");
	var pass2 = $("#pass2");
	var pass2Info = $("#pass2Info");
	var message = $("#message");
	var profession = $("#profession");
	var country = $("#country");


	//On key press
	fname.change(validateFirstName);
	lname.change(validateLastName);
	password.change(validatePass1);
	pass2.change(validatePass2);
	email.change(validateEmail);
	email2.change(validateEmail2);
	profession.change(showProfDetails);
	country.change(validateCountry);
	
	//On Submitting
	form.submit(function(){
		if(validateFirstName() & validateLastName() & validateEmail()& validateEmail2() & validatePass1() & validatePass2() & validateCountry())
			return true
		else
			return false;
	});
	
	//validation functions
	function validateEmail(){
		//testing regular expression
		var a = $("#email").val();
		var filter = (/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|cat|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i);
		//if it's valid email
		if(filter.test(a)){
			email.removeClass("error2");
			emailInfo.text("OK, this email address is valid!");
			emailInfo.removeClass("error2");
			emailInfo.addClass("success2");
			return true;
		}
		//if it's NOT valid
		else{
			email.removeClass("success2");
			emailInfo.text("Error! Type a valid e-mail please!");
			emailInfo.removeClass("success2");
			email.addClass("error2");
			emailInfo.addClass("error2");
			return false;
		}
	}
	function validateEmail2(){
		var a = $("#email");
		var b = $("#email2");
		//are NOT valid
		if( email.val() != email2.val()){
			email2.addClass("error2");
			email2Info.text("E-Mail doesn't match!");
			email2Info.removeClass("success2");
			email2Info.addClass("error2");
			return false;
		}
		//are valid
		else{
			email2.removeClass("error2");
			email2Info.text("Ok! E-Mail matches!");
			email2Info.removeClass("error2");
			email2Info.addClass("success2");
			return true;
		}
	}
	function validateFirstName(){
		//if it's NOT valid
		if(fname.val().length < 2){
			fname.addClass("error2");
			fnameInfo.text("We want first names with more than 2 letters!");
			fnameInfo.addClass("error2");
			return false;
		}
		//if it's valid
		else{
			fname.removeClass("error2");
			fnameInfo.text("That is a valid first name!");
			fnameInfo.removeClass("error2");
			fnameInfo.addClass("success2");
			return true;
		}
	}
	function validateLastName(){
		//if it's NOT valid
		if(lname.val().length < 2){
			lname.addClass("error2");
			lnameInfo.text("We want last names with more than 2 letters!");
			lnameInfo.addClass("error2");
			return false;
		}
		//if it's valid
		else{
			lname.removeClass("error2");
			lnameInfo.text("That is a valid last name!");
			lnameInfo.removeClass("error2");
			lnameInfo.addClass("success2");
			return true;
		}
	}
	function validatePass1(){
		var a = $("#password1");
		var b = $("#password2");

		//it's NOT valid
		if(password.val().length <4){
			password.addClass("error2");
			passwordInfo.text("Remember: At least 4 characters: letters and numbers");
			passwordInfo.addClass("error2");
			return false;
		}
		//it's valid
		else{			
			password.removeClass("error2");
			passwordInfo.text("OK, valid password!");
			passwordInfo.removeClass("error2");
			passwordInfo.addClass("success2");
			validatePass2();
			return true;
		}
	}
	function validatePass2(){
		var a = $("#password1");
		var b = $("#password2");
		//are NOT valid
		if( password.val() != pass2.val() ){
			pass2.addClass("error2");
			pass2Info.text("Passwords doesn't match!");
			pass2Info.addClass("error2");
			return false;
		}
		//are valid
		else{
			pass2.removeClass("error2");
			pass2Info.text("OK, passwords match!");
			pass2Info.removeClass("error2");
			pass2Info.addClass("success2");
			return true;
		}
	}
	
	function showProfDetails(){
		if ($("#profession").val() == 1 || $("#profession").val() == 21) {
			$('div.professiondetails').show();
			$('div.professiondetails2').show();
		}
		else {
			$('div.professiondetails').hide();
			$('div.professiondetails2').hide();
		}
	}
	
	function validateCountry(){
		//if it's NOT valid
		if(country.val() == ""){
			country.addClass("error2");
			countryInfo.text("Please select the country in which you live!");
			countryInfo.addClass("error2");
			return false;
		}
		//if it's valid
		else{
			country.removeClass("error2");
			countryInfo.text("You have selected a country!");
			countryInfo.removeClass("error2");
			countryInfo.addClass("success2");
			return true;
		}
	}
	
	showProfDetails()
		
});

//TestInputType(objValue, , strError, objValue.name + ": Only alpha-numeric characters allowed ");

function chkAlphaNum(objValue){
	
	var strRegExp = "[^A-Za-z0-9\\s,.@$%&*()]";
	var ret = true;
	
	var charpos = objValue.value.search(strRegExp);
	if (objValue.value.length > 0 && charpos >= 0) {
		ret = false;
	}
	
	return ret;
}
