//*************************************************************************
//	Name : JS_innerV3.js (formerly formavalidation.js)
//	Description	: Contains generic data validation functions in javascript
//				  for form's data validation like email validation function, 
//				  zip validation function etc.
//	Created : 24th September, 03
//	Author : Amit Choudhary
//	Last ModiFied :	11th April, 08
//	Last ModiFied By : Amit Choudhary
//*************************************************************************

// JScript source code

//	Declaring some global variables	for holding temporary values for calculation
	var i, j, strlen; 
	var strchar = new String("");

function jsZipCodeRangeValidation(strState, strZip)
{
	var strShortZip, arrFixValues, arrFixRanges, intCounter1;
	
	strZip = new String(Trim(strZip));
	strState = new String(strState);
	strState = strState.toUpperCase();
	strShortZip = parseInt(strZip.substr(0,3));
	
	for(intCounter1 = 0; intCounter1 < arrZip.length; intCounter1++)
	{
		if (strState == String(arrZip[intCounter1][0]).toUpperCase())
		{
			arrFixValues = String(arrZip[intCounter1][5]).split(",");
			arrFixRanges = String(arrZip[intCounter1][6]).split(",");
			if ( (strShortZip >= parseInt(arrZip[intCounter1][1]) && strShortZip <= parseInt(arrZip[intCounter1][2])) || (strShortZip >= parseInt(arrZip[intCounter1][3]) && strShortZip <= parseInt(arrZip[intCounter1][4])) || (IsArrayContainPassingElement(arrFixValues, strZip.substr(0,5))) || (IsArrayContainPassingElement(arrFixRanges, strShortZip)) )
				return true;
			else
				return false;
		}	
	}
}

function jsStateWiseZipValidation(strState, strZip)
{
	var intCounter1;
	
	strZip = new String(Trim(strZip)).substr(0,5);
	strState = new String(strState).toUpperCase();

	for(intCounter1 = 0; intCounter1 < arrZip.length; intCounter1++)
	{
		if (strState == arrZip[intCounter1][0])
		{
			if ( strZip >= arrZip[intCounter1][1] && strZip <= arrZip[intCounter1][2] )
				return true;
		}
	}
	return false;		
}


function fgetHelp(aid, id)
{
	var str = "window.open('HelpFile.asp?fldname=" + id + "')"
	document.getElementById(aid).href = str;
}

//	For getting handle of the window which show the help for a particular field
	var HelpWindow;

//	For Defining initial shape and behaviour of the new window
	var strHelpWinProp

//	Specifying initial shape and behaviour of the new window
	strHelpWinProp = " toolbar=no"  
	//	Back, Forward, etc...
	+ ",location=no"			
	//	URL field(Address Bar)
	+ ",directories=no"			
	//	"What's New", etc...
	+ ",status=yes"				
	//	Status Bar at bottom of window.
	+ ",menubar=no"				
	//	Menubar at top of window.
	+ ",resizable=0"	//	1 = "yes", 0 = "no"		
	//	Allow resizing by dragging. 
	+ ",scrollbars=yes"			
	//	Displays scrollbars if document is larger than window.
	+ ",titlebar=yes"			
	//	Enable/Disable titlebar resize capability.
	+ ",width=600"
	//	Defining width of window equal to current screen width
	+ ",height=500"
	//	Defining height of window equal to current screen height - 55(pixcel)
	//	so the taskbar is also visible
	+ ",top="+(((screen.availHeight) - 500)	/2)				
	//	 Offset of windows top edge from screen.
	+ ",left="+(((screen.availWidth) - 600)	/2)					
	//	Offset of windows left edge from screen.
	+ "";

function Open_Show_HelpWindow(strField)
{
//	Get the field name and append this to the 
//	specifyed asp page as querystring
	
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	sPage = sPage.substring(sPage.lastIndexOf('/') + 1);
	//alert(sPage);
	
	//var myString = "HelpFile.asp?field=" + strField + "£¥£¥" + sPage
	var myString = "HelpFile.asp?field=" + strField + "56648931231" + sPage
	
	//alert(myString);

	if(HelpWindow && HelpWindow.open && !HelpWindow.closed)
	{
//		Checking if the HelpWindow is exist and not closed than
//		replace it's location to the new Url(myString)
//		and set focus on it
		HelpWindow.location.replace(myString);
		HelpWindow.focus();
	}
	else
	{
//		HelpWindow is not exist so open a new window with the
//		specifyed Url(myString) and initial parameter (strHelpWinProp)
//		and take this window's handle in to the HelpWindow
//		so we can reuse this window
		HelpWindow = window.open(myString,'wndHelp',strHelpWinProp); 
		if(HelpWindow && HelpWindow.open && !HelpWindow.closed)
		    HelpWindow.focus();
	}
}

