/*
   Author: Tyler Laczko
   Date:   January 2007
   Purpose:provide javascript for web pages
*/

/*********************************************************************
*Function:	checkConfirm
*Purpose:	This function opens a popup box that waites for the user to confirm there actions
			using a yes or a cancel option.
*Params:	msg - The message to be displayed in the popup box
***********************************************************************/
function checkConfirm(msg)
{
  return confirm(msg);
}

function checkRegistrationForm()
{
	if (document.register.userName.value.length < 5)
	{
		window.alert("Please enter a user name");
		document.register.userName.focus();
		return false;
	}
	else if (!checkEmail(document.register.email.value))
	{
		window.alert("Please enter a valid email address");
		document.register.email.focus();
		return false;
	}
	else if (document.register.password.value != document.register.password2.value 
			 || document.register.password.value.length < 5)
	{
		document.register.password.value = '';
		document.register.password2.value = '';
		window.alert("Please re-enter your password");
		document.register.password.focus();
		return false;
	}
	else if(!document.register.terms[0].checked)
	{
		window.alert("Your must accept the Terms of Use to continue.");
		document.register.terms[0].focus();
		return false;
	}
	
	else if(!document.register.privacy[0].checked)
	{
		window.alert("Your must accept the Privacy Statement to continue.");
		document.register.privacy[0].focus();
		return false;
	}
	else if (document.register.verif_box.value < 10000 || document.register.verif_box.value > 99999)
	{
		window.alert("Please enter the verification number");
		document.register.verif_box.focus();
		return false;
	}
	return checkConfirm("Is this information correct?");
}

function checkContactForm()
{
        if (document.contactUsForm.name.value.length == 0)
        {
				window.alert("Please enter your Name");
                document.contactUsForm.name.focus();
                return false;
        }
		else if (!checkEmail(document.contactUsForm.email.value))
        {
				window.alert("Please enter a valid Email Address");
                document.contactUsForm.email.focus();
                return false;
        }
        else if (document.contactUsForm.subject.value.length == 0)
        {
				window.alert("Please enter a Subject");
                document.contactUsForm.subject.focus();
                return false;
        }
        else if (document.contactUsForm.message.value.length == 0)
        {
                window.alert("Please enter a Message");
                document.contactUsForm.message.focus();
                return false;
        }
        //All required form fields are validated
        else
        {
                return checkConfirm("Is this information correct?");
        }
}

function checkAdvertisementForm()
{
        if (document.advertisementForm.name.value.length == 0)
        {
				window.alert("Please enter your Name");
                document.advertisementForm.name.focus();
                return false;
        }
		else if (!checkEmail(document.advertisementForm.email.value))
        {
				window.alert("Please enter a valid Email Address");
                document.advertisementForm.email.focus();
                return false;
        }
        else if (document.advertisementForm.subject.value.length == 0)
        {
				window.alert("Please enter a Subject");
                document.advertisementForm.subject.focus();
                return false;
        }
		else if (!checkDate(document.advertisementForm.startDate.value))
		{
			window.alert("Please enter a valid Start Date");
			document.advertisementForm.startDate.focus();
			return false;
		}
        else if (!document.advertisementForm.term[0].checked 
			&& !document.advertisementForm.term[1].checked 
			&& !document.advertisementForm.term[2].checked 
			&& !document.advertisementForm.term[3].checked)
        {
                window.alert("Please select a Term");
                document.advertisementForm.term[0].focus();
                return false;
        }
        //All required form fields are validated
        else
        {
                return checkConfirm("Is this information correct?");
        }
}

function checkSendMSGForm()
{
    if (document.sendMSG.subject.value.length == 0)
	{
		window.alert("Please enter a subject");
		document.sendMSG.subject.focus();
		return false;
	}
	else if (document.sendMSG.msg.value.length == 0)
	{
		window.alert("Please enter a message");
		document.sendMSG.msg.focus();
		return false;
	}
	//All required form fields are validated
	else
	{
		return checkConfirm("Is this information correct?");
		
	}
}

function checkEmailFriend()
{
        if (document.emailFriendFORM.yourName.value.length == 0)
        {
				window.alert("Please enter your Name");
                document.emailFriendFORM.yourName.focus();
                return false;
        }
		else if (!checkEmail(document.emailFriendFORM.yourEmail.value))
        {
				window.alert("Please enter your Email Address");
                document.emailFriendFORM.yourEmail.focus();
                return false;
        }
		else if (!checkEmail(document.emailFriendFORM.friendEmail.value))
        {
				window.alert("Please enter your friends Email Address");
                document.emailFriendFORM.friendEmail.focus();
                return false;
        }
        //All required form fields are validated
        else
        {
                return checkConfirm("Is this information correct?");

        }
}

