//to validate a text area
function taValidation(strString)
{
   arr = strString.split("\r\n")
   var strtemp = "";
   for (var i=0; i<arr.length; i++)
   {
    strtemp = strtemp + trim(arr[i])
   }

   if (trim(strtemp) == "")
       return false;
   else
       return true;
}

//to return a trimmed string
function trim(strStr) 
{
	var intLen = strStr.length;
	var intBegin = 0, intEnd = intLen-1;
	while (strStr.charAt(intBegin) == " " && intBegin < intLen) 
	{
		intBegin++;
	}
	while (strStr.charAt(intEnd) == " " && intBegin < intEnd) 
	{
		intEnd--;
	}
	return strStr.substring(intBegin, intEnd+1);
}

//to check on keypress if entered value is numeric or not
function fnIsNumber(eventObj, obj)
{
	 var keyCode
	
	 //check for Browser Type
	 if (document.all)
	 {
	  	keyCode = eventObj.keyCode
	 }
	 else
	 {
	  	keyCode = eventObj.which
	 }
	
	 if ((keyCode > 47 && keyCode < 58) || (keyCode == 46) || (keyCode == 8) || (keyCode == 0))
	   return true;
	 else
	   return false;
}

//to check on keypress if entered value is integer or not
function fnIsIntNumber(eventObj, obj)
{
     var keyCode

     //check for Browser Type
     if (document.all)
     {
      	keyCode = eventObj.keyCode
     }
     else
     {
      	keyCode = eventObj.which
     }

     if ((keyCode > 47 && keyCode < 58) || (keyCode == 8) || (keyCode == 0))
       return true;
     else
       return false;
}

function fnIsContactNumber(eventObj, obj)
{
	 var keyCode

     //check for Browser Type
     if (document.all)
     {
      	keyCode = eventObj.keyCode
     }
     else
     {
      	keyCode = eventObj.which
     }
 
     if ((keyCode > 47 && keyCode < 58) || (keyCode == 8) || (keyCode == 0) || (keyCode == 40) || (keyCode == 41) || (keyCode == 32) || (keyCode == 45) )
       return true;
     else
       return false;
}

//to check on keypress if entered value is alphabet or not
function fnIsAlphabet(eventObj, obj)
{
     var keyCode

     //check for Browser Type
     if (document.all)
     {
      	keyCode = eventObj.keyCode
     }
     else
     {
      	keyCode = eventObj.which
     }

     if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (keyCode == 32)|| (keyCode == 8) || (keyCode == 0))
      return true;
     else
      return false;
}

//to check on keypress if entered value is alphanumeric or not
function fnIsAlphaNumeric(eventObj, obj)
{
     var keyCode

     //check for Browser Type
     if (document.all)
     {
      	keyCode = eventObj.keyCode
     }
     else
     {
      	keyCode = eventObj.which
     }

     if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (keyCode > 47 && keyCode < 58) || (keyCode == 32) || (keyCode == 8) || (keyCode == 0))
      return true;
     else
      return false;
}

//to open a new file
function openNew1(file,imgHeight,imgWidth,scrolling)
{
  ypos = (screen.height / 2) - imgHeight/2;
  xpos = (screen.width / 2) - imgWidth/2;
  NewWindow1=window.open(file, "Win1", "height="+imgHeight+",width="+imgWidth+",toolbar=0,menubar=0,scrollbars="+scrolling+",status=0,location=0,left="+xpos+",top="+ypos+"screenx="+xpos+",screeny="+ypos);
  NewWindow1.focus();
}

//same as above
function openNew2(file,imgHeight,imgWidth,scrolling)
{
  ypos = (screen.height / 2) - imgHeight/2;
  xpos = (screen.width / 2) - imgWidth/2;
  NewWindow2=window.open(file, "Win2", "height="+imgHeight+",width="+imgWidth+",toolbar=0,menubar=0,scrollbars="+scrolling+",status=0,location=0,left="+xpos+",top="+ypos+"screenx="+xpos+",screeny="+ypos);
  NewWindow2.focus();
}

//function to check if valid date or not
var strDtChar= "-";
var minYear = 1900;
var maxYear = 2100;
function IsInteger(s)
{
	var i;
    if (s.length == 0) 
    {
    	return false;
    }
	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 fnStripCharsInBag(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++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function fnDaysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function fnDaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
    } 
   return this
}