//*** ======================================================================
//*** This function is added by Amit On 8th March, 07
//*** This will open a pop up window for displaying new 2006 Questions.
function Open_Window_NewQ2006(strLink)
{
    if(HelpWindow && HelpWindow.open && !HelpWindow.closed)
	{
	    //		Checking if the HelpWindow is exist and not closed than
        //		replace it's location to the new Url(myString)
        //		and set focus on it
		HelpWindow.location.replace(strLink);
		HelpWindow.focus();
	}
	else
	{
	    //		HelpWindow is not exist so open a new window with the
        //		specifyed Url(myString) and initial parameter (strHelpWinProp)
        //		and take this window's handle in to the HelpWindow
        //		so we can reuse this window
        HelpWindow = window.open(strLink,'New2006Questions',strHelpWinProp); 
        if(HelpWindow && HelpWindow.open && !HelpWindow.closed)
		    HelpWindow.focus();
	}
    
}

//*** End Of Addition By Amit On 8th March, 07
//*** ======================================================================

function sessionTimeOut()
{
    //	alert("In sessionTimeOut");
	window.setTimeout('self.focus(); alert("If your session continues to be idle, you will be logged off in two minutes and your changes will be lost. To avoid this, save your information or go to another page using the buttons at the bottom of the page.");',1620000);
}

function sessionExpiredMessage()
{
    //	alert("In sessionExpiredMessage");
	window.setTimeout('self.focus(); alert("Your session has timed out and you have been logged off. You will now be directed to the login page to login again."); sessionExpired();',1740000);
}

function sessionExpired()
{
	var strRedirectPage;
	strRedirectPage = '990LogOut.asp';
	
//	var obj = document.createElement("input");
//	obj.type = "hidden";
//	obj.name = "menuredirectpage";
//	obj.id = "menuredirectpage";
//	obj.value = strRedirectPage;
//	
//	var objForm = document.createElement("form");
//	objForm.method = "post";
//	objForm.action = "990EZMenuRedirect.asp";
//	
//	objForm.appendChild(obj);
//	   
//	document.appendChild(objForm);
//	objForm.submit();

	var boolIE = document.all;
	if(boolIE && navigator.platform == "Win32")
	{
		var objForm = document.createElement("form");
		objForm.method = "post";
		objForm.action = "990EZMenuRedirect.asp?menuredirectpage=" + strRedirectPage;
		
		document.appendChild(objForm);
		objForm.submit(); 
	}
	else
	{		
		var objForm = document.forms[0];
		objForm.method = 'post';
		objForm.action = "990EZMenuRedirect.asp?menuredirectpage=" + strRedirectPage;
		objForm.submit();
	}
	
	
/*	var objForm = document.forms[0];
	objForm.method = 'post';
	objForm.action = "990EZMenuRedirect.asp?menuredirectpage=" + strRedirectPage;
	objForm.submit();
*/
}

var sjsPath = new String(window.location.pathname);
//alert(sjsPath);
var sjsPage = new String(sjsPath.substring(sjsPath.lastIndexOf('\\') + 1));
//alert(sjsPage);
sjsPage = sjsPage.substring(sjsPage.lastIndexOf('/') + 1).toLowerCase();
//alert(sjsPage);

var arrPageName = new Array();
arrPageName[0] = "990NVerifyFields.asp";
arrPageName[1] = "Form990NCreate.asp";
arrPageName[2] = "Form990NDBAName.asp";
arrPageName[3] = "Form990NMainPartI.asp";
arrPageName[4] = "Form990NMainPartII.asp";

var strPageX;
for (intPageX in arrPageName){
    if(arrPageName[intPageX].toLowerCase() == sjsPage){
        sessionTimeOut();
	    sessionExpiredMessage();
    }
}

if(sjsPath.indexOf("DEntry") > -1){
    
    if(sjsPage.substr(0,8) == "frmadmin"){ 
        sessionTimeOut();
        sessionExpiredMessage();
    }
}