function checkLoginForm()
{
	if (document.login.userName.value.length < 5)
	{
		window.alert("Please enter your username");
		document.login.userName.focus();
		return false;
	}
	else if (document.login.password.value.length < 5)
	{
		window.alert("Please enter your password");
		document.login.password.focus();
		return false;
	}
	return true;
}

function checkAddJobForm()
{
	if (document.addJobForm.jobTitle.value == "")
	{
		window.alert("Please enter a Job Title");
		document.addJobForm.jobTitle.focus();
		return false;
	}	
	if(document.getElementById("richEdit0").value.length < 100)
	{
		window.alert("Please enter a Job Description");
		document.getElementById("richEdit0").focus();
		return false;
	}
	if (!checkDate(document.addJobForm.startDate.value))
	{
		window.alert("Please enter a valid Start Date");
		document.addJobForm.startDate.focus();
		return false;
	}
	
	if (document.addJobForm.position1.value == "")
	{
		window.alert("Please select a Position");
		document.addJobForm.position1.focus();
		return false;
	}	
	
	if(document.addJobForm.wage.value.length > 0)
	{
		if(!checkPrice(document.addJobForm.wage.value))
		{
			window.alert("Please enter a valid Wage Amount");
			document.addJobForm.wage.focus();
			return false;
		}
	}
	
	if (document.addJobForm.country.value == "")
	{
		window.alert("Please select a Country");
		document.addJobForm.country.focus();
		return false;
	}	
	if (document.addJobForm.prov.value == "")
	{
		window.alert("Please select a Province or State");
		document.addJobForm.prov.focus();
		return false;
	}	
	if (document.addJobForm.city.value == "")
	{
		window.alert("Please select a City");
		document.addJobForm.city.focus();
		return false;
	}	
	
	if (document.addJobForm.adTitle.value.length < 5)
	{
		window.alert("Please enter an Ad Title");
		document.addJobForm.adTitle.focus();
		return false;
	}	
	if (document.addJobForm.adDescription.value.length < 10)
	{
		window.alert("Please enter an Ad Description");
		document.addJobForm.adDescription.focus();
		return false;
	}	
	if (!checkDate(document.addJobForm.postDate.value))
	{
		window.alert("Please enter a valid Post Date");
		document.addJobForm.postDate.focus();
		return false;
	}
	if (!checkDate(document.addJobForm.closingDate.value))
	{
		window.alert("Please enter a valid Closing Date");
		document.addJobForm.closingDate.focus();
		return false;
	}
	else
	{
		return checkConfirm("Is this information correct?");
	}
}

function checkAddResumeForm()
{
	if (document.addResumeForm.resumeTitle.value == "")
	{
		window.alert("Please enter a Resume Title");
		document.addResumeForm.resumeTitle.focus();
		return false;
	}	
	if(document.getElementById("richEdit0").value.length < 100)
	{
		window.alert("Please enter details for your Resume");
		document.getElementById("richEdit0").focus();
		return false;
	}
	if (!checkDate(document.addResumeForm.startDate.value))
	{
		window.alert("Please enter a valid Start Date");
		document.addResumeForm.startDate.focus();
		return false;
	}
	
	if (document.addResumeForm.position1.value == "")
	{
		window.alert("Please select a Position");
		document.addResumeForm.position1.focus();
		return false;
	}	
	
	if(document.addResumeForm.wage.value.length > 0)
	{
		if(!checkPrice(document.addResumeForm.wage.value))
		{
			window.alert("Please enter a valid Wage Amount");
			document.addResumeForm.wage.focus();
			return false;
		}
	}
	
	if (document.addResumeForm.country.value == "")
	{
		window.alert("Please select a Country");
		document.addResumeForm.country.focus();
		return false;
	}	
	if (document.addResumeForm.prov.value == "")
	{
		window.alert("Please select a Province or State");
		document.addResumeForm.prov.focus();
		return false;
	}	
	
	if (document.addResumeForm.adTitle.value.length < 5)
	{
		window.alert("Please enter an Ad Title");
		document.addResumeForm.adTitle.focus();
		return false;
	}	
	if (document.addResumeForm.adDescription.value.length < 10)
	{
		window.alert("Please enter an Ad Description");
		document.addResumeForm.adDescription.focus();
		return false;
	}	
	if (!checkDate(document.addResumeForm.postDate.value))
	{
		window.alert("Please enter a valid Post Date");
		document.addResumeForm.postDate.focus();
		return false;
	}
	if (!checkDate(document.addResumeForm.endDate.value))
	{
		window.alert("Please enter a valid End Date");
		document.addResumeForm.endDate.focus();
		return false;
	}
	else
	{
		return checkConfirm("Is this information correct?");
	}
}

