// JavaScript Document
var ulogged = "false";

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function findWidth(obj){
	xPos = obj.offsetWidth;
	return xPos;
}

//Start of drop down script
var subMnus="";
function showMenu(idx,img){
	try{
		hideAllMenu();
		var dv=document.getElementById("sub"+idx);
		if(idx==5)
			dv.style.left=(findPosX(document.getElementById(img))+findWidth(document.getElementById(img)))-findWidth(dv);
		else
			dv.style.left=findPosX(document.getElementById(img));
		dv.style.top=115;
		dv.style.visibility="visible";
	}
	catch(e){}
}

//This function is to hide the dropdown menu
function hideAllMenu(){
	try{
		var ar=subMnus.split(',');
		for(i=0;i<ar.length;i++){
			var dv=document.getElementById("sub"+ar[i]);
			dv.style.visibility="hidden";
		}
	}
	catch(e){}
}

//This function is to hide the dropdown menu

//End of drop down script

// This function checks to see if a selection was made in a checkbox group
function cbxSelectionMade(cbx){
	var isGood=false;
	if(cbx.checked){
		isGood=true;
	}
	for(i=0;i<cbx.length && !isGood;i++){
		if(cbx[i].checked){
			isGood=true;
		}
	}
	return isGood;
}

// This function checks to see if a selection was made in a dropdown box
function cboSelectionMade(cbo){
	var isGood=false;
	
	if(cbo.options[cbo.selectedIndex].value!="")
		isGood=true;
		
	return isGood;
}

// This function is used to validate email entries
function isValidEmail(thisEmail){
	var emailexp = /.*\@.*\..*/;
	if(!emailexp.test(thisEmail)) {
		return false;
	} 
	return true;
}

// function checks a date value to make sure its valid
function isValidDate(aDate) {
	var dateexp = /^(\d{1,2}\/\d{1,2}\/\d{4})$/;
    if(!dateexp.test(aDate)) { return false; } 	
	var	temp = new String(aDate), m = 0, d = 0;
	
	for (i=0; i < temp.length; i++){ 
		var str = temp.charAt(i); 
		if(str == "/") { if(m == 0) { m = i; } else { d = i; break; }}			
	}
	
	var month = parseInt(temp.substring(0, m), 10);
	var day = parseInt(temp.substring(m + 1, d), 10); 
	var year = parseInt(temp.substring(d + 1, temp.length), 10);								
					
	switch (month) {
		case 1:	case 3:	case 5:	case 7:	case 8:	case 10: case 12:					
			if((day < 1) || (day > 31)) {  return false;	} break;
		case 2:		
			if((year % 400 == 0) || (year % 4 == 0)) {	if((day < 1) || (day > 29)) {  return false;	} break}
			if((day < 1) || (day > 28)) {  return false; } break;
		case 4:	case 6:	case 9: case 11:
			if((day < 1) || (day > 30)) {	 return false; } break;
		default: return false;			
	}		
	return true;		
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if(a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//This function is to validate feedback form
function validateFeedback(thisForm){
	if(!isValidEmail(thisForm.userEmailAddress.value)){
		alert("Please provide a valid email address.");	
		thisForm.userEmailAddress.focus()
		return false;
	}
	
	if(thisForm.userComments.value==""){
		alert("Please fill out your comments.");	
		thisForm.userComments.focus()
		return false;
	}
	
	return true;
}

//This function is to validate nomination form
function validateNomination(thisForm){	
	if(thisForm.position.value==""){
		alert("Please fill out the position.");	
		thisForm.position.focus()
		return false;
	}
	if(thisForm.nomName.value==""){
		alert("Please fill out the nominee's name.");	
		thisForm.nomName.focus()
		return false;
	}
	if(!isValidEmail(thisForm.nomEmail.value)){
		alert("Please provide a valid email address for the nominee.");	
		thisForm.nomEmail.focus()
		return false;
	}
	
	return true;
}

function run_profileDiv() {
	try{
	 var dv = document.getElementById("profile_div");
	 if(dv.style.display == 'inline'){
		dv.style.display = 'none'; 
	 }else{
		 var url = 'tmpprofile.cfm';
		 //var pars = 's='+escape($F('input_string'));
		 var pars = "";
		 var target = 'profile_div';
		 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars});
		 var dv2 = document.getElementById("placer");
		 dv.style.left = findPosX(dv2) -362;
		 dv.style.top = findPosY(dv2) + 10;
		 dv.style.display = 'inline';
	 }
	}catch(e){}
}