function IsDate(dtStr)
{
	var daysInMonth = fnDaysArray(12)
	var pos1 = dtStr.indexOf(strDtChar)
	var pos2 = dtStr.indexOf(strDtChar,pos1+1)
	var strMonth = dtStr.substring(0,pos1)
	var strDay = dtStr.substring(pos1+1,pos2)
	var strYear = dtStr.substring(pos2+1)
	strYr = strYear
	if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
	}
	month = parseInt(strMonth)
	day = parseInt(strDay)
	year = parseInt(strYr)
	
	if (pos1 == -1 || pos2 == -1)
	{
		alert("The date format should be: mm-dd-yyyy");
		return false;
	}
	if (strMonth.length < 1 || month < 1 || month > 12)
	{
		alert("Please enter a valid month");
		return false;
	}
	
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > fnDaysInFebruary(year)) || day > daysInMonth[month])
	{
		alert("Please enter a valid day");
		return false;
	}
	
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
	{
		alert("Please enter a valid 4 digit year between " + minYear + " and "+maxYear);
		return false;
	}
	
	if (dtStr.indexOf(strDtChar,pos2+1) != -1 || IsInteger(fnStripCharsInBag(dtStr, strDtChar)) == false)
	{
		alert("Please enter a valid date");
		return false;
	}
    
	return true;
}
//end date

//better version of trim and taValidation
function fnIsBlank(strInput)  
{
	if ((strInput == null) || (strInput == "")) 
		return false; //original true
	
	for(var i=0; i<strInput.length; i++)  
	{
	   var chrChar = strInput.charAt(i);		
	   if((chrChar != ' ') && (chrChar != '\\n') && (chrChar != '\\t') && (chrChar != '\\r\\n')) 
	   	   return true;//original false
    }
	return false;//original true
}

//if an option button has been checked or not
function fnIsChecked(objInput)
{
	intOK = 0;
	if (objInput.length)
	{
		for (var i=0; i<objInput.length; i++)
		{
			if (objInput[i].checked) 
			{
			  intOK=1;
			}
		}
	}
	else
	{
		if (objInput.checked) 
		{
		  intOK=1;
		}
	}
	if (intOK == 1) 
	{ 
	  return true; 
	}
	else 
	{ 
	  return false; 
	}
}

//If a multiselect list box
function fnMultibox(objInput)
{
	intOK = 0;
	for (var i=0; i<objInput.length; i++)
	{	
		if (objInput[i].selected) 
		{ 
		  intOK = 1 
		}
	}
	if (intOK == 1) 
	{ 
	  return true; 
	}
	else 
	{ 
	  return false;
	}
}

//to check if valid email or not
function IsEmail(strEmail) 
{
	var y = strEmail.indexOf("\@");
  	var x = strEmail.indexOf(".");
  	var z = y + 1;
  	if(y < 0 || x < 0 || x == z)  
  	{ 
  	  return false; //original true
  	}
	return true;//original false
}

function IsWebsite(strWebsite)
{
	 var theurl=strWebsite;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
         return true;
     }
     else
     {
         return false; 
     }
}
//to validate forms
function fnCheckForm(frmInput, arrList, arrCustomFunction, arrCompareField, arrCompareFieldAlert, strChangeColor) 
{
		//initialization of variables
		var strMsg = "";    
		var strErr = "";
		var intFlag = 0;
		
		// running through the message loop
		for (strKey in arrList)
		{
			var strType = ""; // setting string variable to null
			var intFoundError = 0;
			var intChangeStyle = 0;
		
			objField = eval("frmInput."+strKey); // making a object for input field
            
			if (objField.length > 0) 
			{ 
			  strType = objField[0].type; 
			}  // setting the type to strType variable 
			if (!strType) 
			{ 
			  strType = objField.type;
			}// again checking and setting the type to strType variable 

			// condition for strType variable
			if (arrCustomFunction[strKey])
			{
				    intChangeStyle=1;
					if (!eval(arrCustomFunction[strKey]+"('"+objField.value+"')"))
					{
						intFoundError=1;
					}
			}
			else 
			{	
				switch (strType) 
				{
					case "text": 
					case "password":
									intChangeStyle = 1;
									if (trim(objField.value) == false) 
									{
									  intFoundError = 1;
									}
								 	break;
					case "textarea":
									intChangeStyle = 1;
									if (taValidation(objField.value) == false) 
									{
									  intFoundError = 1;
									}
									break;
					case "radio":
					case "checkbox":
								    if (fnIsChecked(objField) == false) 
								    {
								      intFoundError = 1;
								    }
									break;
					case "select-one":
									  intChangeStyle=1;
									  if (objField.selectedIndex==0) 
									  {
									    intFoundError = 1;
									  }
									  break;
					case "select-multiple":
										   intChangeStyle=1;
										   if (fnMultibox(objField) == false) 
										   { 
										     intFoundError = 1
										   }
										   break;
				}
			}

			if (intFoundError == 1) 
			{
				strErr = strErr + arrList[strKey] + "\n";
				if (strChangeColor!="" && intChangeStyle==1)	
				{
				  objField.style.backgroundColor = strChangeColor;
				  if (intFlag == 0)
				  {
				  	intFlag = 1;
				  	if (strType != "hidden")
				  	{
				  		objField.focus();
				  	}
				  }
				}
			}
			else 
			{
				if (strChangeColor!="" && intChangeStyle==1)	
				{
				  objField.style.backgroundColor='#FFFFFF';
				}
			}
    	}
        
		//running through the compare fields
		for (strKey in arrCompareField)
		{
			var strType = ""; // setting string variable to null
			var intFoundError = 0;
			var intChangeStyle = 0;
			objField = eval("frmInput."+strKey); // making a parent compare object for input field
			objFieldCompare = eval("frmInput."+arrCompareField[strKey]); // making a child compare object for input field
			if(objField.value.length < 6)
			{
				intChangeStyle=1;
			  	intFoundError=1;
			}
			if (objField.value != objFieldCompare.value)
			{		
			  intChangeStyle=1;
			  intFoundError=1;
			}	
            
			if (intFoundError==1) 
			{
				strErr = strErr + arrCompareFieldAlert[strKey] + "\n";
				if (strChangeColor!="" && intChangeStyle==1)	
				{
				  objField.style.backgroundColor=strChangeColor;
				}
			}
			else 
			{
				if (strChangeColor!="" && intChangeStyle==1)	
				{
					objField.style.backgroundColor='#FFFFFF';
				}
			}

		}

		// if no error then initialize the error
		if(strErr != "")
		{ 
			// adding to the error message
			strMsg += "Please correct/check the following:\n";
			strMsg += "-------------------------------------------------------------------------\n\n";	           
			strMsg += strErr;
			alert(strMsg);
			return(false);	
		}
		else 
		{ 
			return (true); 
		}
}