function WithOutMenuMenuFormSubmit(strRedirectPage)
{
	var objForm = document.forms[0];
	objForm.method = 'post';
	objForm.action = "990EZMenuRedirect.asp?menuredirectpage=" + strRedirectPage;
	objForm.submit();
}


function WithOutMenuForm990Logout(strRedirectPage)
{
	var boolSave;
	
	boolSave = confirm("Do you want to logout from this site? Click \"OK\" to log out and return to the Home page. Click \"Cancel\" to stay logged in.");
	
	if (boolSave == true)
	{
		var objForm = document.forms[0];
		objForm.method = 'post';
		objForm.action = "990EZMenuRedirect.asp?menuredirectpage=" + strRedirectPage;
		objForm.submit();
	}
}

function attachGeneric_onkeypress()
{
	//alert("in attachGeneric_onkeypress");
	
	var intFormCounter, intElementCounter, formObj, elemntObj, strElementType, strElementClass;
	strElementType = new String("");
	strElementClass = new String("");
	for(intFormCounter = 0; intFormCounter < document.forms.length; intFormCounter++)
	{
		formObj = document.forms[intFormCounter]
		//alert((intFormCounter + 1) + " Form Name is : " + formObj.name + ".");
		if(! formObj)
		{
			alert("Error : Could not get Form object.");
			return false;
		}
		//alert(formObj.elements.length)
		for(intElementCounter = 0; intElementCounter< formObj.elements.length; intElementCounter++)
		{
			elemntObj = formObj.elements[intElementCounter]
			if(elemntObj)
			{
				strElementType = elemntObj.type;
				if(strElementType.toLowerCase() == "text" || strElementType.toLowerCase() == "textarea")
				{
					strElementClass = elemntObj.className;
					if(strElementClass.toLowerCase() != "txtboxcurrency" &&  strElementClass.toLowerCase() != "txtboxcurcalc")
					{
						//return;
						//alert(elemntObj.name);
					/*	if(elemntObj.onkeypress)
						{
							//alert((intElementCounter +1) + " Object Name is : " + elemntObj.name + ", has a keypress event assocated with it.");
							//alert(elemntObj.onkeypress);
							elemntObj.onkeypress = null;
						}
						elemntObj.onkeypress = genericFormKeyPress;
						
					*/	
						if(elemntObj.onblur)
						{
							elemntObj.onblur = null;
						}
						elemntObj.onblur = genericFormBlur;
					}
				}
			}
		}
	}
}

function genericFormKeyPress(objEvent)
{
	if(this.name == "name")
	{
		// ^a-zA-Z0-9 -()&']
		var intKey;
		if(document.all)
		{
			intKey = window.event.keyCode;
			
		}
		else
		{
			intKey = objEvent.which;
		}
			
		//alert(String.fromCharCode(intKey))
			
		//alert(this.name);
		//alert(intKey)
			
		// 13 For Return (Enter) Key
		// 38 For Ampersand (&) Key
		// 39 For Apostrophe (') Key
		// 34 For Quote (") Key
			
		if(intKey == 13 || intKey == 38 || intKey == 39 || intKey == 34)
			return false;
		else
			return true;
	}
}

function testDisable()
{
	var intFormCounter, intElementCounter, formObj, elemntObj, strElementType
	strElementType = new String("");
	for(intFormCounter = 0; intFormCounter < document.forms.length; intFormCounter++)
	{
		formObj = document.forms[intFormCounter]
		if(! formObj)
		{
			alert("Error : Could not get Form object.");
			return false;
		}
		for(intElementCounter = 0; intElementCounter< formObj.elements.length; intElementCounter++)
		{
			elemntObj = formObj.elements[intElementCounter]
			if(elemntObj)
			{
				strElementType = elemntObj.type;
				if(strElementType.toLowerCase() == "button" || strElementType.toLowerCase() == "submit")
				{
					elemntObj.disabled = true;
				}
			}
		}	
	}
}

//window.setTimeout('testDisable();', 3000);

