///////////////////////////////////////////////////////////////////////////////////////////////
//
//	global_legacy.js - contains utility javascript functions and global variables
//
//	included functions:
//		
//		- popUp(name,url,w,h)
//		- isEmailAddr(email)
//		- isInteger(s) - used in phone number validation
//		- stripCharsInBag(s, bag) - used in phone number validation
//		- checkInternationalPhone(strPhone) - used in phone number validation
//		- trim(inputString) - trims whitespace from the beginning and end of a string
//		- validatePassword()
//		- changeStyle(id,newClass) - changes classname property of an element
//		- goToUrl(url) - sends user to url
//		- resumeBuilderLogin() - alerts user that they must log-in to apply for jobs online
//
///////////////////////////////////////////////////////////////////////////////////////////////

var FORM_ERROR_MESSAGE = "There were some errors in the information you are submitting or you are missing some required info.\n\nPlease check to see that you have filled out all required fields and the all the information you enter is accurate.";

function popUp(name,url,w,h)  {
        window.open(url,name,'width='+w+',height='+h+',scrollbars=1, resizable=1, status=1, toolbar=1');
}

function isEmailAddr(email)
{
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}


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){

	var minDigitsInIPhoneNumber = 10;
	var digits = "0123456789";
	var phoneNumberDelimiters = "()- .";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string.
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}

function validatePassword(pass,confirm) {
	
	var password = trim(pass);
	var confirmPassword = trim(confirm);
	
	// check to see if password is correct length
	if(password.length < 6 || password.length > 10)
		return false;
	else if(password != confirmPassword)
		return false;
	else
		return true;

}

function changeStyle(id,newClass)
{
	var i,p,v,obj,args=changeStyle.arguments;
	for(i=0;i<args.length-1;i+=2)
	{
		var identity=document.getElementById(args[i]);
		identity.className = args[i+1];
	}
}

function goToUrl(url) {
	window.location=url;	
}

function resumeBuilderLogin() {
	alert("You must log-in before you can submit your online resume");
	window.location = '/builder/SignIn.aspx';
}