/*function fnCheckAll(frmInput,chkCheckAllBox,chkBoxToBeChecked)
{
  //convert to actual objects
  objCheckAllBox = eval("frmInput."+chkCheckAllBox);
  objBoxToBeChecked = eval("frmInput."+chkBoxToBeChecked);
  alert(frmInput+"  " +objCheckAllBox+"  " +"");
  if (objCheckAllBox.checked == true)
  {
    for (var i=0; i<objBoxToBeChecked.length; i++)
         objBoxToBeChecked[i].checked = true;   
  }
  else
  {
  	for (var i=0; i<objBoxToBeChecked.length; i++)
         objBoxToBeChecked[i].checked = false;
  } 
}*/

//Function to check or uncheck list of checkboxes checkboxes
//Parameters: Takes 2 Parameters
//		1 - The checkbox on click of which the fuction is called
//		2 - The list of checkboxes which will be checked or unchecked depending on value of first parameter
function fnCheckUnCheckAll(chkCheckAllBox,chkBoxToBeChecked)
{
	if (!chkBoxToBeChecked.length)
	{
		chkBoxToBeChecked.checked = chkCheckAllBox.checked;
	}
	else
	{
		for (i = 0; i < chkBoxToBeChecked.length; i++)
			chkBoxToBeChecked[i].checked = chkCheckAllBox.checked;
	}
}

//Function to Validate Number
//Parameters: Takes 3 Parameters
//		1 - The number to check
//		2 - Maximum number of digits allowed before decimal
//		3 - Maximum number of digits allowed after decimal
function IsValidNumber(intNum,intPrecision,intScale)
{
    var intNumber
    intNumber = trim(intNum)
	if(trim(intNumber)=="")
		return false;
	
	//Check For Valid intNumber
	if (isNaN(intNumber)==true)    
		return false;
	
	//Check if More Than One Decimal 
	if(intNumber.split(".").length > 2) 
		return false;
		
	if(intNumber.indexOf(".") > 0)
	{
		//If the number contains decimal point
		if((intNumber.split(".")[0]).length > intPrecision)
			return false;
		
		if((intNumber.split(".")[1]).length > intScale)
			return false;	
		return true;
	}
	else
	{
		//If the number doesn't contain decimal point
		if(intNumber.length > intPrecision)
			return false;
		else
			return true;
	}
}

//This function checks if the entered value is a string
function fnIsString(strStr)
{
	var strStr1 = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var strStr2 = strStr.length;
	if (strStr == '') return false;
	for(var i=0; i<=strStr2; i++)
	{
		var strChar = strStr.substr(i,1);
		if (strStr1.indexOf(strChar) == -1)
		{
			return false;
		}
	}
	return true;
}

//This function checks if the entered value is a pure numeric value
function fnIsDigit(strStr)
{
    var strNum = "1234567890";
    var intCtr,intLen;
    intLen=strStr.length;
    for(intCtr=0; intCtr <= intLen && strNum.indexOf(strStr.charAt(intCtr))>=0; intCtr++);
    if(intCtr > intLen)
    {
        return true;
    }
    else
    {
    	return false;
    }
}

