// JavaScript Document

function hideUnhide(eid){
	$cval = document.getElementById(eid).style.display;
	if($cval == "" || $cval == "none"){
		document.getElementById(eid).style.display = "block";
	}else{
		document.getElementById(eid).style.display = "none";
	}
}

function openCourseSel() {
	window.open("coursesel.html", "Window2","width=910,height=450,scrollbars=yes,location=no");
}

function returnthisval(eid, dval, valuid){
	var ctitle = document.getElementById(eid).innerHTML;
	if(dval == "dayone"){
		window.opener.document.getElementById('dayonecourse').innerHTML = ctitle;
		window.opener.document.getElementById('dayonecoursetitle').value = ctitle;
		window.opener.document.getElementById('dayonecourseid').value = valuid;
	}else if(dval == "daytwo"){
		window.opener.document.getElementById('daytwocourse').innerHTML = ctitle;
		window.opener.document.getElementById('daytwocoursetitle').value = ctitle;
		window.opener.document.getElementById('daytwocourseid').value = valuid;
	}else if(dval == "daythree"){
		window.opener.document.getElementById('daythreecourse').innerHTML = ctitle;
		window.opener.document.getElementById('daythreecoursetitle').value = ctitle;
		window.opener.document.getElementById('daythreecourseid').value = valuid;
	}else if(dval == "dayfour"){
		if(valuid == 15){
			ctitle = document.getElementById(eid).innerHTML + ' & ' + document.getElementById(eid+'2').innerHTML;
		}
		window.opener.document.getElementById('dayfourcourse').innerHTML = ctitle;
		window.opener.document.getElementById('dayfourcoursetitle').value = ctitle;
		window.opener.document.getElementById('dayfourcourseid').value = valuid;
	}else if(dval == "dayfive"){
		window.opener.document.getElementById('dayfivecourse').innerHTML = ctitle;
		window.opener.document.getElementById('dayfivecoursetitle').value = ctitle;
		window.opener.document.getElementById('dayfivecourseid').value = valuid;
	}
}
function onMourseFocusInEffect(eid){
	document.getElementById(eid).style.background = "#eeeeee";
}			
function onMourseFocusOutEffect(eid){
	document.getElementById(eid).style.background = "#ffffff";
}	

/* New function for second version of work */
function onMourseFocusInEffectForClosedSubject(eid){
	document.getElementById(eid).style.background = "#990000";
}			
function returnCloseMessage(eid){
	var courseName = document.getElementById(eid).innerHTML;
	alert("This Course ["+courseName+"] is CLOSED. Please select from other courses.");
	return false;
}
/* end of new function */
/*
	Functions for form validations
	by Mohammad Belal Hossain
	on February 2009
	parameter: eid = element id
	return: if value is null it returns false
*/
function isNull(eid) {
	var val = document.getElementById(eid).value;

	if(val == ""){
		alert("You can not leave this field blank");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
	}
	return true;
}
function isDivNull(eid) {
	var val = document.getElementById(eid).innerHTML;

	if(val == "&nbsp;"){
		alert("You can not leave this field blank");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
	}
	return true;
}

/*
	Functions for form validations
	by Mohammad Belal Hossain
	on February 2009
	parameter: eid = element id
	return: if value is null it returns true
*/
function isEqual(eid1,eid2,msg) {
	var val1 = document.getElementById(eid1).value;
	var val2 = document.getElementById(eid2).value;

	if(val1 != val2){
		alert(msg);
		document.getElementById(eid1).style.border = '1px solid #990000';
		document.getElementById(eid2).style.border = '1px solid #990000';
		document.getElementById(eid1).focus();
		return false;
	}
	return true;
}

/*
	Functions for form validations
	by Mohammad Belal Hossain
	on February 2009
	parameter: eid = element id
	return: if value is numeric it returns false
*/
function isNumeric(eid) {
	var val = document.getElementById(eid).value;

	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(val)){
		alert("Value should be numeric numeric");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
	}
	return true;
}

function verifyEmail(eid){
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

	 if (document.getElementById(eid).value.search(emailRegEx) == -1) {
		alert("Please enter a valid email address.");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
     }
     return true;
}

function checkDropdown(eid,highlight_eid) {
    if (document.getElementById(eid).selectedIndex == 0) {
       alert("You didn't choose an option from the drop-down list.");
	   document.getElementById(highlight_eid).style.border = '1px solid #990000';
	   return false;
    }
	document.getElementById(highlight_eid).style.border = 'none';
	return true;
}

function removeCR(eid){
	checkString = document.getElementById(eid).value;
	if(checkString != ""){
		newString = "";    // REVISED/CORRECTED STRING
		count = 0;         // COUNTER FOR LOOPING THROUGH STRING
		pointer = 0;
		// LOOP THROUGH STRING CHARACTER BY CHARACTER
		for (i = 0; i < checkString.length; i++) {
			ch = checkString.substring(i, i+1);
			//if ((ch >= "#Chr(44)#") || (ch = "#Chr(32)#")){
			if(ch == ","){
				pointer = 1;
				continue;
			}else {
				newString += ch;
			}
		}
		if(pointer == 1){
			alert("Sorry, You can not use comma for this field, so we have removed commas");
			document.getElementById(eid).value = newString;
			document.getElementById(eid).style.border = '1px solid #000000';
			document.getElementById(eid).focus();
			return true;
		}
	}else{
       alert("You can not leave City, State, Zip field emaplty.");
	   document.getElementById(eid).style.border = '1px solid #990000';
 	   document.getElementById(eid).focus();
	   return false;
	}
	return true;
}

 