function login_profileDiv() {
	try{
	 var url = 'tmpprofile.cfm';
	 //var pars = 's='+escape($F('input_string'));
	 var uname = document.logForm.loginName.value;
	 var upass = document.logForm.loginPass.value;
	 var pars = "login=user&loginName="+uname+"&loginpass="+upass;
	 if(document.logForm.logme.checked){
		 pars+="&logme=1";
	 }
	 var dv = document.getElementById("profile_div");
	 //dv.style.display = 'none';
	 var dv2 = document.getElementById("placer");
	 dv.style.left = findPosX(dv2) -362;
	 dv.style.top = findPosY(dv2) + 10;
	 var target = 'profile_div';
	 //var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars, onComplete:function(){alert(document.getElementById("htHideTheDiv").value);}});
	 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars, onComplete:function(){if(document.getElementById("htHideTheDiv").value=='1')window.location.href='myProfile.cfm';}});
	}catch(e){}
}

//This function is to validate that the form image code has been entered
function validateNominationConfirm(thisForm){	
	if(thisForm.imageVerify.value==""){
		alert("Please enter the security image code.");	
		thisForm.imageVerify.focus()
		return false;
	}
	
	return true;
}

function validateApplication(thisForm){
	if(thisForm.firstName.value==""){
		window.alert("Please enter your first name.");
		thisForm.firstName.focus();
		return false;
	}   
	if(thisForm.lastName.value==""){
		window.alert("Please enter your last name.");
		thisForm.lastName.focus();
		return false;
	}   
	if(thisForm.address1.value == ""){
		window.alert("Please enter a valid street address.");
		thisForm.address1.focus();
		return false;
	}   
	if(thisForm.city.value == ""){
		window.alert("Please enter a valid city name.");
		thisForm.city.focus();
		return false;
	}    
	if(!cboSelectionMade(thisForm.country)){
		window.alert("Please choose a country!");
		thisForm.country.focus();
		return false;
	} 
	if(!cboSelectionMade(thisForm.prov)){
		window.alert("Please select your state/province!");
		thisForm.prov.focus();
		return false;
	}  
	if(thisForm.prov[thisForm.prov.selectedIndex].value == "__" && thisForm.oprov.value=="" ){
		window.alert("Please provide other state/province!");
		thisForm.oprov.focus();
		return false;
	}
	if(thisForm.postal.value == ""){
		window.alert("Please enter a valid zip/postal code.");
		thisForm.postal.focus();
		return false;
	} 
	if(thisForm.phone.value == ""){
		window.alert("Please enter a valid phone number.");
		thisForm.phone.focus();
		return false;
	}
	if( thisForm.email.value == ""||!isValidEmail(thisForm.email.value)){
		window.alert("Please enter a valid email address!");
		thisForm.email.focus();
		return false;
	}
	if(thisForm.password.value == ""){
		window.alert("Please enter a password!");
		thisForm.email.focus();
		return false;
	}
	if(thisForm.password.value != thisForm.password2.value){
		window.alert("Your password and confirm password do not match!");
		thisForm.password2.focus();
		return false;
	}
	
	return true;
}

//This function is to validate nomination form
function validateFriend(thisForm){	
	if(thisForm.firstName.value==""){
		alert("Please provide your friend's first name.");	
		thisForm.firstName.focus();
		return false;
	}
	/*if(thisForm.lastName.value==""){
		alert("Please provide your friend's last name.");	
		thisForm.lastName.focus();
		return false;
	}*/
	if(!isValidEmail(thisForm.email.value)){
		alert("Please provide a valid email address for your friend.");	
		thisForm.email.focus();
		return false;
	}
	
	return true;
}