function genericFormBlur(objEvent)
{
	var regPattern;
	var regObj;
	var boolValid = true;
	var objValue = new String(this.value);
	objValue = Trim(objValue);
	this.value = objValue;
	if(this.name == "name")
	{
		//alert(this.name);
		//alert(this.value);
		//regPattern = "(([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;) ?)*([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;)"
	/*	if(objValue.search(/(([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;) ?)*([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;)/) == -1)
		{
			boolValid = false;
			alert("InValid");
		}
		else
		{
			alert("Valid");
		}*/
		
		//regObj = new RegExp("(([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;) ?)*([A-Za-z0-9#\-\(\)]|&#x26;|&#x27;)")
		//regObj = new RegExp("(([A-Za-z0-9#\\-\\(\\)]|&#x26;|&#x27;) ?)*([A-Za-z0-9#\\-\\(\\)]|&#x26;|&#x27;)")
		regObj = new RegExp("(([A-Za-z0-9#\\-\\(\\)]|&|') ?)*([A-Za-z0-9#\\-\\(\\)]|&|')")
	/*	
		alert(regObj.exec(objValue));
		alert(objValue.search(/(([A-Za-z0-9#\\-\\(\\)]|&|') ?)*([A-Za-z0-9#\\-\\(\\)]|&|')/));
		alert(regObj.test(objValue));
		alert(objValue.match(regObj));
		if(regObj.exec(objValue) == null)
		{
			boolValid = false;
			alert("not match");
		}
		else
		{
			alert("matched");
		}*/
		
		//alert(objValue);
		var strTemp = "ùÿÖÜ¢£¥Pƒá";
		objValue = objValue.replace(regObj, strTemp);
		//alert(objValue);
		if(strTemp != objValue)
		{
	//		alert("Invalid");
		}
		else
		{
	//		alert("Valid");
		}
	}

//	if(boolValid == false)
//	{
//		alert("InValid");
//	}
}

//*** ********************************************************************************
//*** Added by Amit on 13th September, 07

//*** This function checks that user enters valid data in the control
//*** using the regular expression or charcter checking one by one
//*** ********************************************************************************