//This function checks if the entered value is a mixture of digits and strings
function fnIsStringDigit(strStr)
{
	var strStr1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
	var strStr2 = strStr.length;
	for(var i=0; i<=strStr2; i++)
	{
		var strChar = strStr.substr(i,1);
		if (strStr1.indexOf(strChar)==-1)
		{
			return false;
		}
	}
	return true;
}

//This function checks that the string should contain both alphabets and digits
function fnIsAlphaDigit(strStr)
{
	var strAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var strDigits = "1234567890";
	var intLength = strStr.length;
	
	intAlphaFound = 0;
	for(var i = 0; i < intLength; i++)
	{
		var strChar = strStr.substr(i,1);
		if (strAlpha.indexOf(strChar) != -1)
		{
			intAlphaFound = 1;
			break;
		}
	}
	
	intDigitFound = 0;
	for(var i=0; i < intLength; i++)
	{
		var strChar = strStr.substr(i,1);
		if (strDigits.indexOf(strChar) != -1)
		{
			intDigitFound = 1;
			break;
		}
	}
	
	if ((intAlphaFound) && (intDigitFound))
	{
		return true;
	}
	return false;
}

//Checks if a value is selected or not
function fnIsSelected(objInput,strMsg)
{
	if (objInput.value == "" || objInput.value == "0" || objInput.value == 0)
	{
		alert(strMsg);
		objInput.focus();
		return false;
	}
	return true;
}

//Checks if field value has number of characters between two specified limits
function fnIsMinMax(objInput,intMinLen,intMaxLen,strMsg,strBgColor)
{
	if(objInput.value.length < intMinLen || objInput.value.length > intMaxLen) 
	{ 
		objInput.style.backgroundColor=strBgColor;
		alert(strMsg);	
		objInput.focus(); 
		return false; 
	} 
	objInput.style.backgroundColor='white';
	return true; 
}

//check for file type
function fnCheckFileType(strField,strMsg)
{
  var objRegEx = new RegExp("(.doc|.pdf)$");	
  if (!objRegEx.test(strField))
  {
  	alert(strMsg);
  	strField.focus();
  	return false;
  }
  return true;	
}

//check for image type
function fnCheckImageType(strField,strMsg)
{
  var objRegEx = new RegExp("(.jpg|.jpeg|.gif|.JPG|.JPEG|.GIF)$");	
  if (!objRegEx.test(strField))
  {
  	alert(strMsg);
  	strField.focus();
  	return false;
  }
  return true;	
}

//check for size of image file. 
//YOU CAN CHECK either in terms of width and height of image or size of image in bytes
function fnCheckImageSize(strField,strMsg)
{
  var objImg = new Image(); 
  objImg.src = strField.value; 
  
  /*var Dimensions = objImg.width + 'x' + objImg.height;*/
  
  if(objImg.fileSize > 102400) 
  { 
	alert(strMsg); 
	strField.focus(); 
	return false; 
  } 
  return true;
}

//check for phone
function fnIsPhone(strField1,strField2,strField3,strMsg)
{
  var objRegEx = new RegExp("^[\d-+()]+$");
  var strPhone = "(" + strField1.value + ")" + strField2.value + "-" + strField3.value;
  if (!objRegEx.test(strPhone))
  {
  	alert(strMsg);
  	strField1.focus();
  	return false;
  }
  return true;
}

function fnSearchChk()
{
	strTxtSearch = document.getElementById('txtSearchFor').value;
	strSelSearch = document.getElementById('lstSearchFor').value;
	// enter search text
	if (strSelSearch == '' && trim(strTxtSearch) == '')
	{
		alert("Enter some search text in text box \n OR \nselect an alphabet from the list");
		document.getElementById('txtSearchFor').focus();
		return false;
	}
	if (strSelSearch != '' && strTxtSearch != '')
	{
		alert('You can specifically choose to search a particular string \n OR \n choose an alphabet from the list \n BUT NOT BOTH');
		return false;
	}
	if (trim(strTxtSearch) != '')
	{
		document.getElementById('hidText').value = '1';
	}
	return true;
}

//Function for valid IP Address
function fnIsValidIP(strIP)
{
	if ((document.getElementById(strIP).value > 255) || (document.getElementById(strIP).value < 0))
		return false;
	else
		return true;
}

strAFile = "ajax.php?";
function fnCounty(intState,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divCounty'+strDiv))
	{
	 	if (intState)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "county=y&sid="+intState+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divCounty'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(1,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(2,strDiv);
	 	}
	}
}

function fnCity(intCounty,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divCity'+strDiv))
	{
		if ((intCounty) && (document.getElementById('lstState'+strDiv).value))
		{
			intState = document.getElementById('lstState'+strDiv).value;
		 	strArgs = "city=y&sid="+intState+"&ctid="+intCounty+"&div="+strDiv;
			var xmlhttp = createXMLHttpObject();
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divCity'+strDiv).innerHTML = xmlhttp.responseText;
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
		}
		else
		{
			fnClear(1,strDiv);
		}
	}
	else
	{
		//see city_cityadd.php page for example
		if (document.getElementById('divCountySubmit'))
		{
			if (document.getElementById('lstCounty').value != "")
			{
				document.frmAdd.submit();
			}
		}
	}
}

