/**
 *  Javascript class to handle the Help messages.
 *
 *
 */
function Help(instance, msg) {
	this.instance = instance;
	this.container = document.getElementById('window_help');
	this.content = document.getElementById('window_help_text');
	this.default_msg = msg;

	this.set = function (msg) {
		this.content.innerHTML = msg;
		return true;
	}
	this.clear = function () {
		this.content.innerHTML = '';
		return true;
	}
	this.reset = function () {
		this.content.innerHTML = this.default_msg;
		return true;
	}
	
	this.show = function () {
		this.container.style.display = 'block';
		return true;	
	}
	this.hide = function () {
		this.container.style.display = 'none';
		return true;
	}
}

function dropdownPaging(frmObj,module,perform) {// when we select option on dropdown
     
	var q_string = "";
	q_string = "?module="+module+"&perform="+perform;
   
    var page = ""
    page = frmObj.page_no.value;
	
	var s_text			= document.frmSearch.s_text.value;
	var s_type			= document.frmSearch.s_type.value;

    var s_order_field	= document.frmSearch.s_order_field.value;
	var s_order_mode	= document.frmSearch.s_order_mode.value;
	

    if ( s_text != "") {
		q_string += "&s_text="+ s_text;
	}

	if ( s_type != "") 	{
		q_string += "&s_type="+ s_type;
	}
    

	if ( s_order_field != "") {
		q_string += "&s_order_field="+ s_order_field;
	}

	if ( s_order_mode != "") {
		q_string += "&s_order_mode="+ s_order_mode;
	}

 
    if ( s_text != "" || s_type != "" || s_order_field != "" || s_order_mode != "")	{
		q_string += "&btn_filter=1";
	}


	if ( page != "" && page > 0 ) {
		q_string += "&p="+ page;
	}
	else {
		q_string += "&p=1";
	}

	q_string += createQueryString(frmObj);

	location.href = q_string;
	return false;
}


function sortTableField(frmObj,module,perform,sort_by,sort_mode) {// when we select option on dropdown
     
	var q_string = "";
	q_string = "?module="+module+"&perform="+perform;
   
    var page = ""
    page = frmObj.page_num.value;
	
	var s_text			= document.frmSearch.s_text.value;
	var s_type			= document.frmSearch.s_type.value;

    var s_order_field	= document.frmSearch.s_order_field.value;
	var s_order_mode	= document.frmSearch.s_order_mode.value;
 
	//BOF::CHANGE
	var rpp	= document.frmSearch.rpp.value;
	//EOF::CHANGE

    if ( s_text != "") {
		q_string += "&s_text="+ s_text;
	}

	if ( s_type != "") 	{
		q_string += "&s_type="+ s_type;
	}
    

	if ( s_order_field != "") {
		q_string += "&s_order_field="+ sort_by;
	}

	if ( s_order_mode != "") {
		q_string += "&s_order_mode="+ sort_mode;
	}
   //BOF::CHANGE
   if ( rpp != "") {
		q_string += "&rpp="+ rpp;
	}
    //EOF::CHANGE
    if ( s_text != "" || s_type != "" || s_order_field != "" || s_order_mode != "")	{
		q_string += "&btn_filter=1";
	}


	if ( page != "" && page > 0 ) {
		q_string += "&p="+ page;
	}
	else {
		q_string += "&p=1";
	}

	q_string += createQueryString(frmObj);

	location.href = q_string;
	return false;
}


function showForm(module,perform,extra) {// when we select option on dropdown
   
	var q_string = "";
	q_string = "?module="+module+"&perform="+perform;
	
	if(typeof(extra)!= 'undefined'){
		q_string+= extra;	
	}
	location.href = q_string;
	return false;
}

/**
* Function is used to clear the form data.
* 	
*
* @param page	Page Number
*/
function clearFormElement(frmObjEle) {// when we click on paging link

	frmObjEle.s_text.value	=	'';
    frmObjEle.s_type.selectecIndex		=	-1;
	frmObjEle.s_order_field.selectedIndex	=	0;
	frmObjEle.s_order_mode.selectedIndex	=	0;
	frmObjEle.rpp.value	=	'';
    frmObjEle.submit();
}