function clearTextBox(input)
{
	if (input.value == "you@address.com (email)")
	{
		input.value = "";
	}
	else if(input.value == "Quick Search")
	{
		input.value = "";
	}
} 


function fillTextBox(input)
{
	if (input.value == "")
	{
		input.value = "you@address.com (email)";
	}
} 

/*******************************************
function checkDate
purpose ensure the value entered in the input box, checkDate, is a correctly formed date
param date - value entered into the date input box
*******************************************/
function checkDate(date)
{
    var rexp = / ([1-9]|0[1-9]|1[012])\/([1-9]|0[1-9]|[12][0-9]|3[01])\/(19|20)\d\d /;
    return rexp.test(" "+date+" ");
}

/*function checkDate(date)
{
    var rexp = /([1-9]|0[1-9]|[12][0-9]|3[01])-([1-9]|0[1-9]|1[012])-(19|20)\d\d ([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-9]|0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):([0-9]|0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])/;
    return rexp.test(date);
}*/

/*******************************************
function checkPrice
purpose ensure the value entered in the input box, checkPrice, is a correctly formed price
param price - value entered into the price input box
*******************************************/
function checkPrice(price)
{
    var rexp = /^\d+(\.\d\d)?$/;
    return rexp.test(price);
}

/*******************************************
function checkPhone
purpose ensure the value entered in the input box, checkPhone, is a correctly formed phone
param phone - value entered into the phone input box
*******************************************/
function checkPhone(phone)
{
    var rexp = /^(\(?\d{3}\)?[ -]?)?\d{3}[ -]?\d{4}$/;
    return rexp.test(phone);
}

/*******************************************
function checkCC
purpose ensure the value entered in the input box, checkPhone, is a correctly formed phone
param phone - value entered into the phone input box
*******************************************/
function checkCC(cc)
{
    var rexp = /^5[1-5]\d{14}$/;
    return rexp.test(cc);
}

/*******************************************
* Function 	checkEmail
* purpose 	ensure the value entered in the input box, pcode, is a correctly formed email
* param 	email - value entered into the email input box
*******************************************/
function checkEmail(email)
{
  var rexp = /^[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}$/;
  return rexp.test(email);
}


function showhide(id) 
{
	var el = document.getElementsByTagName('p');
	var L , i=0;
	while(L = el[i++]) 
	{  		
		if(L.style.display == "block" && L.getAttribute('id')==id)
		{
				L.style.display="none";
		}
		else
		{
			L.style.display=(L.getAttribute('id')==id) ? "block" : "none";
		}
	}
}




function getMenu(x)
{
	var element=document.getElementById("mnu"+x);
	var mnuPosition = findPos(document.getElementById("nav"+x));
	element.style.display = "block";
	element.style.top =( mnuPosition[1]+20)+"px";
	element.style.left=(mnuPosition[0]+10+"px");
}

function disMenu(x)
{
	document.getElementById("mnu"+x).style.display="none";
}

function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showHideSolution(x)
{
	var element=document.getElementById("brainSolution"+x);
	if(element.style.display == "block")
	{
		element.style.display = "none"
	}
	else
	{
		element.style.display = "block"
	}
}


function bookmark(url,title)
{
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}







function hidediv(buttonID) 
{
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		document.getElementById(buttonID).style.visibility = 'hidden';
	}
	else 
	{
		if (document.layers) { // Netscape 4
			document.buttonID.visibility = 'hidden';
		}
		else { // IE 4
			document.all.buttonID.style.visibility = 'hidden';
		}
	}
}

function showdiv(buttonID) 
{
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		document.getElementById(buttonID).style.visibility = 'visible';
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			document.buttonID.visibility = 'visible';
		}
		else 
		{ // IE 4
			document.all.buttonID.style.visibility = 'visible';
		}
	}
}


