/*
#############################################################################
#            Alabanza Corporation PROPRIETARY AND CONFIDENTIAL              #
#                                                                           #
#  This  information  includes  trade  secrets  and confidential commercial #
#  and/or financial information belonging to Alabanza Corporation.          #
#  It is exempt from  disclosure  under  the  Freedom  of Information Act.  #
#  Unauthorized  disclosure  and/or  use of  this  information  without the #
#  express  written  consent of Alabanza Corporation is  prohibited and     #
#  may   result  in  criminal   prosecution  and   penalties   pursuant  to #
#  18 U.S.C. section 1905.                                                  #
#                                                                           #
#              COPYRIGHT Alabanza Corporation (Unpublished Work)            #
#############################################################################
*/

/**
*	Function Name:	checkSpacer()
*	Description:	Validates Text Spacer Value.
*	In Parameter:	Spacer's Value
*	Out Parameter:	true boolean - if pattern is matched.
*					false boolean - if pattern is not matched.
* 	Author: 		Ashutosh Jindal
*/

function checkSpacer(spacerValue) {
	var pattern = /^\d{1,}(\.\d{1,2})?$/;  //decimal
	//var pattern2=/\d{1,3}/;  //whole Numbers
	if ( spacerValue.match(pattern) != null ) {
		return true;
	} else	{
		return false;
	}
}

/**
*	Function Name:	trim()
*	Description:	Removes the leading and trailing spaces.
*	In Parameter:	str string
*	Out Parameter:	str string
*/
 function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.

	if (typeof inputString != "string")	{
		return inputString;
	}
   	var retValue = inputString;

	// Check for spaces at the beginning of the string
   	var ch = retValue.substring(0, 1);
   	while (ch == " ") {
      	retValue = retValue.substring(1, retValue.length);
      	ch = retValue.substring(0, 1);
   	}

	// Check for spaces at the end of the string
   	ch = retValue.substring(retValue.length-1, retValue.length);
   	while (ch == " ") {
	  	retValue = retValue.substring(0, retValue.length-1);
      	ch = retValue.substring(retValue.length-1, retValue.length);
   	}
   	return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



