var strThrobberImg = '<img src="images/working.gif" />';
var strThrobberAdminImg = '<img src="../images/working.gif" />';

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

//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;
}

function fnCity_ck(intState,strDiv)
{
	strAFile = "ajax.php?";
	if (!strDiv)
	{
		strDiv = "";
	}
	if (document.getElementById('divCity'+strDiv))
	{
		if (document.getElementById('lstState'+strDiv).value)
		{
			intState = document.getElementById('lstState'+strDiv).value;
		 	strArgs = "city=y&sid="+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('lstCounty').value != "")
			{
				document.frmAdd.submit();
			}
		}
	}
}

//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;
}

//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 dtCh= "-";
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 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++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (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 DaysArray(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 = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,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>daysInFebruary(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(dtCh,pos2+1)!=-1 || IsInteger(stripCharsInBag(dtStr, dtCh))==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
}

//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 != 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;
	// modified by mayuri 
	// if nothing entered return false
	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&act=usc&sid="+intState+"&ctid="+intCounty+"&div="+strDiv+"&sesid="+Math.random();

			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>";
	strCity = "<select name=lstCity"+strDiv+" id=lstCity"+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('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;
		}
	}
}

//to validate forms
function fnCheckUserForm(frmInput, arrList, arrCustomFunction, arrCompareField, arrCompareFieldAlert, strChangeColor, arrUserLength) 
{
		//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;
					}
			}
			if(arrUserLength[strKey])
			{
				intChangeStyle=1;
				if (!eval(arrUserLength[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;
				  	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 CheckLength(strUsername)
{
	if(strUsername.length < 6)
		return false;
	else
		return true;	
}
// Code for Auto tabs
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
     function autoTab(input,len, e) {
        var keyCode = (isNN) ? e.which : e.keyCode; 
        var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
         if(input.value.length >= len && !containsElement(filter,keyCode)) {
           input.value = input.value.slice(0, len);
           input.form[(getIndex(input)+1) % input.form.length].focus();
     }
          function containsElement(arr, ele) {
               var found = false, index = 0;
            while(!found && index < arr.length)
              if(arr[index] == ele)
                 found = true;
                  else
                 index++;
               return found;
                }
          function getIndex(input) {
               var index = -1, i = 0, found = false;
                while (i < input.form.length && index == -1)
                        if (input.form[i] == input)index = i;
                          else i++; 
                         return index;
                 }
          return true;
      }
      
function fnShowMovies(ctrlObjPopu, ctrlObjComm)
{  
	document.getElementById(ctrlObjComm).style.visibility="visible";
	document.getElementById(ctrlObjComm).style.display	='block';
	document.getElementById(ctrlObjPopu).style.visibility="hidden";
	document.getElementById(ctrlObjPopu).style.display	='none';
	
	document.getElementById('ShowM').className='rcActTab';
	document.getElementById('showS').className='rcnTab';

}
function fnShowSongs(ctrlObjPopu, ctrlObjComm)
{
	document.getElementById(ctrlObjPopu).style.visibility="visible";
	document.getElementById(ctrlObjPopu).style.display	='block';
	document.getElementById(ctrlObjComm).style.visibility="hidden";
	document.getElementById(ctrlObjComm).style.display	='none';
	
	document.getElementById('showS').className='rcActTab';
	document.getElementById('ShowM').className='rcnTab';
}      
function echeck(str)
 {

	
 		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    
		    return false
		 }

 		 return true					
	}
	
function ResizeThem()
{
    var maxheight = 100;
    var maxwidth = 100;
    var imgs = document.getElementsByTagName("img");
    for ( var p = 0; p < imgs.length; p++ )
    {
            if ( imgs[p].getAttribute("alt") == "resize" )
             {
                var w = parseInt( imgs[p].width );
                var h = parseInt( imgs[p].height );
                if ( w > maxwidth )
                {
                    imgs[p].style.cursor = "pointer";
                        h = ( maxwidth / w ) * h;
                        w = maxwidth;
                        imgs[p].height = h;
                        imgs[p].width = w;
                }

                if ( h > maxheight )
                {
                    imgs[p].style.cursor="pointer";
                        imgs[p].width = ( maxheight / h ) * w;
                        imgs[p].height = maxheight;
                }
            }
    }
}

function fnDoClickEnter(buttonName,e)
{
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.

    var key;
	if(window.event)
	{
		key = window.event.keyCode;     //IE
	}
	else
	{
		key = e.which;     //firefox
	//	key = key.charCode;     //firefox
	}
	
     if (document.all)
     {
      	keyCode = eventObj.keyCode
     }
     else
     {
      	keyCode = eventObj.which
     }	

    if (key == 13)
    {
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		if (btn != null)
		{ //If we find the button click it
			btn.click();
			event.keyCode = 0
		}
    }
}

function fnEnterHitSearch(eventObj, obj,buttonName)
{
     var keyCode

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

    if (keyCode == 13)
    {
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		if (btn != null)
		{ 
			//document.getElementById(buttonName).focus();
			btn.click();
			eventObj.keyCode = 0
		}
    }
}

// strDate = 04-15-2009
//
// return timestamp
function fnGetTimeStamp(strDate)
{
	objMonth = {
		"01":"00",
		"02":"01",
		"03":"02",
		"04":"03",
		"05":"04",
		"06":"05",
		"07":"06",
		"08":"07",
		"09":"08",
		"10":"09",
		"11":"10",
		"12":"11"
		};
	
//2009-03-01
	arrTemp = strDate.split("-");
	date = new Date(arrTemp[2],objMonth[arrTemp[0]],arrTemp[1]);
			

	//alert( date.getFullYear()+"-"+(mm)+"-"+dd);
	return date.getTime();
}

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();
}

function fnSetDisplayPoll(intRecordId,resDivId,throbberDivId)
{
	if ((intRecordId > 0))
	{
		strArgs = "rid="+intRecordId+"&act=polld&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")
					{
						alert(xmlHTTP.responseText);
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlHTTP.status);
				}
		    }
		    else
		    {
		    	document.getElementById(throbberDivId).innerHTML = strThrobberImg;
		    }
		}
		xmlHTTP.send("");
	}
	else
	{
		//alert ('Invalid date, no events found for the this date');
		return false;
	}	
}