function validateProfile(thisForm){
	if(thisForm.firstName.value==""){
		window.alert("Please enter your first name.");
		thisForm.firstName.focus();
		return false;
	}   
	if(thisForm.lastName.value==""){
		window.alert("Please enter your last name.");
		thisForm.lastName.focus();
		return false;
	}   
	if(thisForm.address1.value == ""){
		window.alert("Please enter a valid street address.");
		thisForm.address1.focus();
		return false;
	}   
	if(thisForm.city.value == ""){
		window.alert("Please enter a valid city name.");
		thisForm.city.focus();
		return false;
	}  
	if(!cboSelectionMade(thisForm.country)){
		window.alert("Please choose a country!");
		thisForm.country.focus();
		return false;
	}  
	if(!cboSelectionMade(thisForm.prov)){
		window.alert("Please select your state/province!");
		thisForm.prov.focus();
		return false;
	}  
	if(thisForm.prov[thisForm.prov.selectedIndex].value == "__" && thisForm.oprov.value=="" ){
		window.alert("Please provide other state/province!");
		thisForm.oprov.focus();
		return false;
	}
	if(thisForm.postal.value == ""){
		window.alert("Please enter a valid zip/postal code.");
		thisForm.postal.focus();
		return false;
	}  
	if(thisForm.phone.value == ""){
		window.alert("Please enter a valid phone number.");
		thisForm.phone.focus();
		return false;
	}
	if( thisForm.email.value == ""||!isValidEmail(thisForm.email.value)){
		window.alert("Please enter a valid email address!");
		thisForm.email.focus();
		return false;
	}
	if(thisForm.password.value != ""){
		if(thisForm.password.value != thisForm.password2.value){
			window.alert("Your password and confirm password do not match!");
			thisForm.password2.focus();
			return false;
		}
	}
	
	return true;
}

//This function is to validate nomination form
function validateInv(thisForm){	
	if(thisForm.yourName.value==""){
		alert("Please provide your name.");	
		thisForm.yourName.focus();
		return false;
	}
	if(!isValidEmail(thisForm.emailAddress.value)){
		alert("Please provide a valid email address.");	
		thisForm.emailAddress.focus();
		return false;
	}
	if(thisForm.phoneNumber.value == ""){
		window.alert("Please enter a valid phone number.");
		thisForm.phoneNumber.focus();
		return false;
	}
	
	return true;
}

//This function is to validate nomination form
function validateCorp(thisForm){
	if(thisForm.corporation.value==""){
		alert("Please provide your corporation's name.");	
		thisForm.corporation.focus();
		return false;
	}
	if(thisForm.yourName.value==""){
		alert("Please provide your name.");	
		thisForm.yourName.focus();
		return false;
	}
	if(thisForm.yourPosition.value==""){
		alert("Please provide your position.");	
		thisForm.yourPosition.focus();
		return false;
	}
	if(thisForm.address1.value == ""){
		window.alert("Please enter a valid street address.");
		thisForm.address1.focus();
		return false;
	}   
	if(thisForm.city.value == ""){
		window.alert("Please enter a valid city name.");
		thisForm.city.focus();
		return false;
	}   
	if(!cboSelectionMade(thisForm.country)){
		window.alert("Please choose a country!");
		thisForm.country.focus();
		return false;
	} 
	if(!cboSelectionMade(thisForm.prov)){
		window.alert("Please select your state/province!");
		thisForm.prov.focus();
		return false;
	}  
	if(thisForm.prov[thisForm.prov.selectedIndex].value == "__" && thisForm.oprov.value=="" ){
		window.alert("Please provide other state/province!");
		thisForm.oprov.focus();
		return false;
	}
	if(thisForm.postal.value == ""){
		window.alert("Please enter a valid zip/postal code.");
		thisForm.postal.focus();
		return false;
	}  
	if(!isValidEmail(thisForm.emailAddress.value)){
		alert("Please provide a valid email address.");	
		thisForm.emailAddress.focus();
		return false;
	}
	if(thisForm.phoneNumber.value == ""){
		window.alert("Please enter a valid phone number.");
		thisForm.phoneNumber.focus();
		return false;
	}
	
	return true;
}
		
function intuitiveBus() {
	//try{
	 var dv = document.getElementById("dvIntuit");
	 var dv2 = document.getElementById("imgIntuit");
	 dv.innerHTML="Loading...";
	 var url = 'tmpIntuitBus.cfm';
	 var pars = 'criteria='+document.fIntuit.criteria.value+'&filter='+(document.fIntuit.filter[1].checked?'symbol':'company');
	 var target = 'dvIntuit';
	 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars});
	 dv.style.left = findPosX(dv2);
	 dv.style.top = findPosY(dv2);
	 if(document.fIntuit.criteria.value != ''){
	 	dv.style.display = 'inline';
	 }else{
		dv.style.display = 'none';
	 }
	//}catch(e){}
}

