function validate_form(thisform)
{
with (thisform)
{
if (validate_required(name,"Name is required field.","")==false)
  {name.focus();return false}
if (validate_email(email,"Not a valid e-mail address","")==false)
  {email.focus();return false}
  
if (validate_required(position,"Please indicate if you are an Employer or a Candidate.","")==false)
  {position.focus();return false}

with(position){
	if(value =="Candidate"){
		
  
	var filepath = uploadedFile;
	var str = filepath.value;
	var fileType = str.slice(-4);
	
	if ((fileType.toLowerCase() == ".txt") || 
		(fileType.toLowerCase() == ".pdf") ||
		(fileType.toLowerCase() == ".doc") ||
		(fileType.toLowerCase() == ".jpg") || 
		(fileType.toLowerCase() == ".odt") ||
		(fileType.toLowerCase() == ".ods") || 		
		(fileType.toLowerCase() == ".xls") || 
		(fileType.toLowerCase() == ".zip") || 
		(fileType.toLowerCase() == ".png"))
	 { return true}
	else { alert("Invalid File Format! Make sure your resume is in .doc, .odt, .pdf, .txt, .xls or .zip format"); return false}
	
		if (validate_required(title_position,"Please indicate your job title/position.","")==false)
		  {title_position.focus();return false}
		
		if (validate_required(location,"Please indicate your location.","")==false)
		  {location.focus();return false}
	} //end if candidate
	
}// end with position

} //END WITH



} //end function validate




function showDiv(theVal,div1, div2) {
	var ele = document.getElementById(div1);
	var ele2 = document.getElementById(div2);
	var e = document.getElementById(theVal);
	var elem = e.options[e.selectedIndex].value;
	
	switch(elem){
		case "Employer": {ele.style.display = "block";	ele2.style.display = "none"; break;}
		case "Candidate": {ele.style.display = "none";	ele2.style.display = "block"; break;}
		default:{ ele.style.display = "none"; ele2.style.display = "none";}
		}
}

function hideDiv(hideDiv1, hideDiv2) {
	var ele = document.getElementById(hideDiv1);
	var ele2 = document.getElementById(hideDiv2);
	ele.style.display = "none";
	ele2.style.display = "none";
	
}


function validate_required(field,alerttxt,initialVal)
{
with (field)
{

if(value==null||value==""||value==initialVal)
  {alert(alerttxt);return false}

else {return true}
}
}


function validate_radio(field,alerttxt)
{


if ((field[0].checked) || (field[1].checked))
  {return true; }

else {alert(alerttxt); return false;}
return false;

}




function validate_email(field,alerttxt,initialVal)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else if (value==initialVal) 
  {alert(alerttxt);return false}
else {return true}
}
}


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function validate_phone(field, alerttxt) 
{
with (field)
{
	if ((value==null)||(value=="")){
		alert("Please Enter your Phone Number")
		focus()
		return false
	}
	if (checkInternationalPhone(value)==false){
		alert("Please Enter a Valid Phone Number")
		value=""
		focus()
		return false
	}
	return true
}
}


/****************************************/