function validateRegForm () {
	//validate if the user name field is empty or not
	if(isNull('firstname')){

		//validate if the given email is empty or not
		if(isNull('lastname')){

			//validate if the given email is empty or not
			if(isNull('position')){
				
				//validate if the given email is empty or not
				if(document.getElementById('pos_type1').checked == true || document.getElementById('pos_type2').checked == true|| document.getElementById('pos_type3').checked == true){
					document.getElementById('pos_type_radios').style.border = 'none';
					
					//validate if the given email is empty or not
					if(isNull('organization')){
						
						//validate if the given email is empty or not
						if(document.getElementById('org_type1').checked == true || document.getElementById('org_type2').checked == true){
							document.getElementById('org_type_radios').style.border = 'none';
							
							//validate if the given email is empty or not
							if(isNull('email')){
								
								//validate if the given email address is valid or not
								if(verifyEmail('email')){

									//validate if the given email address is valid or not
									if(isNull('address')){

										//validate if the given email address is valid or not
										if(isNull('city_state')){
											
											if(checkDropdown('country','countryseloption')){
												//validate if the given email address is valid or not
												if(isNull('phone')){
													
													//validate if the given email address is valid or not
													if(isNull('fax')){
														
														//validate if the given email address is valid or not
														if(isNull('arrival_date')){
															
															//validate if the given email address is valid or not
															if(isNull('arrival_flight')){

																//validate if the given email address is valid or not
																if(isNull('depart_date')){
																	
																	//validate if the given email address is valid or not
																	if(isNull('depart_flight')){

																		//validate if the given email address is valid or not
																		if(isDivNull('dayonecourse')){
																			
																			//validate if the given email address is valid or not
																			if(isDivNull('daytwocourse')){
																				
																				//validate if the given email address is valid or not
																				if(isDivNull('daythreecourse')){
																					
																					//validate if the given email address is valid or not
																					if(isDivNull('dayfourcourse')){
																						
																						//validate if the given email address is valid or not
																						if(isDivNull('dayfivecourse')){
																							
																							if(document.getElementById('tshirt1').checked == true || 
																							   document.getElementById('tshirt2').checked == true || 
																							   document.getElementById('tshirt3').checked == true || 
																							   document.getElementById('tshirt4').checked == true || 
																							   document.getElementById('tshirt5').checked == true){

																								document.getElementById('tshirt_radios').style.border = 'none';

																								if(document.getElementById('payment1').checked == true || 
																									document.getElementById('payment2').checked == true){

																									document.getElementById('payment_radios').style.border = 'none';
																									if(removeCR('city_state')){
																										return true;
																									}
																								}else{
																									alert("Please indicate your method of payment.");
																									document.getElementById('payment_radios').style.border = '1px solid #990000';
																									return false;
																								} // payment1, payment2
																							}else{
																								alert("Please indicate your prefered t-shirt size.");
																								document.getElementById('tshirt_radios').style.border = '1px solid #990000';
																								return false;
																							} //tshirt1, tshirt2, tshirt3, tshirt4, tshirt5
																						} //if(isNull('dayfivecourse')){
																					} //if(isNull('dayfourcourse')){
																				} //if(isNull('daythreecourse')){
																			} //if(isNull('daytwocourse')){
																		} //if(isNull('dayonecourse')){
																	} //if(isNull('depart_flight')){
																} //if(isNull('depart_date')){
															} //if(isNull('arrival_flight')){
														} //if(isNull('arrival_date')){
													} //if(isNull('fax')){
												} //if(isNull('phone')){
											} //if(checkDropdown('country','countryseloption')){
										} // if(isNull('city_state')){
									} // if(isNull('address')){
								} // if(verifyEmail('email')){
							} // if(isNull('email')){
						} else{
							alert("You must select a Position Type");
							document.getElementById('org_type_radios').style.border = '1px solid #990000';
							return false;
						} // org_type1, org_type2
					} // if(isNull('organization')){
				} else{
					alert("You must select a Position Type");
					document.getElementById('pos_type_radios').style.border = '1px solid #990000';
					return false;
				} // pos_type1, pos_type2
			} //if(isNull('position')){
		} //if(isNull('lastname')){
	} //if(isNull('firstname')){
	return false;
}

function validAdminLoginForm(){
	//validate if the user name field is empty or not
	if(isNull('adminUserName')){

		//validate if the user name field is empty or not
		if(isNull('adminUserPassword')){
			return true;
		}
	}
	return false;
}

function validAdminChangePasswordForm(){
	//validate if the user name field is empty or not
	if(isNull('currentPassword')){

		//validate if the user name field is empty or not
		if(isNull('newPassword')){

			//validate if the user name field is empty or not
			if(isNull('confirmPassword')){

				//validate if the user name field is empty or not
				if(isEqual('newPassword','confirmPassword',"Password and Confirm Password Doesn't match, Please try again.")){
					return true;
				}
			}
		}
	}
	return false;
}