function companyChosen(theid,thename){
	document.fIntuit.addid.value=theid;
	document.fIntuit.criteria.value=thename;
	document.getElementById("dvIntuit").style.display='none';
	addBusToList();
}

function addBusToList()
{
	try{
	 var dv = document.getElementById("dvPBuslisting");
	 dv.innerHTML="Adding corporation...";
	 var url = 'tmpProfBusList.cfm';
	 var pars = 'addbusid='+document.fIntuit.addid.value;
	 var target = 'dvPBuslisting';
	 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars});
  
	  document.fIntuit.addid.value="0";
	  document.fIntuit.criteria.value="";
	}catch(e){}
}

function remFromBusList(thisbus)
{
	try{
	 if(confirm("Are you sure you wish to remove this corporation")){
	 var dv = document.getElementById("dvPBuslisting");
	 dv.innerHTML="Removing corporation...";
	 var url = 'tmpProfBusList.cfm';
	 var pars = 'rembusid='+thisbus;
	 var target = 'dvPBuslisting';
	 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars});
	 }
	}catch(e){}
}

function onEnterKey(e){
	var ccode;
	if(e && e.which)
	{
		e = e;
		ccode = e.which;
	} 
	else 
	{
		e = event;
		ccode = e.keyCode;
	}
	
	if(ccode==13){
		login_profileDiv();
	}
}

//This function is to validate nomination form
function validateApplicant(thisForm){
	/*if(!cboSelectionMade(thisForm.position)){
		alert("Please provide your corporation's name.");	
		thisForm.position.focus()
		return false;
	}*/
	if(thisForm.yourName.value==""){
		alert("Please provide your name.");	
		thisForm.yourName.focus();
		return false;
	}
	if(!isValidEmail(thisForm.emailAddress.value)){
		alert("Please provide a valid email address.");	
		thisForm.emailAddress.focus();
		return false;
	} 
	/*if(thisForm.address1.value == ""){
		window.alert("Please enter a valid street address.");
		thisForm.address1.focus();
		return false;
	}   
	if(thisForm.city.value == ""){
		window.alert("Please enter a valid city name.");
		thisForm.city.focus();
		return false;
	}   
	if(!cboSelectionMade(thisForm.country)){
		window.alert("Please choose a country!");
		thisForm.country.focus();
		return false;
	} 
	if(!cboSelectionMade(thisForm.prov)){
		window.alert("Please select your state/province!");
		thisForm.prov.focus();
		return false;
	}  
	if(thisForm.prov[thisForm.prov.selectedIndex].value == "__" && thisForm.oprov.value=="" ){
		window.alert("Please provide other state/province!");
		thisForm.oprov.focus();
		return false;
	}
	if(thisForm.postal.value == ""){
		window.alert("Please enter a valid zip/postal code.");
		thisForm.postal.focus();
		return false;
	}  
	if(thisForm.phoneNumber.value == ""){
		window.alert("Please enter a valid phone number.");
		thisForm.phoneNumber.focus();
		return false;
	}*/
	if(thisForm.resume.value == ""){
		window.alert("Please provide your resume/CV to upload!");
		thisForm.resume.focus();
		return false;
	}  
	if(thisForm.resume.value.lastIndexOf(".pdf")==-1 && thisForm.resume.value.lastIndexOf(".doc")==-1){
		window.alert("Resumes are accepted in .doc or .pdf format only.");
		thisForm.resume.focus();
		return false;
	} 
	
	return true;
}
// This function is used to pop the passed calc
function popWin(c){
	window.open(c,'','width=380,height=500,scrollbars=1');
}

function countryChosen(cabbr){
	try{
	 var dv=document.getElementById("selProv");
	 dv.innerHTML="Loading...";
	 var url = 'tmpListProv.cfm';
	 var pars = 'defaultC='+cabbr;
	 var target = 'selProv';
	 var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars});
	}catch(e){}
}