function fnNone()
{
	//see zip.php page for example
	if (document.getElementById('divCitySubmit'))
	{
		if (document.getElementById('lstCity').value != "")
		{
			document.frmAdd.submit();
		}
	}
}

function fnZIP(strZIP,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	
	if (trim(strZIP) == "")
	{
		fnClear(3,strDiv);
	}
	else
	{
		//now pass this zip code and get the state, county and city for it
		var xmlhttp = createXMLHttpObject();
		strArgs = "zip=y&zid="+strZIP;
		xmlhttp.open("GET",strAFile+strArgs,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4)
			{
				if (xmlhttp.status == 200)
				{
					var strString = xmlhttp.responseText;
					if (strString != "0")
					{
						arrV = strString.split("<br>");
						document.getElementById('lstState'+strDiv).value = arrV[0];
						strArgs = "county=y&sid="+arrV[0]+"&sel="+arrV[1]+"&div="+strDiv;
						xmlhttp.open("GET",strAFile+strArgs,true);
						xmlhttp.onreadystatechange=function() 
						{
							if (xmlhttp.readyState==4)
							{
								if (xmlhttp.status == 200)
								{
									document.getElementById('divCounty'+strDiv).innerHTML = xmlhttp.responseText;
									strArgs = "city=y&sid="+arrV[0]+"&ctid="+arrV[1]+"&sel="+arrV[2]+"&div="+strDiv;
									xmlhttp.open("GET",strAFile+strArgs,true);
									xmlhttp.onreadystatechange=function() 
									{
										if (xmlhttp.readyState==4)
										{
											if (xmlhttp.status == 200)
											{
												document.getElementById('divCity'+strDiv).innerHTML = xmlhttp.responseText;
											}
											else
											{
												alert('Error:AJAX request status = ' + xmlhttp.status);
											}
									    }
									}
									xmlhttp.send("");
								}
								else
								{
									alert('Error:AJAX request status = ' + xmlhttp.status);
								}
						    }
						}
						xmlhttp.send("");
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlhttp.status);
				}
		    }
		}
		xmlhttp.send("");
	}
}

function fnClear(intWhat,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	strCounty = "<select name=lstCounty"+strDiv+" id=lstCounty"+strDiv+" class=input1><option value=''>--- Select County ---</option></select>";
	strState = "<select name=lstState"+strDiv+" id=lstState"+strDiv+" class=input1><option value=''>--- Select State ---</option></select>";
	strCity = "<select name=lstCity"+strDiv+" id=lstCity"+strDiv+" class=input1><option value=''>--- Select City ---</option></select>";
	
	strCourseSubLevel = "<select name=lstCourseSubLevel"+strDiv+" id=lstCourseSubLevel"+strDiv+" class=input1><option value=''>--- Select Course Sub Level ---</option></select>";
	
	strInstCourse = "<select name=lstCourses"+strDiv+" id=lstCourses"+strDiv+" class=input1><option value=''>--- Select Course ---</option></select>";
	
	strPermanentState = "<select name=lstPermanentState"+strDiv+" id=lstPermanentState"+strDiv+" class=input1><option value=''>--- Select State ---</option></select>";
	strPermanentCity = "<select name=lstPermanentCity"+strDiv+" id=lstPermanentCity"+strDiv+" class=input1><option value=''>--- Select City ---</option></select>";
	
	strOfficeState = "<select name=lstOfficeState"+strDiv+" id=lstOfficeState"+strDiv+" class=input1><option value=''>--- Select State ---</option></select>";
	strOfficeCity = "<select name=lstOfficeCity"+strDiv+" id=lstOfficeCity"+strDiv+" class=input1><option value=''>--- Select City ---</option></select>";
	
	
	//1 means clear the city Drop Down
	if (intWhat == 1)
	{
		if (document.getElementById('divCity'+strDiv))
		{
			document.getElementById('divCity'+strDiv).innerHTML = strCity;
		}
	}
	
	//2 means clear both county and city drop down
	if (intWhat == 2)
	{
		if (document.getElementById('divCounty'+strDiv))
		{
			document.getElementById('divCounty'+strDiv).innerHTML = strCounty;
		}
		if (document.getElementById('divState'+strDiv))
		{
			document.getElementById('divState'+strDiv).innerHTML = strState;
		}
		if (document.getElementById('divCity'+strDiv))
		{
			document.getElementById('divCity'+strDiv).innerHTML = strCity;
		}
	}
	
	if (intWhat == 3)
	{
		document.getElementById('lstState'+strDiv).value = "";
		if (document.getElementById('divCounty'+strDiv))
		{
			document.getElementById('divCounty'+strDiv).innerHTML = strCounty;
		}
		if (document.getElementById('divCity'+strDiv))
		{
			document.getElementById('divCity'+strDiv).innerHTML = strCity;
		}
	}
	
	if (intWhat == 11)
	{
		if (document.getElementById('divSubLevel'+strDiv))
		{
			document.getElementById('divSubLevel'+strDiv).innerHTML = strCourseSubLevel;
		}
	}
	
	if (intWhat == 12)
	{
		if (document.getElementById('divInstCourses'+strDiv))
		{
			document.getElementById('divInstCourses'+strDiv).innerHTML = strInstCourse;
		}
	}
	
	if (intWhat == 13)
	{
		if (document.getElementById('divPermanentCity'+strDiv))
		{
			document.getElementById('divPermanentCity'+strDiv).innerHTML = strPermanentCity;
		}
	}
	
	//2 means clear both county and city drop down
	if (intWhat == 14)
	{
		if (document.getElementById('divPermanentState'+strDiv))
		{
			document.getElementById('divPermanentState'+strDiv).innerHTML = strPermanentState;
		}
		if (document.getElementById('divPermanentCity'+strDiv))
		{
			document.getElementById('divPermanentCity'+strDiv).innerHTML = strPermanentCity;
		}
	}
	
	if (intWhat == 15)
	{
		if (document.getElementById('divOfficeCity'+strDiv))
		{
			document.getElementById('divOfficeCity'+strDiv).innerHTML = strOfficeCity;
		}
	}
	
	//2 means clear both county and city drop down
	if (intWhat == 16)
	{
		if (document.getElementById('divOfficeState'+strDiv))
		{
			document.getElementById('divOfficeState'+strDiv).innerHTML = strOfficeState;
		}
		if (document.getElementById('divOfficeCity'+strDiv))
		{
			document.getElementById('divOfficeCity'+strDiv).innerHTML = strOfficeCity;
		}
	}
}