function fnSetDisplayNews(intRecordId,resDivId,throbberDivId)
{
	if ((intRecordId > 0))
	{
		strArgs = "nid="+intRecordId+"&act=newsbull&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")
					{
						alert(xmlHTTP.responseText);
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlHTTP.status);
				}
		    }
		    else
		    {
		    	document.getElementById(throbberDivId).innerHTML = strThrobberImg;
		    }
		}
		xmlHTTP.send("");
	}
	else
	{
		//alert ('Invalid date, no events found for the this date');
		return false;
	}	
}

function fnSetDisplayUseFulLink(intRecordId,resDivId,throbberDivId)
{
	if ((intRecordId > 0))
	{
		strArgs = "ulid="+intRecordId+"&act=usefullink&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")
					{
						alert(xmlHTTP.responseText);
					}
				}
				else
				{
					alert('Error:AJAX request status = ' + xmlHTTP.status);
				}
		    }
		    else
		    {
		    	document.getElementById(throbberDivId).sytle.display = '';
		    	document.getElementById(throbberDivId).innerHTML = strThrobberImg;
		    }
		}
		xmlHTTP.send("");
	}
	else
	{
		//alert ('Invalid date, no events found for the this date');
		return false;
	}	
}


function fnCharCountLeft(field, count, max)
{
	if (field.value.length > max)
	{
		field.value = field.value.substring(0, max);
	}
	else
	{
		count.value = max - field.value.length;
	}	
	document.getElementById('divDispCounter').innerHTML = count.value;
}

function fnIsPhoneNumber(eventObj, obj)
{
     var keyCode

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

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 fnGoToPage(strGotoPage)
{
	window.location = strGotoPage;
}

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 fnDispHideDetails(strImgElement,strElement,$strElementID,strImgPath)
{
	if (document.getElementById(strImgElement+$strElementID).src == strImgPath + "plus.gif")
	{
		document.getElementById(strImgElement+$strElementID).src = strImgPath + "minus.gif";
		document.getElementById(strImgElement+$strElementID).title = "Hide Details";
		document.getElementById(strElement+$strElementID).style.visibility = 'visible';
		document.getElementById(strElement+$strElementID).style.display = 'block';
		document.getElementById('taKw').focus();
	}
	else
	{
		document.getElementById(strImgElement+$strElementID).src = strImgPath + "plus.gif";
		document.getElementById(strImgElement+$strElementID).title = "Show Details";
		document.getElementById(strElement+$strElementID).style.visibility = 'hidden';
		document.getElementById(strElement+$strElementID).style.display = 'none';
		document.getElementById('hdnDispStatus').value = 0;
	}
}