function validateInputData(ControlType, obj, strDescription)
{
    if (obj == null)
        return true;
    
    if (Trim(obj.value) == "")
        return true;
    
    var regexp = /[*]/;
    var flag = "notfromButton";
    
    while (ControlType.match(regexp))
    {
        ControlType = ControlType.replace(regexp,"");
        flag = "fromButton";
    }
    //alert(flag);
    
    ControlType = ControlType.toLowerCase();
    //alert(ControlType);
    
    if(arguments.length == 4 && arguments[arguments.length -1] != "US")
    {
        if(ControlType == "zipcode")
            ControlType = "foreignzipcode";
        
        if(ControlType == "city")
            ControlType = "foreigncity";
            
        if(ControlType == "state")
            ControlType = "foreignstate";
    }
    //alert(ControlType);
    
    var strval, keycode, i, strBadChars, strModifiedString, boolChange, strMessage, strWord;
    strval = new String(Trim(obj.value));
    for (i=0;i<strval.length;i++)  
    {
        strval = strval.replace("  ", " ");
    }
    obj.value = strval;
    strBadChars = new String("");
    strModifiedString = new String("");
    //alert(strval);
    
    // Common Key Codes
    // 97 to 122 = a to z, 65 to 90 = A to Z, 48 to 57 = 0 to 9
    // 32 = Single Space [ ], 35 = Hash Sign [#], 36 = Dollar Sign [$], 37 = Percent [%]
    // 38 = Ampersand [&], 39 = Apostrophe ['], 40 = Opening Parenthesis [()], 41 = Closing Parenthesis [)]
    // 44 = Comma [,], 45 = Hyphen [-], 46 = Period Or Dot[.], 47 = Slash [/], 92 = Back Slash [\] (Use \\ in JS Code)
    
    if(ControlType == "person" || ControlType == "individual")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45 || keycode == 32)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
     
    if(ControlType == "businessline1")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45 || keycode == 32 || keycode == 35 || keycode == 38 || keycode == 40 || keycode == 41)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "businessline2")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45 || keycode == 32 || keycode == 35 || keycode == 38 || keycode == 40 || keycode == 41 || keycode == 37 || keycode == 47)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "careof")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 35 || keycode == 47 || keycode == 37 || keycode == 45 || keycode == 40 || keycode == 41 || keycode == 39 || keycode == 38 || keycode == 32)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "address")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 45 || keycode == 32 || keycode == 47)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "city")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode>=65 && keycode <=90 || keycode == 32)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "foreignstate" || ControlType == "foreignzipcode" || ControlType == "foreigncity")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 32 && keycode <= 126 || keycode >= 161 && keycode <= 191 || keycode == 193 || keycode == 201 || keycode == 205 || keycode == 209 || keycode == 211 || keycode == 215 || keycode == 218 || keycode == 220 || keycode == 225 || keycode == 233 || keycode == 237 || keycode == 241 || keycode == 243 || keycode == 250 || keycode == 252)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                    strBadChars = strBadChars + " " + strval.charAt(i);
        }
    }
    
    if(ControlType == "website")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 33 && keycode <= 126)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
    }
    
    strBadChars = Trim(strBadChars);
    if(strBadChars.length > 0)
    {
        //alert(strBadChars);
        if(strBadChars.length > 1 && strBadChars != "SingleSpace")
        {
            if(strBadChars.indexOf("(") != -1 && strBadChars.indexOf("(") != -1)
                strBadChars = strBadChars.replace(") ", "")
            //alert(strBadChars);
            
            strBadChars = strBadChars.replace(")", "(")
            
            strBadChars = strBadChars.replace(",", "Comma[]");
            //alert(strBadChars);
            strBadChars = strBadChars.replace(/ /g, ", ");
            //alert(strBadChars);
            strBadChars = strBadChars.replace("Comma[]", "Comma [,]");
            //alert(strBadChars);
            
            strWord = new String("characters");
        }
        else
        {
            strBadChars = strBadChars.replace(",", "Comma [,]");
            
            strWord = new String("character");
        }
        //alert(strBadChars);
        
        strBadChars = strBadChars.replace("SingleSpace", "Single Space [ ]");
        
        strBadChars = strBadChars.replace("-", "Hyphen [-]");
        strBadChars = strBadChars.replace("'", "Apostrophe [']");
        strBadChars = strBadChars.replace("$", "Dollar Sign [$]");
        strBadChars = strBadChars.replace("#", "Hash Sign [#]");
        strBadChars = strBadChars.replace("&", "Ampersand [&]");
        strBadChars = strBadChars.replace("%", "Percent [%]");
        strBadChars = strBadChars.replace("/", "Slash [/]");
        strBadChars = strBadChars.replace("\\", "Back Slash [\\]");
        strBadChars = strBadChars.replace(".", "Period [.]");
        strBadChars = strBadChars.replace("(", "Parenthesis [()]");
        
        strModifiedString = strModifiedString.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ')
        if (flag != "fromButton")
        {
            strMessage = Trim(strDescription) + " does not accept the following " + strWord + ": " + strBadChars + ".\n\n";
            strMessage = strMessage + "We recommend that you change this entry to read: " + strModifiedString + "\n\n"
            strMessage = strMessage + "Click \"OK\" to accept this change or \"Cancel\" if you want to change the field yourself."
            boolChange = confirm(strMessage);
            if(boolChange == true)
                obj.value = strModifiedString;
            
            return true;
        }
        else
        {
            if(strWord == "character")
                strMessage = Trim(strDescription) + " does not accept the following character: " + strBadChars + ". Please remove this character.";
            else
                strMessage = Trim(strDescription) + " does not accept the following characters: " + strBadChars + ". Please remove these characters.";
            
            return strMessage;
        }
    }
    return true;
}

//*** End Of Addition By Amit On 18th April, 08
//*** =====================================================================================

//*** ********************************************************************************
//*** Added by Amit on 29th April, 07

//*** This function checks that user enters valid data at first position or not
//*** ********************************************************************************