function showHide(id,bool)
{
    var strId = new String();
    strId = id;
    var temp = new Array();
    var temp = strId.split('_'); 
    /*alert(temp[1]);*/
    var trid = 'Div'+ temp[1];

    if(document.getElementById(trid).style.display == 'block')
        { document.getElementById(trid).style.display='none';}
    else    
        { document.getElementById(trid).style.display=(bool)?'block':'none';}               
}

function fnChkValidURL()
{
  //return /^(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(fnChkValidURL.arguments[0]);
  return /^(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(fnChkValidURL.arguments[0]);
}

function fnCloseWindow()
{
	window.close();
}


/*
	dateString = 'mm-dd-YYYY'
	dateSeperator = '-'
*/
function fnGetDateObject(dateString,dateSeperator)
{
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cMonth=dateString.substring(0,curPos);
	
	//extract month portion				
	endPos=dateString.indexOf(sepChar,curPos+1);
	cDate=dateString.substring(curPos+1,endPos);

	//extract year portion				
	curPos=endPos;
	endPos=curPos+5;
	cYear=curValue.substring(curPos+1,endPos);
	
	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate);	
	return dtObject;
}

function fbs_click(strPageURL, strPageTitle)
{
	u=strPageURL;
	if (strPageURL == '')
	{
		u=location.href;
	}
	
	t=strPageTitle;
	if (strPageTitle == '')
	{	
		t=document.getElementsByTagName('meta')['title'];
		t=encodeURIComponent(t);
	}
	
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+t,'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

// Mohtashim
function fnStateNew(intCountry,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divState'+strDiv))
	{
	 	if (intCountry)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "state=y&countryid="+intCountry+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divState'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(1,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(2,strDiv);
	 	}
	}
	
	if (intCountry != "99") {
		document.getElementById("txtCPrefix1").value = "";
		document.getElementById("txtCPrefix2").value = "";
		document.getElementById("txtCPrefix3").value = "";
	} else {
		document.getElementById("txtCPrefix1").value = "91";
		document.getElementById("txtCPrefix2").value = "91";
		document.getElementById("txtCPrefix3").value = "91";
	}	
}

function fnCityNew(intState,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divCity'+strDiv))
	{
		if ((intState) && (document.getElementById('lstCountry'+strDiv).value))
		{
			intCoutry = document.getElementById('lstCountry'+strDiv).value;
		 	strArgs = "citynew=y&coutryid="+intCoutry+"&stateid="+intState+"&div="+strDiv;
			var xmlhttp = createXMLHttpObject();
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divCity'+strDiv).innerHTML = xmlhttp.responseText;
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
		}
		else
		{
			fnClear(1,strDiv);
		}
	}
	else
	{
		//see city_cityadd.php page for example
		if (document.getElementById('divCountySubmit'))
		{
			if (document.getElementById('lstState').value != "")
			{
				document.frmAdd.submit();
			}
		}
	}
}