/**
*	Function Name:	trim()
*	Description:	Removes the leading and trailing spaces.
*	In Parameter:	str string
*	Out Parameter:	str string
*/
 function trimPassword(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.

	if (typeof inputString != "string")	{
		return inputString;
	}
   	var retValue = inputString;

	// Check for spaces at the beginning of the string
   	var ch = retValue.substring(0, 1);
   	while (ch == " ") {
      	retValue = retValue.substring(1, retValue.length);
      	ch = retValue.substring(0, 1);
   	}

	// Check for spaces at the end of the string
   	ch = retValue.substring(retValue.length-1, retValue.length);
   	while (ch == " ") {
	  	retValue = retValue.substring(0, retValue.length-1);
      	ch = retValue.substring(retValue.length-1, retValue.length);
   	}

	//Commented by kavita- 25th feb 2004
	// Note that there are two spaces in the string - look for multiple spaces within the string
	while (retValue.indexOf(" ") != -1)	{
    	retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}

   	return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


/**
*	Function Name:	checkEmail()
*	Description:	Validates email id.
*	In Parameter:	email string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/

function checkEmail(emailStr) {
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address.
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("<?php echo $MESSAGE['INVALID_CHAR_IN_USERNAME']; ?>");
			return false;
   		}	
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("<?php echo $MESSAGE['INVALID_CHAR_IN_DOMAIN_NAME']; ?>");
			return false;
   		}
	}

	// See if "user" is valid
	if (user.match(userPat)==null) {
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address

		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("<?php echo $MESSAGE['INVALID_DESTINATION_ID']; ?>");
				return false;
   			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("<?php echo $MESSAGE['INVALID_DOMAIN_NAME']; ?>");
			return false;
   		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
		//alert("This address is missing a hostname!");
		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}
//  End -->




function verifyIP(ipaddr) {
   var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
   if (re.test(ipaddr)) {
      var parts = ipaddr.split(".");
      if (parseInt(parseFloat(parts[0])) == 0) { return false; }
      for (var i=0; i<parts.length; i++) {
         if (parseInt(parseFloat(parts[i])) > 255) { return false; }
      }
      return true;
   } else {
      return false;
   }
}

/**
*	Function Name:	checkPasswd()
*	Description:	Validates password string. Password should not contain ',','.' and '=' characters.
*	In Parameter:	pwd string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function checkPasswd(pwd) {
	var pattern = /[,:=\s]/;
	if (pwd.match(pattern) == null)	{
		return	true;
	} else {
		return false;
	}
}


/**
*	Function Name:	checkSpace()
*	Description:	checks for white space.
*	In Parameter:	username string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function checkSpace(username) {
	var pattern = /[\s]/;
	if (username.match(pattern) == null) {
		return	true;
	} else	{
		return false;
	}
}

/**
*	Function Name:	checkBookmark()
*	Description:	Validates bookmark string. Bookmark should not contain '?','%','#'.'&' and '=' characters.
*	In Parameter:	bookmark string
*	Out Parameter:	true boolean - if pattern is matched.
*					false boolean - if pattern is not matched.
*/
function checkBookmark(bookmark) {
	var pattern = /[?%#&=]/;
	if (bookmark.match(pattern) == null) {
		return	true;
	} else	{
		return false;
	}
}


function checkCharacters(val) {
	//var pattern = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;
	// removed & and hyphen in the pattern

	var pattern = /[$\\@\\\#%\^\!\*\(\)\[\]\+\_\{\}\`\~\=\|]/;

	if (val.match(pattern) == null)	{
		return	true;
	} else	{
		return false;
	}
}

/**
*	Function Name:	isNumber()
*	Description:	Check for digits.
*	In Parameter:	num string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isNumber(num) {
	var pattern = /^[\d-]+$/;
	if (num.match(pattern) != null)	{
		return	true;
	} else	{
		return false;
	}
}


/**
*	Function Name:	isPhoneNumber()
*	Description:	Check for digits.
*	In Parameter:	num string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isPhoneNumber(num) {
	var pattern = /^[\d\s]+$/;
	if (num.match(pattern) != null)	{
		return	true;
	} else {
		return false;
	}
}

/**
*	Function Name	:	checkName()
*	Description		:	Check for first/last name.
*	In Parameter	:	name string
*	Out Parameter	:	true boolean - if pattern is matched.
*						false boolean - if pattern is not matched.
*/
function checkName(name) {
	var pattern = /^[A-Za-z][A-Za-z-\s]+[A-Za-z]$/;
	if (name.match(pattern) != null) {
		return	true;
	} else {
		return false;
	}
}

function checkSiteName(name) {
	var pattern = /^[A-Za-z][\w\s-.,']*$/;
	if (name.match(pattern) != null) {
		return	true;
	} else {
		return false;
	}
}

/**
*	Function Name	:	checkURL()
*	Description		:	Check for valid URL.
*	In Parameter	:	url string
*	Out Parameter	:	true boolean - if pattern is matched.
*						false boolean - if pattern is not matched.
*/
function checkURL(url) {

	//var pattern = /^(http:\/\/|https:\/\/)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})(:[0-9]{2,4})*)|(([0-9]{1,3}\.){3}([0-9]{1,3}))(:[0-9]{2,4})*)((\/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)$/;
	//Changed - kavita 21st march 05
	//length for top level domain which is {2,3} is removed. Also any characters are allowed in parameters including unicode also..
	//To resolve production bug.

	//	var pattern = /^(http:\/\/|https:\/\/)((([A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})(:[0-9]{2,4})*)|((\d{1,3}\.)(\d{1,3}\.)(\d{1,3}\.)(\d{1,3}))(:\d{2,4})*)((\/|\?)[A-Za-z0-9~#%&'_\+=:\?\.-]*)*)$/;
	 var pattern = /^(http:\/\/|https:\/\/)((([A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})(:[0-9]{2,4})*)|((\d{1,3}\.)(\d{1,3}\.)(\d{1,3}\.)(\d{1,3}))(:\d{2,4})*)((\/|\?)(.)*)*)$/;

	// SBP START 12.30.00 27-09-2006 this is commented to rmove validation for www
	//var pattern = /^(http:\/\/|https:\/\/)((([A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+(\.[A-Za-z]{2,})(:[0-9]{2,4})*)|((\d{1,3}\.)(\d{1,3}\.)(\d{1,3}\.)(\d{1,3}))(:\d{2,4})*)((\/|\?)(.)*)*)$/;
	// SBP END 12.45.00 27-09-2006 

	if (url.match(pattern) != null)	{	
		return	true;
	} else {
		return false;
	}
}

function isBlankString(str) {
	str = trim(str);
	if(str == '' || str.length == 0 || str == '\n')	{
		return true;
	} else {
		return false;
	}
}

function winOpen(strURL, strName, strFlags) {

	//check if a URL has been specified, and return immediately, if it has not been specified
	if (!strURL) {
		alert("<?php echo $MESSAGE['SPECIFY_URL']; ?>");
		return false;
	}

	//variable to hold a valid child window name
	var strChildName;
	//if a name for the child window is not provided, provide a default name
	if (!strName) {
		strChildName = "SiteBuilderChildWin";
	} else {
		strChildName = strName;
	}

	//if window flags have been specified, use them, else don't
	if (strFlags) {
		top.hChildWin = window.open(strURL, strChildName, strFlags);
	} else {
		top.hChildWin = window.open(strURL, strChildName);
	}

	//Focus the window
	top.hChildWin.focus();
	//return the child window handle
	return top.hChildWin;

}


function winModalOpen(strURL, strName, strFlags) {

	//check if a URL has been specified, and return immediately, if it has not been specified
	if (!strURL) {
		alert("<?php echo $MESSAGE['SPECIFY_URL']; ?>");
		return false;
	}
	//variable to hold a valid child window name
	var strChildName;
	//if a name for the child window is not provided, provide a default name
	if (!strName) {
		strChildName = "SiteBuilderChildWin";
	} else {
		strChildName = strName;
	}

	//if window flags have been specified, use them, else don't
	if (strFlags) {
		top.hChildWin = window.showModalDialog(strURL, strChildName, strFlags);
	} else {
		top.hChildWin = window.showModalDialog(strURL, strChildName);
	}
	return top.hChildWin;

}


/**
*	Function Name:	checkExtension()
*	Description:	The respective field is checked for whether its extension is .gif
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtension(fname) {
    var extension;

    extension = fname.substring(fname.lastIndexOf('.'),fname.length)

    if ((extension == ".gif") || (extension == ".jpg") || (extension == ".jpeg")  || (extension == ".png") || (extension == ".GIF") || (extension == ".JPG") || (extension == ".JPEG")  || (extension == ".PNG") ) {
	     return true;
    } else {
        return false;
    }
}


/**
*	Function Name:	checkJPG_PNG()
*	Description:	The respective field is checked for whether its extension is .jpg,.jpeg,.png
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*
*/

function checkJPG_PNG(fname) {
	file = new String(fname);
	var length = file.length;
	var lastindex = file.lastIndexOf("\\");
	if(lastindex == -1) {
		lastindex = file.lastIndexOf("/");
	}
	var ext = file.substring(lastindex, length);
	var filename = new String(ext);
	
	var pattern = /[\w\s]+[\.jpg|\.jpeg|\.png|\.JPG|\.JPEG|\.PNG]$/;
	if(filename.match(pattern) != null) {
		return true;
	} else {
		return false;  
	}
}

/**
*	Function Name:	checkExtensionWithHtml()
*	Description:	The respective field is checked for whether its extension is .html
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtensionWithHtml(extension) {
	//var pattern = /[\w + \.(html)];
	var pattern = /^\w+(\.html|\.htm)$/;
	if (extension.match(pattern) != null) {
		return	true;
	} else {
		return false;
	}
}


/**
*	Function Name:	checkExtensionWithShtml()
*	Description:	The respective field is checked for whether its extension is .shtml
*
*	In Parameter:	String  fname It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtensionWithShtml(fname) {
    var extension;

    extension = fname.substring(fname.lastIndexOf('.'),fname.length)

    if ((extension == ".shtml")) {
	     return true;
    } else {
        return false;
    }
}



/**
*	Function Name:	checkExtensionWithGif()
*	Description:	The respective field is checked for whether its extension is .gif
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtensionWithGif(fname) {
    var extension;

    extension = fname.substring(fname.lastIndexOf('.'),fname.length)

    if ((extension == ".gif")){
	     return true;
    } else {
        return false;
    }
}


/**
*	Function Name:	checkExtensionWithZip()
*	Description:	The respective field is checked for whether its extension is .zip
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtensionWithZip(fname) {
    var extension;

    extension = fname.substring(fname.lastIndexOf('.'),fname.length)

    if ((extension == ".zip")) {
	     return true;
    } else {
        return false;
    }
}

/**
*	Function Name:	doCancel()
*	Description:	On click of Cancel button,it Cancels the changes and
*			either close the window or go back to the mentioned
*			URL.
*	In Parameter:	URL string
*	Out Parameter:	none
*/
function doCancel(strUrl) {	
	// Block of variable declaration and initialization
	var formName = document.forms[0];

	// If action is null then close the window, else submit the form to
	// the mentioned URL.
	if(isBlankString(strUrl)) {
		window.close();
		return false;
	} else {
		// Invoke method to set action for the form
		setAction(formName,strUrl);
	} // end of if..else
}


/**
*	Function Name:	doClose()
*	Description:	On click of Cancel button,it Cancels the changes and
*					either close the window or go back to the mentioned
*					URL.This overloaded function is used from edittable
*					only.If any of the web search engine is added in the
*					table, they have their own form.so form name needs to
*					be passed.				
*	In Parameter:	URL string, form name
*	Out Parameter:	none
*/
function doClose(strUrl,form_name) {

	// Block of variable declaration and initialization
	var formName = eval("document."+form_name);
	// If action is null then close the window, else submit the form to
	// the mentioned URL.
	if(isBlankString(strUrl)) {
		window.close();
		return false;
	} else {
		// Invoke method to set action for the form
		setAction(formName,strUrl);
	} // end of if..else
}

/**
*	Function Name:	doHelp()
*	Description:	On click of Help button,it displays help for active
*			page.
*	In Parameter:	PAGE URL string
*	Out Parameter:	none
*/
function doHelp(page) {
	//Changed by kavita - 21th nov 2003 -build is for client
	winOpen(page,"Help","height=275,width=378,toolbar=no,status=no,menubar=no,scrollbars=yes");
	return false;
}

/**
*	Function Name:	setAction()
*	Description:	set the action of the form to submit.
*	In Parameter:	form object
*		 	action string
*	Out Parameter:	none
*/
function setAction(form,action) {

	// specifying the action for the form
	form.action=action;
}

/**
*	Function Name:	redirectToURL()
*	Description:	redirect the page to given URL.
*	In Parameter: 	action string
*	Out Parameter:	none
*/
function redirectToURL(action) {

	// specifying the action for the form
	location.href=action;
}

function checkCombo(comboName) {
	// Block of variable declaration and initialization
	var objCombo = "document.forms[0]"+"."+comboName+".selectedIndex";
	var i = eval(objCombo);

	if(i== 0) {
		return true;
	} else {
		return false;
	}
}


/**
*	Function Name:	checkMatch(strx,stry)
*	Description:	On click of Submit button,this function check
*			whether both password and confirmed password are equal.
*	In Parameter:	Combo box string
*	Out Parameter:	none
*/

function checkMatch(strx,stry) {
    var str1 = new String();
    var str2 = new String();
    str1 = strx;
    str2 = stry;
    var i=0
    //alert('Value'+str1+','+str2);

    if(str1.length == str2.length) {
        for(i=0;i<str1.length;i++) {
            if(str1.charAt(i) != str2.charAt(i)) {
                break;
            }
        }
        if(i == str1.length) {
             return true;
        } else {
             return false;
        }
   } else {
        return false;
   }
}

/**
*	Function Name:	isMaxString(str)
*	Description:	On click of Done button,this function check the
*                 maximum and minimum limit of text string
*	In Parameter:	Text String,minimum length,maximum length
*	Out Parameter:	none
*/
function isMaxString(str,min,max) {
    str = trim(str);
    if(str.length < min || str.length > max) {
         return true;
    } else {
	return false;
    }
}

function isBeginWithAlpha(str) {
	var pattern = /^[A-Za-z]/;
	if (str.match(pattern) != null)	{
		return	true;
	} else {
		return false;
	}
}

/**
*	Function Name	:	popUp()
*	Description	:	Will display image on pop up window.
*	In Parameter	:	var
*	Out Parameter	:	None
*/

function popUp(imagepath) {

    var path = document.location.href;
    var windowname = 'preview_';
    //  alert((screen.height / 2));
    //  w = window.open(str , windowname, 'width=200,height=250,toolbar=no,status=no,scrollbars=auto,resizable=no' );
    w = window.open("preview.jsp?image=" + imagepath  , windowname, "width=400, height=240,location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes,top = 0,left = 0");
    w.focus();
}



/**
*	Function Name	:	setWindowProperties()
*	Description	:	On load of body this function will set all the properties of
				window such as toolbar,menubar,status,scrollbars and also resize
				the window.
*	In Parameter	:	var windowObject, var Width, var Height, var scrollbars,
				var toolbar, var resizeable, var status, var menubar
*	Out Parameter	:	None
*/
function setWindowProperties(win,winWidth,winHeight,isScrollbars,isToolbar,isResizeable,isStatus,isMenubar) {
	win.resizeTo(winWidth,winHeight);
}


/**
*	Function Name	:	isImageSelected()
*	Description		:	This function validated whether an image has been chosen or not
						by choosing radio button option.
*	In Parameter	:	var rdoimagename
*	Out Parameter	:	None
*/
function isImageSelected(rdoimagename) {
	if(rdoimagename.length > 1) {
		for(i=0;i<rdoimagename.length;i++) {
			if(rdoimagename[i].checked) {
				return true;
			}
		}
	} else {
		if(rdoimagename.checked) {
			return true;
		}
	}
}

/**
*	Function Name	:	checkRadio()
*	Description		:	This function checks the appropriate radio button.
*	In Parameter	:	var radiovalue
*	Out Parameter	:	None
*/
function checkRadio(strRadio) {
	var formName = document.forms[0];
	for(i=0;i<formName.rdolink.length;i++) {
	   	if(formName.rdolink[i].value == strRadio) {
			formName.rdolink[i].checked = true;
		}
	}
}

function verifyIP(ipaddr) {
   var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
   if (re.test(ipaddr)) {
      var parts = ipaddr.split(".");
      if (parseInt(parseFloat(parts[0])) == 0) { return false; }
      for (var i=0; i<parts.length; i++) {
         if (parseInt(parseFloat(parts[i])) > 255) { return false; }
      }
      return true;
   } else {
      return false;
   }
}


/**
*	Function Name	:	checkPercentageMatch()
*	Description	:	This function checks whether the string has "%" or not.
*	In Parameter	:	var radiovalue
*	Out Parameter	:	None
*/

function checkPercentage(fname) {
    var extension;
    if(fname.match("%")) {
    	return true;
    }
} //end of function


/**
*	Function Name	:	setFocus()
*	Description		:	This function sets the focus in the given input field.
*	In Parameter	:	var field
*	Out Parameter	:	None
*/

function setFocus(field) {
	var formName = document.forms[0];
	var objfield = eval("formName."+field);
	objfield.focus();
} //end of function



/**
*	Function Name	:	checkUniqueBookmark(selpage , validbookmark )
*	Description		:	This function checks the validity of the bookmark on a page.
*	In Parameter	:	var selpage  , var  validbookmark
*	Out Parameter	:	Boolean
*/

var validbookmark;
var selpage;
function checkUniqueBookmark(selpage , validbookmark ) {
	var formName = document.forms[0];
	var length = 0;
	var i = 0;
	length = selpage.length;
	for(i =0;i<length;i++) {
		if( selpage[i].value == validbookmark) {
			return false;
		}
	}
	return true;
}


/**
*	Function Name	:	DisableContextMenu()
*	Description		:	This function disables the right click of the mouse.
*	In Parameter	:	None
*	Out Parameter	:	Boolean
*/


function DisableContextMenu() {
	return false;
}


/**
*	Function Name	:	popUpHemeraImage()
*	Description	:	Will display image on pop up window.
*	In Parameter	:	var
*	Out Parameter	:	None
*/

function popUpHemeraImage(imagepath) {
    var path = document.location.href;
    var windowname = 'preview_';
    //  w = window.open(str , windowname, 'width=200,height=250,toolbar=no,status=no,scrollbars=auto,resizable=no' );
    w = window.open("previewhemeraimage.jsp?image=" + imagepath  , windowname, "width=400, height=240,location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes,top = 0,left = 0");
    w.focus();
}


function  checkButton(event) {
	var browser = navigator.appName.substring ( 0, 9 );
	var event_number = 0;
    if (browser=="Microsoft"){
		event_number = event.button;
	} else if (browser=="Netscape") {
		event_number = event.which;
	}

	if (event_number==2 || event_number== 3) {
		alert("<?php echo $MESSAGE['DISABLED_RIGHT_CLICK']; ?>");	
		return false;
	}

	return true;
}



function  checkButtonOn(event) {
	var win = eval("this.window");
	if(win.loaded == false) {
		return false;
	}
	return true;
}
//added by Shweta Pardeshi for Help file configuartions on 28-12-2004


function popHelp(URL) {
	window.open("freepaidhelp.jsp?filename="+escape(URL),"Help"," toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=450");
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=450');");
	return false;
}



function cancelAddPage() {
	var formName = document.forms[0];
	var strUrl = 'canceladdpage.jsp';
	var i=0;
	setAction(formName,strUrl);
	return true;
}

function popupHelp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=450');");
	return false;
}


function checkControlItemName(name) {
	//var pattern = /^[ \w]+$/;
	var pattern = /^[ \w]+$/;
	if (name.match(pattern) == null) {
		return	true;
	} else {
		return false;
	}
}


function checkControlItemLabel(name) {
	//var pattern = /^[ \w]+$/;
	//var pattern = /^[ \"*]+$/;
	var pattern = "\"";
	if (name.match(pattern) == null) {
		return	false;
	} else {
		return true;
	}
}

/**
*	Function Name	:	checkDoubleQuotes(name)
*	Description		:	This function checks the wheather the double Quote is present in the String or not
*	In Parameter	:	val field
*	Out Parameter	:	None
*/

function checkDoubleQuotes(name) {
	//var pattern = /^[ \w]+$/;
	//var pattern = /^[ \"*]+$/;
	var pattern = "\"";
	if (name.match(pattern) == null) {
		return	false;
	} else {
		return true;
	}
}


/**
*	Function Name:	checkReservedWords()
*	Description:	This function checks whether the string contains double quote.
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If reserved is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/


function checkOptions(name) {
	//var pattern = /^[ \w]+$/;
	var pattern = /^[ \w][\w,.]+$/;
	if (name.match(pattern) == null) {
		return	true;
	} else {
		return false;
	}
}


/**
*	Function Name:	checkReservedWords()
*	Description:	The respective field is checked for whether its reserved word or not.
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If reserved is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkReservedWords(reserved) {
    if (   (reserved == "sort")  || (reserved == "redirect") || (reserved == "required") || (reserved == "env_report")  || (reserved == "return_link_url")   || (reserved == "return_link_title")   || (reserved == "background")  || (reserved == "bgcolor")  || (reserved == "text_color")  || (reserved == "link_color")   || (reserved == "vlink_color")   || (reserved == "alink_color")   ) {
		return true;
    } else {
        return false;
    }
}


/**
*	Function Name:	checkOptionSeparator(strx)
*	Description:	The function check whether the option has "," character or not
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If reserved is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/
function  checkOptionSeparator(strx) {
	//alert(strx);
    var str1 = new String();
    var arrOptions;
	str1 = strx;
    var i=0
	if(str1.length > 0) {
		count = 0;
        if(str1.charAt(0) ==  ','   ||  str1.charAt( str1.length - 1 )  == ',' ) {
			alert("<?php echo $MESSAGE['CANNOT_START_OR_END_WITH_COMMA']; ?> ");
			return false;
        }

		for(i=0;i<str1.length;i++) {
			if(str1.charAt(i) ==  ',') {
				count = 1;
				break;
			}
		}
		if( count == 0) {
			alert("<?php echo $MESSAGE['HAS_SEPERATED_WITH_COMMA']; ?> ");
			return false;
		} else {
			return true;
		}
    }
 } // end of 	checkOptionSeparator   



/**
*	Function Name:	checkOptionReservedWords(strx)
*	Description:	The function check whether any reserved word os present in the string.
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If reserved is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function  checkOptionReservedWords(strx) {
    var str1 = new String();
    count = 0;
    var arrOptions;
    str1 = strx;
   
    arrOptions = str1.split(',');
	for(var j = 0 ; j< arrOptions.length ; j++) {
		arrOptions[j] = trim(arrOptions[j]);
		if(checkReservedWords( arrOptions[j] ) ) {
			count = 1
			break;
		}
	}
	
	if(count == 1) {
		return true;
	} else {
		return false;
	}
}




/**
*	Function Name:	checkOptionForEmpty(strx)
*	Description:	The function check the emptyness between the options.
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If reserved is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/



function  checkOptionForEmpty(strx) {
    var str1 = new String();
    count = 0;
    var arrOptions;
    str1 = strx;
    arrOptions = str1.split(',');
	for(var j = 0 ; j< arrOptions.length ; j++) {
		arrOptions[j] = trim(arrOptions[j]);
		if(arrOptions[j].length == 0  ) {
			count = 1
			break;
		}
	}
	
	if(count == 1) {
		return true;
	} else {
		return false;
	}
		
} // end of  checkOptionForEmpty(strx)


/**
*	Function Name	:	checkAsteric(name)
*	Description		:	This function checks the wheather the asteric is present in the String or not
*	In Parameter	:	val field
*	Out Parameter	:	None
*/

function checkStar(name) {
	//var pattern = /^[ \w]+$/;
	//var pattern = /^[ \"*]+$/;
	var star = '*';
	var count = 0;
	for(var i=0;i<name.length ; i++) {
		if(name.charAt(i) == star) {
			count = 1;
			break;
		}
	}
	
	if(count == 1 )	{
		return true;
	} else {
		return false;
	}
} 


/**
*	Function Name	:	checkSpace(name)
*	Description		:	This function checks the wheather the space is present in the String or not
*	In Parameter	:	val field
*	Out Parameter	:	None
*/

function checkSpaceForControlItem(name) {
	//var pattern = /^[ \w]+$/;
	//var pattern = /^[ \"*]+$/;
	var star = ' ';
	var count = 0;
	for(var i=0;i<name.length ; i++) {
		if(name.charAt(i) == star) {
			count = 1;
			break;
		}
	}
	
	if(count == 1 ) {
		return true;
	} else {
		return false;
	}
} 
       
//checkMatch(strx,stry)


/**
*	Function Name	:	checkOptionForEqual(name)
*	Description		:	This function checks the wheather the options aresame.
*	In Parameter	:	val field
*	Out Parameter	:	None
*/

function  checkOptionForEqual(strx) {
    var str1 = new String();
    count = 0;
    var arrOptions;
    str1 = strx;
    arrOptions = str1.split(',');
   if(arrOptions.length > 1) {
		for(var i = 0 ; i< arrOptions.length ; i++) {
			arrOptions[i] = trim(arrOptions[i]);
			if(count == 1) {
				break;
			}
			for(var j = i+1 ; j< arrOptions.length ; j++) {
				arrOptions[j] = trim(arrOptions[j]);
				if( checkMatch( arrOptions[i] , arrOptions[j] ) ) {
					count = 1
					break;
				}
			}
		}

		if(count == 1) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}	
} // end of  checkOptionForEmpty(strx)


//this function checks whether a string contains only alphanumeric characters and hyphen
function checkNavbarTitleString(name) {
	var pattern = /^[\s\w-]+$/;
    if (name.match(pattern) == null) {
		return  false;
	} else {
		return true;
	}
}



function FileNameValidation(name) {
	file = new String(name);
	var length = file.length;
	var lastindex = file.lastIndexOf("\\");
	var lastindex1 = file.lastIndexOf(".");
	if(lastindex == -1){
		lastindex = file.lastIndexOf("/");
	}
	var ext = file.substring(lastindex+1,lastindex1);
	var pattern = /^[\s\w-]+$/;
    if (ext.match(pattern) == null) {
		return false;
	} else {
		return true;
	}
}


/**
*	Function Name	:	checkSpace(name)
*	Description		:	This function checks the wheather the space is present in the 	String or not
*	In Parameter	:	val field
*	Out Parameter	:	None
*/

function checkForCharacter(name , star ) {
	var count = 0;
	for(var i=0;i<name.length ; i++) {
		if(name.charAt(i) == star) {
			count = 1;
			break;
		}
	}
	
	if(count == 1 ) {
		return true;
	} else {
		return false;
	}
} 



/**
*	Function Name	:	 checkEmailAddressList(strx)
*	Description		:	This function checks the validiti for the email address within the email address list.
*	In Parameter	:	val field
*	Out Parameter	:	None
*/


function  checkEmailAddressList(strx) {
    var strEmailAddres = new String();
    count = 0;
    var arrEmailAddressList;
    strEmailAddres = strx;
    arrEmailAddressList = strEmailAddres.split(',');
	for(var j = 0 ; j< arrEmailAddressList.length ; j++) {
		arrEmailAddressList[j] = trim(arrEmailAddressList[j]);
		if(!checkEmail( arrEmailAddressList[j] ) ) {
			count = 1
			break;
		}
	}
	
	if(count == 1) {
		return true;
	} else {
		return false;
	}
}

function checkheightheaderimage(rdoimagename,height) {
	if(rdoimagename.length > 0) {
		for(i=0;i<rdoimagename.length;i++) {
			if(rdoimagename[i].checked) {
				var str= new String();
				str= rdoimagename[i].value;
				var arrimagename = str.split('_');
				if(arrimagename[arrimagename.length-2] < height) {
					return true;
				} else {
					return false;
				}
			}
		}
	}
}




/**
*	Function Name:	checkExtensionWithSWF()
*	Description:	The respective field is checked for whether its extension is .gif
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkExtensionWithSWF(fname) {
    var extension;
    extension = fname.substring(fname.lastIndexOf('.'),fname.length)
    if ( (extension == ".swf") ||  (extension == ".SWF")    ) {
	     return true;
    } else {
        return false;
    }
}

function checkPollOptions(name) {
	var pattern = /^[\w][\s\w,.-]+$/;
	if (name.match(pattern) == null) {
		return	true;
	} else {
		return false;
	}
}


function checkPollTitle(name) {
	var pattern = /^[\s\w?,.-_]+$/;
	if (name.match(pattern) == null) {
		return	false;
	} else {
		return true
	}
}
		

function checkDrivingDirection(name){
	var pattern = /^[\w][\s\w,.-]+$/;
	if (name.match(pattern) == null) {
		return	false;
	} else {
		return true;
	}
}




/**
* function to validate file extenssion 
* this function checks for number of file extension characters if there is no file extension
* it returns false else true 
*/

function isFileValid(file_name) {
	file = new String(file_name);
	var length = file.length;
	var lastindex = file.lastIndexOf("\\");
	if(lastindex == -1) {
		lastindex = file.lastIndexOf("/");
	}
	var ext = file.substring(lastindex, length);
	var extension = new String(ext);
	var lastindex = extension.lastIndexOf(".");
	if( lastindex == -1) {
		return false;
	}
	if(lastindex == 1)		
		return false;
	return true;
}


/**
*	Function Name:	checkSpecialChars()
*	Description:	checks for white space and special chars.
*	In Parameter:	username string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function checkSpecialChars(filename) {
	var pattern = /[^\w-]+/;
	if (filename.match(pattern) == null) {
		return	false;
	} else {
		return true;
	}
}

/**
*	Function Name:	checkDocumnetExtension()
*	Description:	The respective field is checked for whether its extension is of standard document type
					like .txt, .doc, .rtf.
*
*	In Parameter:	String  It represents filename
*	Out Parameter:	true If extension is valid otherwise false.
*
*	@author	:	Sunil B. Javeri
*
*/

function checkDocumentExtension(fname) {
    var extension;
    extension = fname.substring(fname.lastIndexOf('.'),fname.length)
    if ((extension == ".txt") || (extension == ".doc") || (extension == ".rtf")) {
	     return true;
    } else {
        return false;
    }
}


/**
*	Function Name:	validateDateFormat()
*	Description:	This function takes one parameter that is date. It checks for date format of 'mm-dd-yyyy'.
					It also validates month and date range.
*
*	In Parameter:	String  date
*	Out Parameter:	true If date is an valid date.
*
*	@author	:	Sandeep P.
*
*/

function validateDateFormat(date_format) {		 
	if(	date_format =="") {
		return "1";
	}
	var date_array = date_format.split("-");	
	if(date_array.length !=3) {
		return "2";
	}		
	if( (date_array[0].length != 2) | (date_array[1].length != 2) | (date_array[2].length != 4) ){
		return "3";
	}

	if( isNaN(date_array[0]) | isNaN(date_array[1]) | isNaN(date_array[2]) ){
		return "4";
	}
	months = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
	if((date_array[0] > 12) | (date_array[1] > months[eval(date_array[0])]) | (date_array[1] <= 0) | (date_array[2] == 0) ) {
		return "5";
	}
	if((date_array[0]==2) & (date_array[1]>28) & ((date_array[2]%4)!=0))	{
		return "6";
	}
	if(date_format == '00-00-0000'){
		return "7";
	}
	return "ok";
}


/**
*	Function Name:	validatePhoneNumber()
*	Description:	This function takes one parameter that is phone number. It checks for phone number format of '###-###-####'.
*	In Parameter:	String  phone_number
*	Out Parameter:	true If valid phone number.
*
*	@author	:	Sandeep P.
*
*/

function validatePhoneNumber(phone_number) {		 
	if(	phone_number ==""){
		return false;
	}
	if(phone_number == '000-000-0000') {
		return false;
	}
	var phone_number_array = phone_number.split("-");	
	if(phone_number_array.length !=3){
		return false;
	}		
	if( (phone_number_array[0].length != 3) | (phone_number_array[1].length != 3) | (phone_number_array[2].length != 4) ){
		return false;
	}

	if( isNaN(phone_number_array[0]) | isNaN(phone_number_array[1]) | isNaN(phone_number_array[2]) ){
		return false;
	}
	return true;
}




/**
*	Function Name:	isAlphabets()
*	Description:	Check for a-zA-Z.
*	In Parameter:	value string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isAlphabets(value) {
	var pattern = /^[a-z A-Z]+$/;
	if (value.match(pattern) != null) {
		return	true;
	} else {
		return false;
	}
}


/**
*	Function Name:	isAlphaNumeric()
*	Description:	Check for alphanumeric character using space.
*	In Parameter:	value string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isAlphaNumeric(value) {
	var pattern = /^[\s\w]+$/;
	if (value.match(pattern) == null) {
		return	false;
	} else {
		return true;
	}
}




/**
*	Function Name:	arraySearch()
*	Description:	search a particular value in an array and retun index if found or negative value if not found.
*	In Parameter:	needle to be searched, array
*	Out Parameter:	index - if needle found
*			negative number - if needle not found
*/

function arraySearch( searchS, arraySA ) {
	var I = 0;
	var minI = 0;
	var maxI = arraySA.length - 1;
	var s = "";
	var foundB = false;
	I = minI - 1;
	while ( ( I <= maxI ) && ( !( foundB ) ) ) {
		I = I + 1;
		s = arraySA[ I ];
		foundB = ( searchS == s );
	}
	if ( foundB ) {
		return( I );
	} else {
		return( -1000 ); // some negative number indicating not found
	}
}


/**
*	Function Name:	isZipCode()
*	Description:	Check for valid zip code-1.
*	In Parameter:	code string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isZipCode(code) {
	var pattern = /^[\d]+$/;
	if ((code.match(pattern) != null)& (code != 0)) {
		return	true;
	} else {
		return false;
	}
}

/**
*	Function Name:	isZipCodeZip4()
*	Description:	This function takes one parameter that is Zip Code- ZIP+4. It checks for zip code format of '#####-####'.
*	In Parameter:	String  zip_code_zip_4
*	Out Parameter:	true If valid phone number.
*
*	@author	:	Sandeep P.
*
*/

function isZipCodeZip4(zip_code_zip_4) {		 
	if(	zip_code_zip_4 ==""){
	return false;
	}
	var zip_code_zip_4_array = zip_code_zip_4.split("-");	
	if(zip_code_zip_4_array.length !=2){
		return false;
	}		
	if( (zip_code_zip_4_array[0].length != 5) | (zip_code_zip_4_array[1].length != 4) ){
		return false;
	}
	if( isNaN(zip_code_zip_4_array[0]) | isNaN(zip_code_zip_4_array[1]) ){
		return false;
	}
	if( (zip_code_zip_4_array[0]== 0) | (zip_code_zip_4_array[1]== 0) ){
		return false;	
	}
	return true;
}



/**
*	Function Name:	validatePrice(price)
*	Description:	This function takes one parameter that is price. It checks for valid price in xxxxx.xx format.
*	In Parameter:	String  price
*	Out Parameter:	true If valid price.
*
*	@author	:	Sandeep P.
*
*/

function validatePrice(price) {
	var pattern = /^[.\d]+$/;
	if (price.match(pattern) == null) {
			return	true;
	} else {
		var price_array = price.split(".");	
		if(price_array.length > 2) {
			return true;
		}	
		if(	price_array.length == 2) {
			if( price_array[1].length > 2 ){
				return true;
			}
		}
		return false;
	}
}

/**
*	Function Name:	isInteger()
*	Description:	Check for integer.
*	In Parameter:	num string
*	Out Parameter:	true boolean - if pattern is matched.
*			false boolean - if pattern is not matched.
*/
function isInteger(num) {
	var pattern = /^[0-9]+$/;
	if (num.match(pattern) != null)	{
		//alert("Correct");
		return	true;
	} else	{
		//alert("Incorrect");
		return false;
	}
}




/**
*	Function Name:	check()
*	
*/
function check(field) {
        if (checkflag == "false") {
                for (i = 0; i < field.length; i++) {
                        field[i].checked = true;
                }
                // account for one checkbox
                field.checked = true;
                checkflag = "true";
                return "Uncheck All";
        } else {
                for (i = 0; i < field.length; i++) {
                        field[i].checked = false;
                }
                // account for one checkbox
                field.checked = false;
                checkflag = "false";
                return "Check All";
        }
}