function validateInputDataPosition(ControlType, obj, strDescription)
{
    if (obj == null)
        return true;
    
    if (Trim(obj.value) == "")
        return true;
    
    var regexp = /[*]/;
    var flag = "notfromButton";
    
    while (ControlType.match(regexp))
    {
        ControlType = ControlType.replace(regexp,"");
        flag = "fromButton";
    }
    //alert(flag);
    
    ControlType = ControlType.toLowerCase();
    //alert(ControlType);
    
    if(arguments.length == 4 && arguments[arguments.length -1] != "US")
    {
        if(ControlType == "zipcode")
            ControlType = "foreignzipcode";
        
        if(ControlType == "city")
            ControlType = "foreigncity";
            
        if(ControlType == "state")
            ControlType = "foreignstate";
    }
    //alert(ControlType);
    
    var strval, keycode, i, strBadChars, strModifiedString, boolChange, strMessage, strWord, strAllowable;
    strval = new String(Trim(obj.value));
    for (i=0;i<strval.length;i++)  
    {
        strval = strval.replace("  ", " ");
    }
    obj.value = strval;
    strBadChars = new String("");
    strModifiedString = new String("");
    //alert(strval);
    
    // Common Key Codes
    // 97 to 122 = a to z, 65 to 90 = A to Z, 48 to 57 = 0 to 9
    // 32 = Single Space [ ], 35 = Hash Sign [#], 36 = Dollar Sign [$], 37 = Percent [%]
    // 38 = Ampersand [&], 39 = Apostrophe ['], 40 = Opening Parenthesis [()], 41 = Closing Parenthesis [)]
    // 44 = Comma [,], 45 = Hyphen [-], 46 = Period Or Dot[.], 47 = Slash [/], 92 = Back Slash [\] (Use \\ in JS Code)
    
    if(ControlType == "person" || ControlType == "individual")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hyphen [-] or Apostrophe [']");
    }
     
    if(ControlType == "businessline1")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45 || keycode == 35 || keycode == 38 || keycode == 40 || keycode == 41)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hash Sign [#] or Hyphen [-] or Parenthesis [()] or Ampersand [&] or Apostrophe [']");
    }
    
    if(ControlType == "businessline2")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 39 || keycode == 45 || keycode == 35 || keycode == 38 || keycode == 40 || keycode == 41 || keycode == 37 || keycode == 47)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hash Sign [#] or Hyphen [-] or Parenthesis [()] or Ampersand [&] or Apostrophe ['] or Slash [/] or Percent [%]");
    }
    
    if(ControlType == "careof")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90 || keycode == 35 || keycode == 47 || keycode == 37 || keycode == 45 || keycode == 40 || keycode == 41 || keycode == 39 || keycode == 38)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hash Sign [#] or Hyphen [-] or Parenthesis [()] or Ampersand [&] or Apostrophe ['] or Slash [/] or Percent [%]");
    }
    
    if(ControlType == "address")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode >=48 && keycode <= 57 || keycode>=65 && keycode <=90)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9]");
    }
    
    if(ControlType == "city")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 97 && keycode <= 122 || keycode>=65 && keycode <=90)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z]");
    }
    
    if(ControlType == "foreignstate" || ControlType == "foreignzipcode" || ControlType == "foreigncity")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 33 && keycode <= 126 || keycode >= 161 && keycode <= 191 || keycode == 193 || keycode == 201 || keycode == 205 || keycode == 209 || keycode == 211 || keycode == 215 || keycode == 218 || keycode == 220 || keycode == 225 || keycode == 233 || keycode == 237 || keycode == 241 || keycode == 243 || keycode == 250 || keycode == 252)
                i = strval.length + 1;
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hash Sign [#] or Hyphen [-] or Parenthesis [()] or Ampersand [&] or Apostrophe ['] or Slash [/] or Percent [%] or standard US keyboard characters");
    }
    
    if(ControlType == "website")
	{
	    for (i=0;i<strval.length;i++)  
        {
            keycode = strval.charCodeAt(i)
            if (keycode >= 33 && keycode <= 126)
                strModifiedString = strModifiedString + strval.charAt(i);
            else
                if(strBadChars.indexOf(strval.charAt(i)) == -1)
                {
                    if(keycode != 32)
                        strBadChars = strBadChars + " " + strval.charAt(i);
                    else
                        strBadChars = strBadChars + " " + "SingleSpace";
                }
        }
        strAllowable = new String("Letter [A to Z or a to z] or Number [0 to 9] or Hash Sign [#] or Hyphen [-] or Parenthesis [()] or Ampersand [&] or Apostrophe ['] or Slash [/] or Percent [%] or standard US keyboard characters");
    }
    
    strBadChars = Trim(strBadChars);
    if(strBadChars.length > 0)
    {
        //alert(strBadChars);
        if(strBadChars.length > 1 && strBadChars != "SingleSpace")
        {
            if(strBadChars.indexOf("(") != -1 && strBadChars.indexOf("(") != -1)
                strBadChars = strBadChars.replace(") ", "")
            //alert(strBadChars);
            
            strBadChars = strBadChars.replace(")", "(")
            
            strBadChars = strBadChars.replace(",", "Comma[]");
            //alert(strBadChars);
            strBadChars = strBadChars.replace(/ /g, ", ");
            //alert(strBadChars);
            strBadChars = strBadChars.replace("Comma[]", "Comma [,]");
            //alert(strBadChars);
            
            strWord = new String("characters");
        }
        else
        {
            strBadChars = strBadChars.replace(",", "Comma [,]");
            
            strWord = new String("character");
        }
        //alert(strBadChars);
        
        strBadChars = strBadChars.replace("SingleSpace", "Single Space [ ]");
        
        strBadChars = strBadChars.replace("-", "Hyphen [-]");
        strBadChars = strBadChars.replace("'", "Apostrophe [']");
        strBadChars = strBadChars.replace("$", "Dollar Sign [$]");
        strBadChars = strBadChars.replace("#", "Hash Sign [#]");
        strBadChars = strBadChars.replace("&", "Ampersand [&]");
        strBadChars = strBadChars.replace("%", "Percent [%]");
        strBadChars = strBadChars.replace("/", "Slash [/]");
        strBadChars = strBadChars.replace("\\", "Back Slash [\\]");
        strBadChars = strBadChars.replace(".", "Period [.]");
        strBadChars = strBadChars.replace("(", "Parenthesis [()]");
        
        strModifiedString = strModifiedString.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ')
        if (flag != "fromButton")
        {
            strMessage = Trim(strDescription) + " does not accept the following " + strWord + ": " + strBadChars + ".\n\n";
            strMessage = strMessage + "We recommend that you change this entry to read: " + strModifiedString + "\n\n"
            strMessage = strMessage + "Click \"OK\" to accept this change or \"Cancel\" if you want to change the field yourself."
            boolChange = confirm(strMessage);
            if(boolChange == true)
                obj.value = strModifiedString;
            
            return true;
        }
        else
        {
            if(strWord == "character")
                strMessage = Trim(strDescription) + " cannot start with " + strBadChars + ", it must start with a " + strAllowable + ".";
            else
                strMessage = Trim(strDescription) + " cannot start with " + strBadChars + ", it must start with a " + strAllowable + ".";
            
            return strMessage;
        }
    }
    return true;
}