function fnCourseSubLevel(intCountry,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divSubLevel'+strDiv))
	{
	 	if (intCountry)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "course=y&levelid="+intCountry+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divSubLevel'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(1,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(11,strDiv);
	 	}
	}
}

function fnCourseValueDD(intLevel,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divCourseLevelValue'+strDiv))
	{
	 	if (intLevel)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "level=y&lid="+intLevel+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{ 
						if(xmlhttp.responseText.charAt(1) )
						{
							document.getElementById("TRLEVEL_VALUE").style.display = "";
							document.getElementById('divCourseLevelValue'+strDiv).innerHTML = xmlhttp.responseText;
						}
						else
						{
							document.getElementById("TRLEVEL_VALUE").style.display = "none";
						}
						fnClear(1,strDiv);
					}
					else
					{
						document.getElementById("TRLEVEL_VALUE").style.display = "none";
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	}
}

function fnfnInstCourses(intInstitute,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divInstCourses'+strDiv))
	{
	 	if (intInstitute)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "institute=y&instid="+intInstitute+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divInstCourses'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(1,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(12,strDiv);
	 	}
	}
}


function fnPermanentStateNew(intCountry,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divPermanentState'+strDiv))
	{
	 	if (intCountry)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "Permanentstate=y&countryid="+intCountry+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divPermanentState'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(13,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(14,strDiv);
	 	}
	}
	
	if (intCountry != "99") {
		document.getElementById("txtCPrefixPermanent").value = "";
	} else {
		document.getElementById("txtCPrefixPermanent").value = "91";
	}
}

function fnPermanentCityNew(intState,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divPermanentCity'+strDiv))
	{
		if ((intState) && (document.getElementById('lstPermanentCountry'+strDiv).value))
		{
			intCoutry = document.getElementById('lstPermanentCountry'+strDiv).value;
		 	strArgs = "Permanentcitynew=y&coutryid="+intCoutry+"&stateid="+intState+"&div="+strDiv;
			var xmlhttp = createXMLHttpObject();
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divPermanentCity'+strDiv).innerHTML = xmlhttp.responseText;
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
		}
		else
		{
			fnClear(13,strDiv);
		}
	}
}

function fnOfficeStateNew(intCountry,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divOfficeState'+strDiv))
	{
	 	if (intCountry)
	 	{
			var xmlhttp = createXMLHttpObject();
			strArgs = "Officestate=y&countryid="+intCountry+"&div="+strDiv;
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divOfficeState'+strDiv).innerHTML = xmlhttp.responseText;
						fnClear(15,strDiv);
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
	 	}
	 	else
	 	{
	 		fnClear(16,strDiv);
	 	}
	}
	
	if (intCountry != "99") {
		document.getElementById("txtCPrefixOffice").value = "";
	} else {
		document.getElementById("txtCPrefixOffice").value = "91";
	}
}

function fnOfficeCityNew(intState,strDiv)
{
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divOfficeCity'+strDiv))
	{
		if ((intState) && (document.getElementById('lstOfficeCountry'+strDiv).value))
		{
			intCoutry = document.getElementById('lstOfficeCountry'+strDiv).value;
		 	strArgs = "Officecitynew=y&coutryid="+intCoutry+"&stateid="+intState+"&div="+strDiv;
			var xmlhttp = createXMLHttpObject();
			xmlhttp.open("GET",strAFile+strArgs,true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4)
				{
					if (xmlhttp.status == 200)
					{
						document.getElementById('divOfficeCity'+strDiv).innerHTML = xmlhttp.responseText;
					}
					else
					{
						alert('Error:AJAX request status = ' + xmlhttp.status);
					}
			    }
			}
			xmlhttp.send("");
		}
		else
		{
			fnClear(15,strDiv);
		}
	}
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else
		cntfield.value = maxlimit - field.value.length;
}

function fnAJXAskQuestion(resDivId,throbberDivId,EmptyEmail)
{
	strNLEmailAddress = document.getElementById('taAskQuestion').value;
	if ((strNLEmailAddress != '' && strNLEmailAddress != 'Type your education related question in the box.'))
	{
		strArgs = "em="+strNLEmailAddress+"&act=setNLSubscriber&sesid="+Math.random();
		xmlHTTP = createXMLHttpObject();
		
		xmlHTTP.open("POST",strAFile+strArgs,true);
		xmlHTTP.onreadystatechange=function() 
		{
			if (xmlHTTP.readyState==4)
			{
				if (xmlHTTP.status == 200)
				{
					var strString = xmlHTTP.responseText;
					if (strString != "0")
					{
						document.getElementById(resDivId).innerHTML = xmlHTTP.responseText;
						document.getElementById('taAskQuestion').value = '';
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlHTTP.status);
				}
		    }
		    else
		    {
		    	document.getElementById(throbberDivId).innerHTML = "";
		    }
		}
		xmlHTTP.send("");
	}
	else
	{
		document.getElementById('idDivNewsSuccess').innerHTML = '<p><span class="txtErrorMsg">'+EmptyEmail+'</span></p>';
		return false;
	}	
}