function confirmMsg(msg) {
	if (!confirm(msg)) {
		return false;
	}
	return true;
}
/**
* Function :: Check value is blank or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateEmptyName(obj) {   
	if( trim(obj.value).length <= 0 )	{
		return false;
	}  
	return true;
}
function validateLength(obj, len) {  
	if( trim(obj.value).length > len )	{
		return false;
	}  
	return true;
}

/**
* Function :: Check value is alpha-numeric or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateAlphabates(obj) {
		
	var objRegExp = /^([a-zA-Z\s]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}

/**
* Function :: Check value is alpha-numeric or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateAlphaNumeric(obj, fieldName) {
		
	var objRegExp = /^([a-zA-Z0-9\s\-]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}


/**
* Function :: Check value is alpha-numeric & - symbol for Product Code
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateAlphaNumericProductCode(obj, fieldName) {
		
	var objRegExp = /^([a-zA-Z0-9\-]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}


/**
* Function :: Check value is alpha-numeric or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateCCOwner(obj, fieldName) {
		
	var objRegExp = /^([a-zA-Z0-9\s\.\&\']+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}

/**
* Function :: Check value is alpha-numeric or not
* @param Obj obj       : Field Object
* Return : True if valid, otherwise false.
*/
function validateAlphaNum(obj) {
		
	var objRegExp = /^([a-zA-Z0-9\s\_]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}
function validatePagename(obj) {
		
	var objRegExp = /^([a-zA-Z0-9-_]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}

function validateTitle(obj) {
		
	var objRegExp = /^([a-zA-Z0-9\_\s\&\-]+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}
/**
* Function :: Check value is integer or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateInteger(obj) {
	var val = obj.value;
	var i;
	/*if (isNaN(obj.value)) {
		return false
	} */
	 for (i = 0; i < val.length; i++)
	  {
		 var c = val.charAt(i);
	
		 if (!isDigit(c)) return false;
	  }

	return true;
}

//Function is used to validate only integer values
function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}
/**
* Function :: Validate the Email Addres
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateEmail(obj) {
	var objRegExp  = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	if (!objRegExp.test(obj.value)) {
		//obj.focus();
		return false;
	}		
	return true;
}
/**
* Function :: Validate the Password
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validatePassword(obj) {
	var objRegExp  = /^([0-9a-zA-Z@!#$%^&+=]){6,32}$/;
	if (!objRegExp.test(obj.value)) {
		//obj.focus();
		return false;
	}		
	return true;
}
/**
* Function to check with given Expression.
*/
function checkRegExp(obj, expression) {
	var objRegExp = expression;
	if ( !objRegExp.test( obj.value ) ) {
	 	return false;
	}else{
	    return true;
	}
	
}
								   

/**
 * Function :: 	Is Used to validated the regular expersion
 */
function checkExp(exp, obj, message) {
	obj.value = trim(obj.value)
			
	if (!exp.exec(obj.value)) {
		alert(message);
		obj.focus();
		return false;
	}		
	return true;
}
/**
 * Function :: 	Is Used to removed the space from left & right side
 * @param str value : Field value
 * Return : Trim Value
 */
function trim(value) {
	
	var exp = /^(\s*)(\S*)(\s*$)/;
	if (exp.test(value)) 
		value = value.replace(exp, '$2');
		
	return value;
}
	
/**
* Function Check Phone Number.
* @param Obj obj       : Field Object
* @param str fieldName : Field Name
*/

function validatePhoneNumber(obj) {
	
	//var objRegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
	//var objRegExp = /^(?:\([0-9]\d{2}\\ ?|[0-9]\d{2}(?:\-?|\?))[0-9]\d{2}[-]?\d{4}$/;
    /*** BOF :: Old Code ***/
	//var objRegExp = /^[0-9]\d{2}-\d{3}-\d{4}$/;
	/*** EOF :: Old Code ***/
	//var objRegExp = /^([0-9\-\(\)\+\s]+)$/;
	
	//var objRegExp = /^[ +]*[(]{0,1}[ +]*[0-9]{3,3}[ +]*[)]{0,1}[-]{0,1}[ +]*[0-9]{3,3}[ +]*[-]{0,1}[]*[0-9]{4,4}[ +]*$/;


	//var objRegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})*$/;

    var objRegExp = /^([0-9\-\(\)\+\s]+)$/; 

	if ( !objRegExp.test(obj.value) ) {
		return false;
	} else {
		return true;	
	}
}

/**
* Function Check Fax Number.
* @param Obj obj       : Field Object
* @param str fieldName : Field Name
*/

function validateFaxNumber(obj) {
	var objRegExp = /^([0-9\-\(\)\+\s]+)$/; //  Original Code
	
	if ( ! objRegExp.test( obj.value ) ) {
		return false;
	} else {
		return true;	
	}
}



/**
* Function Check Fax Number.
* @param Obj obj       : Field Object
* @param str fieldName : Field Name
*/

function validateCouponCodeNumber(obj) {
	var objRegExp = /^([0-9A-Za-z]+)$/; //  Original Code
	
	if ( ! objRegExp.test( obj.value ) ) {
		return false;
	} else {
		return true;	
	}
}


/**
* Function Check USA Zipcode.
* @param Obj obj       : Field Object
* @param str fieldName : Field Name
*/

function validateUSAZip(obj) {
	
	//var objRegExp = /^([0-9]{5})$/;
	var objRegExp = /^([0-9]{5})(-[0-9]{4})?$/i;
	if ( ! objRegExp.test( obj.value ) ) {
		return false;
	} else {
		return true;	
	}
}

function validateCustomerCareNumber(obj) {
	var objRegExp = /^([0-9a-zA-Z\-\'\.\s\&\(\)\+\ ]+)$/;

	if ( !objRegExp.test(obj.value) ) {
		return false;
	} else {
		return true;	
	}
}


function validateDomain(obj, fldName) {
	///^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i
	//return ereg("^(http|ftp|https)://(www\.)?.+\.(com|net|org|co.in|com.au)$", $url);
   //return ereg("^(http|ftp|https)://(www\.)?.+\.([a-z]{2,3})$", $url);
	//var exp = "^(http|ftp|https)://(www\.)?.+\.(com|net|org|co.in|com.au|co.il|co.uk|co.nz|co.za|com.ru|com.ph|dk|edu|gov|il|info|nz|net.nz|org.il|org.nz|org.uk|uk|us)$";	
	var exp = "^((ftp|http|https|FTP|HTTP|HTTPS)?://)"
        + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 199.194.52.184
        + "|" // allows either IP or domain
        + "([0-9a-zA-Z_!~*'()-]+\.)*" // tertiary domain(s)- www.
        + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // second level domain
        + "(com|net|org|co.in|com.au|co.il|co.uk|co.nz|co.za|com.ru|com.ph|dk|edu|gov|il|info|nz|net.nz|org.il|org.nz|org.uk|uk|us|COM|NET|ORG|CO.IN|COM.AU|CO.IL|CO.UK|CO.NZ|CO.ZA|COM.RU|COM.PH|DK|EDU|GOV|IL|INFO|NZ|NET.NZ|ORG.IL|ORG.NZ|ORG.UK|UK|US))" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // port number- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
	var strRegExp = new RegExp(); 
	strRegExp.compile(exp); 
	if (!strRegExp.test(obj.value)) { 
		return false; 
	} 
	return true;
	
}


//** Function to Validate Store Url *//

function validateStoreUrlDomain(obj, fldName) {

	var exp = "^((http|https|HTTP|HTTPS)+://)"
        + "+(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)" // IP- 199.194.52.184 or www 
		+ "|" // allows either IP or domain
		+ "([0-9a-zA-Z_!~*'()-]+\.)*" // tertiary domain(s)- www.
        + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // second level domain
        + "(com|net|biz|org|co.in|com.au|co.il|co.uk|co.nz|co.za|com.ru|com.ph|dk|edu|gov|il|info|nz|net.nz|org.il|org.nz|org.uk|uk|us|COM|NET|BIZ|ORG|CO.IN|COM.AU|CO.IL|CO.UK|CO.NZ|CO.ZA|COM.RU|COM.PH|DK|EDU|GOV|IL|INFO|NZ|NET.NZ|ORG.IL|ORG.NZ|ORG.UK|UK|US))" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // port number- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
		

	var strRegExp = new RegExp(); 
	strRegExp.compile(exp);
	
	if (!strRegExp.test(obj.value)) { 
		return false; 
	}
	return true;
}

/**
 * This function is used to create the query string format of 
 * all the elements that are present within the scope of the 
 * form that has been passed as an argument.
 *
 * @param	form element	The form for which the query string is to be created.
 *
 * @return	querystring		the querystring format of all the elements is retunred back.
 */

function createQueryString(form) {
	
	var query_string = "";
	for (var i = 0; i < form.elements.length; i++) {
		switch (form.elements[i].type) {
			case ("text"): {
				if ( form.elements[i].value != "" ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("password"): {
				if ( form.elements[i].value != "" ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("textarea"): {
				if ( form.elements[i].value != "" ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("hidden"): {
				if ( form.elements[i].value != "" ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("checkbox"): {
				if ( form.elements[i].checked ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("select-one"): {
				query_string += "&"+ form.elements[i].name 
									+"="+ encode(form.elements[i].options[form.elements[i].selectedIndex].value);
				break;
			}
			case ("select-multiple"): {
				s_options = "";
				for ( j=0; j < form.elements[i].length; j++ ) {
					if ( form.elements[i].options[j].selected ) {
						s_options += ","+ encode(form.elements[i].options[j].value);
					}
				}
				if (s_options != "") {
					s_options = s_options.substr(1);
					query_string += "&"+ form.elements[i].name +"="+ s_options;
				}
				break;
			}
			case ("radio"): {
				if ( form.elements[i].checked ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
			case ("submit"): {
				if ( form.elements[i].value != "" ) {
					query_string += "&"+ form.elements[i].name +"="+ encode(form.elements[i].value);
				}
				break;
			}
		}
	}
	return (query_string);
}
function encode(string) {
	return string.replace(/&/g, '%26');
}
/**
* Function :: Check at least one value
* @param Obj element   : Field Object
* Return : True if valid, otherwise false.
*/
function selectOnlyOne( element ) {
	var el = document.getElementsByName(element.name) ;
	for( i=0; i<el.length; i++ ){
		if ( el[i].value != element.value ) {
			el[i].checked = false;
		}
	}	
}
/**
* Function :: Check checkbox select or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateCheckbox(obj, fldName) {
	
	if(obj.checked == 1) {
		return true;
	} else { 
		return false;
	}
}
/**
* Function :: Check radio select or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function validateRadio(obj, fldName) {
	var cnt = -1;
	for (var i=obj.length-1; i > -1; i--) {
		if (obj[i].checked) {cnt = i; i = -1;}
	}
	if (cnt > -1) {
		return true;
	}
	else{
		return false;
	}
}

/**
* Function :: Check radio select or not
* @param Obj obj       : Field Object
* @param str fldName   : Field Name
* Return : True if valid, otherwise false.
*/
function getRadioValue(obj) 
{
	var cnt = -1;
	try{
		for (var i=obj.length-1; i > -1; i--) {
			if (obj[i].checked) 
			{
				return obj[i].value;
				break;
			}
		}
	}
	catch(e){}
}

    /**
	 * Function :: Check all
	 * @param Obj element   : Main check box object
	 * @param Obj element   : Sub check box object
	 * Return : 
	 */
	 
	function checkAll(main_chk, sub_chk)
	{
		
		if(typeof(sub_chk) != 'undefined'){
			if(sub_chk.length > 0){
				for (i = 0; i < sub_chk.length; i++)
				{
					sub_chk[i].checked = main_chk.checked;
					
				}
			}
			else if(main_chk.checked == true || main_chk.checked == false){
				sub_chk.checked = main_chk.checked;
			}
		}
		
	}
	 
    /**
	 * Function :: Un Check
	 * @param Obj element   : Main check box object
	 * @param Obj element   : Sub check box object
	 * Return : 
	 */
	function unCheck(main_chk, sub_chk)
	{
		
		if(sub_chk.length > 0){
			for (i = 0; i < sub_chk.length; i++)
			{
				if(sub_chk[i].checked == true){
					main_chk.checked = true;
				}
				else{
					main_chk.checked = false;
					break;
				}
			}
			
		}
		else{
			if(sub_chk.checked == true){
				main_chk.checked = true;
			}
			else{
				main_chk.checked = false;
			}
		}
	}
	/* EOf */
	
	/**
	 * Function :: Checked selcet check box if all sub check boxes are selected.
	 * @param Obj element   : All contact selected ids - Array
	 * @param Obj element   : contact ids for that page - Array
	 * Return :
	 */
	function checkSelectAll(arr_selected ,arr_form){
	  		 
		if( (arr_selected.length >0)  && (arr_form.length>0)){
			arr_selected = arr_selected.toString();
			if(arr_form.length >0) {
				var count = 0;
				for(i= 0; i<arr_form.length; i++){
					index = arr_selected.indexOf(arr_form[i]);
					if(index != -1){
					 count++;
					}
				}
			 }
			 
			if(count == arr_form.length){
				document.getElementById('chk_select_all').checked = true;
			}else{
				document.getElementById('chk_select_all').checked = false;
			}
		}
		
	}
	
	/**
	 * Function  :: Check at least one chechbox is selected.
	 * @param Obj element   : Field Object
	 * Return               : True if valid, otherwise false.
	 */
	 function isSelectAnyOne( element ) {
		
		if(element.length>0){
			for( i=0; i<element.length; i++ ){
				if ( element[i].checked == true ) {
					return true;
				}
			}
		}
		else if ( element.checked == true ) {
			return true;
		}
		return false;
	 }

/**
	 * Function :: Show/hide the background
	 * @param id element   : div id
	 * Return : True.
	 */

function divShowHide(divId) {
	var id = divId ? divId : 'trans';
	var divId = document.getElementById(id);
	var styles = divId.style;
	if( styles.display == 'block' ) {
		styles.display = 'none';
	} else {
		styles.display = 'block';
		styles.height = window.screen.height+'px';
	}
	return true;
}

function selectTexr(frmObj){
	if (frmObj.value == 'Username' || frmObj.value == 'Password' ) {
     frmObj.focus();
     frmObj.select();
	// frmObj.value ='';
    }
}

  /** Function to prevent the text from copy and paste.
   * @param evt obj       : Field Object
   * @return 			 : false if pressing copy paste
   */
	function disableCtrlModifer(evt)
	{
		var disabled = {a:0, c:0, x:0, v:0};
		var ctrlMod = (window.event)? window.event.ctrlKey : evt.ctrlKey;
		var key = (window.event)? window.event.keyCode : evt.which;
		key = String.fromCharCode(key).toLowerCase();
		return (ctrlMod && (key in disabled))? false : true;
	}

function clearTextUsername(frmObj) {
	var username = frmObj.username;
	if ( username.value == 'Username' ) {
		username.value = '';
	}
}
function clearTextPassword(frmObj) {
	var password = frmObj.password;
	if ( password.value == 'Password' ) {
		password.value = "";
	}
}

function testPassword(passwd) {
	var password = {
						verdects:["Very weak","Weak","Medium","Strong","Very strong"],
						colors:["#AAAAAA","#CCFF00","#FF9933","#339933","#110A9A"],
						scores:[0,10,20,30,40,50],
						min_length:6
					}
	//new_value = checkPassword(passwd, password);
	var pm = new PasswordMeter(password);
	new_value = pm.check(passwd);

	//alert(new_value.verdect+' '+new_value.color+' '+new_value.score+' '+new_value.perge);
	//09&SU9s&S((S*S&^S&sDDS%$*&SD

	var password_meter = document.getElementById("strength_meter");
	password_meter.style.backgroundColor = new_value.color;
	password_meter.style.width = new_value.perge;
	
	var password_text = document.getElementById("strength_text");
	password_text.style.color = new_value.color;
	password_text.innerHTML = new_value.verdect;
}



//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
	if (event.button==2){
		//alert(message);
		return false;
	}
}

function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			//alert(message);
			return false;
		}
	}
}

function disableRightClick() {
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	document.oncontextmenu=new Function("return false")
}

function enableRightClick() {
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
	}
	else if (document.all&&!document.getElementById){
	}
	document.oncontextmenu=new Function("return true")
}


function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

function disableEnterKey() {
	document.onkeypress = stopRKey;
}

function enableRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  return true;
}

function enableEnterKey() {
	document.onkeypress = enableRKey;
}


	

/**
* Function Check USA Zipcode.
* @param Obj obj       : Field Object
* @param str fieldName : Field Name
*/

function validateZip(obj) {
	
	//var objRegExp = /^([0-9]+)$/;
	
	//var objRegExp = /^([0-9]{5})(-[0-9]{4})?$/i;    // Original Code
    
	var objRegExp = /^([0-9a-zA-Z\-\s\&\(\)\+\ ]+)$/; // Working Code


	if ( ! objRegExp.test( obj.value ) ) {
		return false;
	} else {
		return true;	
	}
}

function toggle ( target )
   {
     if (document.getElementById)
     {
         target = document.getElementById( target );
         
         if (target.style.display == "none")
         {
            target.style.display    = "";
         }
         else
         {
            target.style.display    = "none";
         }
      }
   }
   
   
  /**
   * Function :: Check at least one value
   * @param Obj element   : Field Object
   * Return : True if valid, otherwise false.
   */
	function isSelectedAnyOne( element ) {
	
	if(element.length>0){
		for( i=0; i<element.length; i++ ){
			if ( element[i].selected == true ) {
				return true;
			}
		}
	}
	else if ( element.selected == true ) {
		return true;
	}
	return false;
	}
 
	/** 
	* Function Check Interger
	* @Author              :  Rupali khobragade (Not used IsNaN() function here becoz IsNaN() function returns false for fractional values ex. 1.0)
	* @param Obj obj       :  Field Object
	* @param str fieldName :  Field Name
	* @return :True if valid, otherwise false
	*/

	function validateIntergerNum(obj) {
		
		var objRegExp = /^([0-9]+)$/;
		if ( ! objRegExp.test( obj.value ) ) {
			return false;
		} else {
			return true;	
		}
	}

	/**
	* Function for search module of rpp - only allows numeric values.
	* @param e obj  : Field Object.
	* @return       : True for specific key entered by user, otherwise false.
	*/

	function onlyNumerics(e){
		var e = e? e : window.event;
		
		if (!e) 
			return;
		
		var key = 0;
		if (e.keyCode) { 
			key = e.keyCode; 
		} // for moz/fb, if keycode==0 use 'which'
		else if (typeof(e.which)!= 'undefined') { 
			key = e.which; 
		} 
		
		if ( (key>=48 && key<=57)|| key==8 || key==13 || key==0 || key==9 || key==46 || key==37 || key==39){
			return (true) ;
		}
		else{
		//	alert( "Please enter a valid password.  No spaces, more than six characters and contain 0-9");
			return (false);	
		}
	}

	/**
	* Function for search module of rpp - only allows numeric values without decimal point in profit percent.
	* @param e obj  : Field Object.
	* @return       : True for specific key entered by user, otherwise false.
	*/

	function onlyNumericsForProfit(e){
		var e = e? e : window.event;
		
		if (!e) 
			return;
		
		var key = 0;
		if (e.keyCode) { 
			key = e.keyCode; 
		} // for moz/fb, if keycode==0 use 'which'
		else if (typeof(e.which)!= 'undefined') { 
			key = e.which; 
		} 
		
		if ( (key>=48 && key<=57)|| key==8 || key==13 || key==0 || key==9 || key==37 || key==39 ){
			return (true) ;
		}
		else{
		//	alert( "Please enter a valid password.  No spaces, more than six characters and contain 0-9");
			return (false);	
		}
	}



 /**
 * Function :: To check the type of file(.bm,.gif,.jpg,.jpeg)
 * @param Obj element   : Field Object
 * Return : True if valid, otherwise false.
 */
function validateFileExtension(fld) {
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(fld.value)) {
		return false;
	}
	return true;
}

/**
* Function to show static list Pop up when 
* static page link type is selected.
* 
*/
function showSecurityMessage() {	
	//divShowHide('trans');
	document.getElementById('myframe').style.display ='block';
	document.getElementById('show').style.display ='block';
	return false;	
}

/**
* Function to Close static list Pop up
* 
*/
function divSecurityClose()
{
	document.getElementById('show').style.display ='none';
	document.getElementById('myframe').style.display ='none';
	return false;
}

function closeSecurityMessage(frmObj) {
	
	var action = frmObj.show_again;
	if( typeof(action) != "undefined" ) {
		if(isSelectAnyOne(action)) {
			UpdateSecurityMessageStatus();
		} else {
			divSecurityClose();
		}
	} else {
		divSecurityClose();
	}
}

function UpdateSecurityMessageStatus() {
	var q_string 	= '';
	if ( !requestPOST("security-message-status.php", q_string, requestSecurityMessageStatus) ) {
		alert("cannot connect to the server");
	}	
	
}

function requestSecurityMessageStatus() {
	if ( objXmlHttp.readyState == 4	|| objXmlHttp.readyState == "complete" ) {
		if ( objXmlHttp.status == 200 ) {
			document.getElementById('frm_security').submit();
		} else {
			// Invalid response from the server, do nothing.	
		}
	} else {		
	}
}

function validateLoginForm( frmObj ){
	
	var username    	= frmObj.username;
	var password  	    = frmObj.password;
	var msg_err = '';
	
	if( typeof(username) != "undefined" ) {
		if(msg_err == ''){
			username.focus();
		}
		if( !validateEmail(username) )	{
			msg_err = msg_err + 'Enter valid Username.' + '\n';
		}
	}
	if( typeof(password) != "undefined" ) {
		if(msg_err == ''){
			password.focus();
		}
		if( !validatePassword(password) )	{
			msg_err = msg_err + 'Enter valid 6-12 character long Password.' + '\n';
		}
		
	}
	if ( msg_err.length > 0 ) {
		alert(msg_err);
		return false;
	}
	return true;
}

function validateName(obj) {
		
	var objRegExp = /^([a-zA-Z0-9\.\s\&\-\']+)$/;
	if ( ! objRegExp.test( obj.value ) ) {			
		return false;
	} 
	return true;
}
/**
* Function to valiadate URl of Menu Items ie. http://www.examples.com (Complete Path)
* @param obj Object 
* 
*/
function validateDomainExt(obj, fldName) {
	///^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i
	//return ereg("^(http|ftp|https)://(www\.)?.+\.(com|net|org|co.in|com.au)$", $url);
	//return ereg("^(http|ftp|https)://(www\.)?.+\.([a-z]{2,3})$", $url);
	//var exp = "^(http|ftp|https)://(www\.)?.+\.(com|net|org|co.in|com.au|co.il|co.uk|co.nz|co.za|com.ru|com.ph|dk|edu|gov|il|info|nz|net.nz|org.il|org.nz|org.uk|uk|us)$";
	/*var exp = "^((ftp|http|https|FTP|HTTP|HTTPS)?://)"
	+ "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@
	+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 199.194.52.184
	+ "|" // allows either IP or domain
	+ "([0-9a-zA-Z_!~*'()-]+\.)*" // tertiary domain(s)- www.
	+ "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // second level domain
	+ "(com|net|org|co.in|com.au|co.il|co.uk|co.nz|co.za|com.ru|com.ph|dk|edu|gov|il|info|nz|net.nz|org.il|org.nz|org.uk|uk|us|COM|NET|ORG|CO.IN|COM.AU|CO.IL|CO.UK|CO.NZ|CO.ZA|COM.RU|COM.PH|DK|EDU|GOV|IL|INFO|NZ|NET.NZ|ORG.IL|ORG.NZ|ORG.UK|UK|US))" // first level domain- .com or .museum
	+ "(:[0-9]{1,4})?" // port number- :80
	+ "((/?)|" // a slash isn't required if there is no file name
	+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; */
	//var exp = "^(http:\/\/|https:\/\/|ftp:\/\/){1}([0-9A-Za-z_!~*'().&=+$%-]+\.)";

	var exp = /^((http|https):\/\/)(www\.)?([a-zA-Z0-9_-]+)(\.)([a-zA-Z0-9_-]+)$/;
	var strRegExp = new RegExp();
	strRegExp.compile(exp);
	if (!strRegExp.test(obj.value)) {
	return false;
	}
	return true;
}
function popup(url) 
{
 params  = 'width=800';
 params += ', height=600';
 params += ', top=50, left=50'
  params += ', scrollbars=yes, resizable=yes'
 params += ', fullscreen=no';

 newwin=window.open(url,'Newsletters', params);
 if (window.focus) {newwin.focus()}
 return false;
}

// Function to round values of price
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