//*** End Of Addition By Amit On 30th April, 08
//*** =====================================================================================

//*** ********************************************************************************
//*** Added By Amit On 11th October, 07

//*** The below function will show or hide the asterik (if the filed is required/not 
//*** required during the verification process) and change the text colort to red if 
//*** field has error or make it normal if field don't has error based on the passing value
function showRemoveErrorMessage(callType, strFieldName)
{
    callType = new String(callType).toLowerCase();
    
    var strInnerHTML;
    var intCount;
    var strID;
    
    if(callType == "removeall")
    {
        //document.getElementById("td_SREM_n0_dba1").innerHTML = document.getElementById("td_SREM_n0_dba1").innerHTML + "<span class=\"detailtextRed\">*</span>";
	                
        var arrTDName = document.getElementsByTagName("td");
        //alert(arrTDName.length);
        
        for(intCount = 0; intCount < arrTDName.length; intCount++)
        {
            strID = new String(arrTDName[intCount].id);
            if(strID.indexOf("td_SREM_",0) > -1)
            {
                //alert(strID);
                strInnerHTML = new String(document.getElementById(arrTDName[intCount].id).innerHTML);
                //alert(strInnerHTML);
                //alert(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
                //alert(strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0));
                if(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0) > -1)
                    document.getElementById(arrTDName[intCount].id).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
                else
                    if(strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0) > -1)
                        document.getElementById(arrTDName[intCount].id).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0));
                    else
                        if(strInnerHTML.indexOf("<SPAN class=\"detailtextRed\">*</SPAN>", 0) > -1)
                            document.getElementById(arrTDName[intCount].id).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<SPAN class=\"detailtextRed\">*</SPAN>", 0));
            }
        }
        
        /*for(intCount = 0; intCount < arrTD.length; intCount++)
        {
            strInnerHTML = new String(document.getElementById(arrTD[intCount].id).innerHTML);
            alert(strInnerHTML);
            alert(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
            if(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0) > -1)
                document.getElementById(arrTD[intCount].id).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
        }*/
    }
    
    if(callType == "add")
    {
        strInnerHTML = new String(document.getElementById("td_SREM_" + strFieldName).innerHTML);
        if(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0) > -1)
            document.getElementById("td_SREM_" + strFieldName).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
        else    
            if(strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0) > -1)
                document.getElementById("td_SREM_" + strFieldName).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0));
        
        document.getElementById("td_SREM_" + strFieldName).innerHTML = document.getElementById("td_SREM_" + strFieldName).innerHTML + "<span class=\"detailtextRed\">*</span>";
    }
    
    if(callType == "remove")
    {
        strInnerHTML = new String(document.getElementById("td_SREM_" + strFieldName).innerHTML);
        if(strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0) > -1)
            document.getElementById("td_SREM_" + strFieldName).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<span class=\"detailtextRed\">*</span>", 0));
        else    
            if(strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0) > -1)
                document.getElementById("td_SREM_" + strFieldName).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<SPAN class=detailtextRed>*</SPAN>", 0));
            else
            if(strInnerHTML.indexOf("<SPAN class=\"detailtextRed\">*</SPAN>", 0) > -1)
                document.getElementById("td_SREM_" + strFieldName).innerHTML = strInnerHTML.substring(0, strInnerHTML.indexOf("<SPAN class=\"detailtextRed\">*</SPAN>", 0));
    }
}
		