function fnAJXApplyScholarship(resDivId,throbberDivId,EmptyEmail)
{
	strArgs = "act=scholarship&sesid="+Math.random();
	xmlHTTP = createXMLHttpObject();
		
	xmlHTTP.open("POST",strAFile+strArgs,true);
	xmlHTTP.onreadystatechange=function() 
	{
		if (xmlHTTP.readyState==4)
		{
			if (xmlHTTP.status == 200)
			{
				var strString = xmlHTTP.responseText;
				if (strString != "0")
				{
					document.getElementById(resDivId).innerHTML = xmlHTTP.responseText;
				}
			}
			else
			{
				alert('Error:AJAX request status = ' + xmlHTTP.status);
			}
	    }
	    else
	    {
	    	document.getElementById(throbberDivId).innerHTML = "";
	    }
	}
	xmlHTTP.send("");	
}

function fnAJXSubscribe(resDivId,throbberDivId,EmptyEmail)
{
	strNLEmailAddress = document.getElementById('txtEmail').value;
	if ((strNLEmailAddress != '' && strNLEmailAddress != 'Enter your email'))
	{
		strArgs = "emailaddress="+strNLEmailAddress+"&act=setSubscriber&sesid="+Math.random();
		xmlHTTP = createXMLHttpObject();
		
		xmlHTTP.open("GET",strAFile+strArgs,true);
		xmlHTTP.onreadystatechange=function() 
		{
			if (xmlHTTP.readyState==4)
			{
				if (xmlHTTP.status == 200)
				{
					var strString = xmlHTTP.responseText;
					if (strString != "0")
					{
						document.getElementById(resDivId).innerHTML = xmlHTTP.responseText;
						document.getElementById('txtEmail').value = '';
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlHTTP.status);
				}
		    }
		    else
		    {
		    	document.getElementById(throbberDivId).innerHTML = "";
		    }
		}
		xmlHTTP.send("");
	}
	else
	{
		document.getElementById('idDivSubscriptionSuccess').innerHTML = '<p><span class="txtErrorMsg">'+EmptyEmail+'</span></p>';
		return false;
	}	
}

function fnAJXEmailVerify(resDivId,throbberDivId,orgDivId)
{
	strArgs = "act=emailverify&sesid="+Math.random();
	xmlHTTP = createXMLHttpObject();
		
	xmlHTTP.open("POST",strAFile+strArgs,true);
	xmlHTTP.onreadystatechange=function() 
	{
		if (xmlHTTP.readyState==4)
		{
			if (xmlHTTP.status == 200)
			{
				var strString = xmlHTTP.responseText;
				if (strString != "0")
				{
					document.getElementById(orgDivId).style.display = "none";
					document.getElementById(resDivId).innerHTML = xmlHTTP.responseText;
				}
			}
			else
			{
				alert('Error:AJAX request status = ' + xmlHTTP.status);
			}
	    }
	    else
	    {
	    	document.getElementById(throbberDivId).innerHTML = "";
	    }
	}
	xmlHTTP.send("");	
}

function fnAJXCounselMe(resDivId,throbberDivId,cid)
{
	strArgs = "act=CounselMe&cid="+cid+"sesid="+Math.random();
	xmlHTTP = createXMLHttpObject();
	
	xmlHTTP.open("GET",strAFile+strArgs,true);
	xmlHTTP.onreadystatechange=function() 
	{
		if (xmlHTTP.readyState==4)
		{
			if (xmlHTTP.status == 200)
			{
				var strString = xmlHTTP.responseText;
				if (strString != "0")
				{
					document.getElementById(resDivId).innerHTML = xmlHTTP.responseText;
				}
			}
			else
			{
				alert('Error:AJAX request status = ' + xmlHTTP.status);
			}
	    }
	    else
	    {
	    	document.getElementById(throbberDivId).innerHTML = "";
	    }
	}
	xmlHTTP.send("");	
}

//For Pagination
function pagination(page, pageName)
{
	xmlHttp=createXMLHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	

	strSiteVirtualPath=strSiteVirtualPath+"ajax.php";
	strSiteVirtualPath = strSiteVirtualPath+"?act="+pageName+"&starting="+page;
	strSiteVirtualPath=strSiteVirtualPath+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",strSiteVirtualPath,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("page_contents").innerHTML = xmlHttp.responseText;
	}
	else
	{
		document.getElementById("page_contents").innerHTML = '<div align="center" style="padding-top: 100px;"><img src="../images/loading.gif" /></div>';
	}
}
//END