//*** ********************************************************************************
//*** End Of Addition By Amit On 11th October, 07
//*** ********************************************************************************

//*** ********************************************************************************
//*** Added By Amit On 27th February, 08

//*** The Below code will show popup layer in which we can show some text or images
//*** for help purpouse

// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
// ********************************
// application-specific functions *
// ********************************

// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
var xOffset = -350;
var yOffset = 10;

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
    // hide any currently-visible popups
    hideCurrentPopup();
    // stop event from bubbling up any farther
    eventObj.cancelBubble = true;
    // move popup div to current cursor position 
    // (add scrollTop to account for scrolling for IE)
    var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
    var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
    
    //if(newXCoordinate < 0)
    //    newXCoordinate = 10;
    
    if(window.screen.width >= 700)
        newXCoordinate = parseInt((window.screen.width - 700) / 2);
    else
        newXCoordinate = 10;
    
    //alert(newXCoordinate);
    
        
    //if(newYCoordinate < 0)
    //    newYCoordinate = 100;
    
    if(newYCoordinate < 500)
        newYCoordinate = 100;
    else
        newYCoordinate = newYCoordinate - 400;
    
    
    
    moveObject(targetObjectId, newXCoordinate, newYCoordinate);
    // and make it visible
    if( changeObjectVisibility(targetObjectId, 'visible') ) {
        // if we successfully showed the popup
        // store its Id on a globally-accessible object
        window.currentlyVisiblePopup = targetObjectId;
        return true;
    } else {
        // we couldn't show the popup, boo hoo!
        return false;
    }
    } else {
    // there was no event object, so we won't be able to position anything, so give up
    return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
    changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
    window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
    && (navigator.platform.indexOf('Mac') != -1)
    && getStyleObject('blankDiv')) {
    window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
    window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
    && (navigator.platform.indexOf('Mac') != -1)
    && getStyleObject('blankDiv')) {
    getStyleObject('blankDiv').width = document.body.clientWidth - 20;
    getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
    return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
    return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
    return document.layers[objectId];
    } else {
    return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
    styleObject.visibility = newVisibility;
    //alert(newVisibility);
    if(newVisibility == "hidden")
    {
        styleObject.display = "none";
    }
    else
    {
        styleObject.display = "block";
    }            
    return true;
    } else {
    // we couldn't find the object, so we can't change its visibility
    return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    //alert(newXCoordinate);
    //alert(newYCoordinate);
    
    //if(newXCoordinate < 0)
    //    newXCoordinate = 10;
        
    //if(newYCoordinate < 0)
    //    newYCoordinate = 100;
    
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
    styleObject.left = newXCoordinate;
    styleObject.top = newYCoordinate;
    return true;
    } else {
    // we couldn't find the object, so we can't very well move it
    return false;
    }
} // moveObject

//*** ********************************************************************************
//*** End Of Addition By Amit On 27th February, 08
//*** ********************************************************************************

function BrowserBasedDisplay(objControl)
{
    BrowserDetect.init();
    if(typeof(objControl) == "undefined" || objControl == null)
        return false;
    
    if (BrowserDetect.browser == 'Microsoft Internet Explorer')
    {
        try
        {
            objControl.style.display = "inline";
        }
        catch(errObj)
        {
            //alert(errObj.message);
            objControl.style.display ="table-row";
        }
    }
    else
    {
        try
        {
            objControl.style.display ="table-row";
        }
        catch(errObj)
        {
            //alert(errObj.message);
            objControl.style.display ="inline";
        }
    }    
}