/*****************************************************
Regular expression declartion.
Written By: Ramamohan
Written On: 11/6/2008 3:50 PM
*****************************************************/
_SITEURL_="http://" + window.location.hostname + "/";//Site URL
var whitespace =" \t\n\r ";
var a=0;
var fnameRegxp = /^([a-zA-Z]+)$/;
var lnameRegxp = /^([a-zA-Z]+)$/;
var pcodeRegxp = /^([A-Za-z]{1,2})([0-9]{2,3})([A-Za-z]{2})$/;
var telnoRegxp = /^([0-9]{11})$/;
var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
var urlRegxp =   /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|[a-zA-Z]{2,7})(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$/; 
var dobRegxp =  /^([0-9]){2}(\/|-){1}([0-9]){2}(\/|-)([0-9]){4}$/;
var strFilter = /^[A-Za-zƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f0-9-.,:'?!()_@#$&%;=+]*$/;
/***************** Browser ******************/

var http = null;
var isOpera=navigator.userAgent.indexOf('Opera')>-1;
var isIE=navigator.userAgent.indexOf('MSIE')>1&&!isOpera;
var isMoz=navigator.userAgent.indexOf('Mozilla/5.')==0&&!isOpera;
if(isIE)
	http = new ActiveXObject("Microsoft.XMLHTTP");
else if(isMoz)
	http = new XMLHttpRequest();

var str_msg;

/***************** Browser ******************/
function Browser() {
  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}
var browser = new Browser();
/*****************************************************
Function Name: display
Purpose: To display error messages
Written By: Ramamohan
Written On: 11/6/2008 3:50 PM
*****************************************************/
function display(statement,obj_name){
	switch (statement)
	{
		case "EMPTY_TEXT":
		      statement="- "+obj_name+".";    
			break;
		case "UNSELECTED_COMBOBOX":
			statement="- "+obj_name.substr(0)+".";   
			break;			
		case "INVALID_NUMERIC":
			statement="- Invalid "+obj_name+" ( Only numeric characters ).";   
			break;			
		case "INVALID_NAME":
			statement="- Invalid "+obj_name+".";   
			break;
		case "INVALID_INPUT":
			statement="- Invalid "+obj_name+".";   
			break;
		case "BACKSLASH_DOUBLEQUOTE":
			statement = "Backslash is not allowed in "+obj_name+"."
			break;	
        case "NOT_CHECKED":
            statement = "- "+obj_name+".";
            break;
		case "LESS_NMBR":
            statement = "- "+obj_name+" should be greater than 6 digits.";
            break;
		case "INVALID_PHONE_FAX":
			statement="- Invalid "+obj_name+" ( Only numeric characters with - + ( ) ).";  
			break;
		default:
			statement = "[Error: declaration.js] check the display function.";
            break;		
	}//switch
	return statement+'\n';
}
/*****************************************************
Function Name: jsIsNull
Purpose: To check empty fields
Written By: Ramamohan
Written On: 11/6/2008 4:06 PM
*****************************************************/
function jsIsNull(obj,objname)	{ 
 if (obj.value == "" || obj.value == " ")	{
		output = display('EMPTY_TEXT',objname);
		return output;
	}
}
/*****************************************************
Function Name: IsEmail,isDotExpression
Purpose: To check valid email address
Written By: Ramamohan
Written On: 11/6/2008 4:23 PM
*****************************************************/
function IsEmail(InString) {
	var left, right;
	if(InString.length==0) return(false);
	for(Count=0;Count<InString.length;Count++) {
		TempChar = InString.substring(Count,Count + 1);
		if("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-".indexOf(TempChar,0)==-1) return(false); 
	}
	if(InString.indexOf('@')< 1) return(false);
	if(InString.lastIndexOf('@')!= InString.indexOf('@')) return(false);
	left = InString.substring(0,InString.indexOf('@'));
	right = InString.substring(InString.indexOf('@') + 1,InString.length);
	if((!isDotExpression(left,0))||(!isDotExpression(right,1))) return(false);
	
	return(true);
}
function isDotExpression(InString,NeedsDot) {
	var dots,index,tmpNeedDot;
	dots=0;
	for(index=0;index<InString.length;index++) {
		if(InString.substring(index,index+1)==".") {
		if((index==0)||(index==InString.length-1)) return(false);
			dots ++;
			if(dots>1)tmpNeedDot=1;
			else tmpNeedDot=0;
			if(!isDotExpression(InString.substring(0,index),tmpNeedDot)) return(false);	
		}      
	}
	if((NeedsDot==1)&&(dots<1)) return (false);
	if(InString.length < dots * 2+1) return (false);
	return (true);
}
/********************************************************************************
Function Name: fnLogOut
Purpose: If the user not logged in then this function will take him to login page.
Written By: Ramamohan
Written On: 11/7/2008 11:33 AM
*********************************************************************************/
function fnLogOut(sessid)
{
	var url = _SITEURL_+'admin/ajx_login.php?pg=logout';
	var randomno = parseInt(Math.random()*99999999);  // cache buster
	url=url + "&rand=" + randomno;
	http.open("GET", url, false);
	http.send(null);
	var chval=http.responseText;
	
	if(chval!='')
	{
		document.frmPost.action=_SITEURL_+'admin/';
		document.frmPost.submit();
	}
}
/*****************************************************
Function Name: setAdminMenuActive
Purpose: To set current menu active
Written By: Ramamohan
Written On: 12/24/2008 2:03 PM
*****************************************************/
function setAdminMenuActive(id) {
	document.getElementById(id).className ='current_menu';
}
/*****************************************************
Function Name: fnSetTabWidth
Purpose: To set user side table width
Written By: Ramamohan
Written On: 1/27/2009 5:50 PM
*****************************************************/
function fnSetTabWidth()
{
	var IE = document.all?true:false
	if (!IE)
	{
		document.getElementById('tblChart').style.width='99%';
	}
}
/*****************************************************
Function Name: extractNumber
Purpose: To allow only numeric values
Written By: Ramamohan
Written On: 12/24/2008 2:43 PM
*****************************************************/
function extractNumber(obj, decimalPlaces, allowNegative)
{ if (!obj.readOnly) {
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
       reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
   } else if (decimalPlaces < 0) {
       reg0Str += '\\.?[0-9]*';
   }
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
       var reg3Array = reg3.exec(temp);
       if (reg3Array != null) {
		    // keep only first occurrence of . 
   	    //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
	        var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
	        reg3Right = reg3Right.replace(reg3, '');
	        reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
	        temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
       }
   }
	
	obj.value = temp;
}}
/*****************************************************
Function Name: blockNonNumbers
Purpose: To block non numeric values
Written By: Ramamohan
Written On: 12/24/2008 2:43 PM
*****************************************************/
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{ if (!obj.readOnly) {
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
	
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
		
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}
	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}}

//******************************** Ajax Simple
 
 /***************** Browser ******************/
   var http = null;
   var isOpera=navigator.userAgent.indexOf('Opera')>-1;
   var isIE=navigator.userAgent.indexOf('MSIE')>1&&!isOpera;
   var isMoz=navigator.userAgent.indexOf('Mozilla/5.')==0&&!isOpera;
   if(isIE)
	  http = new ActiveXObject("Microsoft.XMLHTTP");
    else if(isMoz)
	  http = new XMLHttpRequest();
/***************** Browser ******************/

/*****************************************************
Function Name: fnEmlSingleCheck
Purpose: To check each check box
Written By: Ramamohan
Written On: 2/23/2009 12:07 PM
*****************************************************/
function fnEmlSingleCheck(val)
{
//alert(obj.chkRecord.checked);
//return false;
	var obj=document.frmPost;
	flag=0;
	if(obj.chkRecord.length == undefined)
	{
		if(!obj.chkRecord.checked)
			flag=1;
	}
	for(i=0;i<obj.chkRecord.length;i++)
	{
		if(!obj.chkRecord[i].checked)
		{
			flag=1;
			break;
		}
	}
	/*if(flag==0)
	{
		obj.chkCheckAll.checked = true;
	}
	else
	{
		obj.chkCheckAll.checked = false;
	}*/
	if(val.checked==true) {
		if(document.frmPost.hidIds.value=='')
			document.frmPost.hidIds.value=val.value;
		else
			document.frmPost.hidIds.value=document.frmPost.hidIds.value + "," +val.value;
	}else{
		var str="";
		if(document.frmPost.hidIds.value!=''){
			var TempArray = document.frmPost.hidIds.value.split(",");
			for(var i=0;i<TempArray.length;i++){
				if(val.value!=TempArray[i]){
					if(str=="")
						str=TempArray[i];
					else
						str +="," + TempArray[i];
				}
			}
		}
		document.frmPost.hidIds.value=str;
	}
}

/*****************************************************
Function Name: fnSingleCheck
Purpose: To check each check box
Written By: Ramamohan
Written On: 12/25/2008 11:33 AM
*****************************************************/
function fnSingleCheck(val)
{
	var obj=document.frmPost;
	flag=0;
	if(obj.chkRecord.length == undefined)
	{
		if(!obj.chkRecord.checked)
			flag=1;
	}
	for(i=0;i<obj.chkRecord.length;i++)
	{
		if(!obj.chkRecord[i].checked)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
	{
		obj.chkCheckAll.checked = true;
	}
	else
	{
		obj.chkCheckAll.checked = false;
	}
	if(val.checked==true) {
		if(document.frmPost.hidIds.value=='')
			document.frmPost.hidIds.value=val.value;
		else
			document.frmPost.hidIds.value=document.frmPost.hidIds.value + "," +val.value;
	}else{
		var str="";
		if(document.frmPost.hidIds.value!=''){
			var TempArray = document.frmPost.hidIds.value.split(",");
			for(var i=0;i<TempArray.length;i++){
				if(val.value!=TempArray[i]){
					if(str=="")
						str=TempArray[i];
					else
						str +="," + TempArray[i];
				}
			}
		}
		document.frmPost.hidIds.value=str;
	}
}
/*****************************************************
Function Name: fnCheckAll
Purpose: To check all check boxes at once
Written By: Ramamohan
Written On: 12/25/2008 11:50 AM
*****************************************************/
function fnCheckAll(val)
{
  var len=document.frmPost.chkRecord.length;
  var i;
  var str = '';
  if(val.checked==false)
  {
	 if(len>1)
	 {
	   for(i=0;i<len;i++)
	   {
		document.frmPost.chkRecord[i].checked=false;
	   }
	 }
	 else
	  {
	   document.frmPost.chkRecord.checked=false;
	  }
	 document.frmPost.hidIds.value=str;
  }
  else
  {
	 if(len>1)
	 {
		for(i=0;i<len;i++)
		{
		  document.frmPost.chkRecord[i].checked=true;
		  if(str=='')
			str = document.frmPost.chkRecord[i].value;
		  else
			str += "," +  document.frmPost.chkRecord[i].value;
		}
	 }
	 else
	  {
		document.frmPost.chkRecord.checked=true;
		str = document.frmPost.chkRecord.value;
	  }
	  document.frmPost.hidIds.value=str;
  }
}
/*****************************************************
Function Name: jsValidatePhoneFax
Purpose: To valid phone fax numbers
Written By: Ramamohan
Written On: 1/5/2009 10:24 AM
*****************************************************/
function jsValidatePhoneFax(obj,msg)
{
	var objValue=obj.value;
	var characters=" -(.)+1234567890"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = display('INVALID_PHONE_FAX',msg);
		return output;
	}		
	else
		return ;
}
/*****************************************************
Function Name: ShowProgress
Purpose: To show process image with masking parent window.
Written By: Ramamohan
Written On: 1/6/2009 4:25 PM
*****************************************************/
function ShowProgress(fnname)
{
	document.getElementById('hdr').focus();
	var fdiv='progress';
	var fwidth='310';
	var fheight='160';
	var fTop='260';
	document.getElementById('err_msg_list').className="";
	document.getElementById('err_msg_list').innerHTML="";
	var fn=fnname+"()";
	var progres_str="<div class=\"mm h100 progress\"><p class=\"hS5\">&nbsp;</p><div><br/><strong><img src=\""+SITE_URL+"images/admin/animated_processing.gif\"></strong></div></div>";

	var scr_width=screen.width;
	var scr_height=screen.height;
	var thewidth=fwidth;
	var topPos=fTop;
	var leftPos=(scr_width-thewidth)/2;
	var tipobj=document.getElementById("popup_container");
	if (typeof thewidth!="undefined") 
		tipobj.style.width=thewidth + "px";
	
	tipobj.innerHTML=progres_str;
	
	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	
	var popupHeight = document.getElementById('popup_container').offsetHeight; 
	var maskHeight = document.getElementById('thispage').offsetHeight;
	
	if(popupHeight < maskHeight)
	{
	  document.getElementById("maskdiv").style.height = maskHeight + 'px';
	  document.getElementById("selectblocker").style.height = maskHeight + 'px';
	}
	else
	{
	  document.getElementById("maskdiv").style.height = popupHeight + 'px';
	  document.getElementById("selectblocker").style.height = popupHeight + 'px';
	}
	document.getElementById("maskdiv").style.width ="100%";
	document.getElementById("selectblocker").style.width ="100%";
	document.getElementById("maskdiv").style.display = "block";
	tipobj.style.visibility="visible";
	setTimeout(""+fn+"", 1500);
}
/****************************************************************
Function Name: fnHdnPopup
Purpose: To hide process image with remove maski of parent window.
Written By: Ramamohan
Written On: 1/6/2009 4:25 PM
*****************************************************************/
function fnHdnPopup(pdiv)
{
	var contObj=document.getElementById("popup_container");
	if(pdiv!='')
	{
		document.getElementById(pdiv).focus();
	}
	document.getElementById("maskdiv").style.display="none";
	document.getElementById("selectblocker").style.display = "none";
	contObj.style.visibility="hidden";
	contObj.style.width='';
}
/****************************************************************
Function Name: fnHdnfrmPopup
Purpose: To hide poupu and remove mask of parent window.
Written By: Ramamohan
Written On: 2/2/2009 12:34 PM
*****************************************************************/
function fnHdnfrmPopup(pdiv)
{
	var contObj=parent.document.getElementById("popup_container");
	/*if(pdiv!='')
	{
		parent.document.getElementById(pdiv).focus();
	}*/
	parent.document.getElementById("maskdiv").style.display="none";
	parent.document.getElementById("selectblocker").style.display = "none";
	contObj.style.visibility="hidden";
	contObj.style.width='';
}
/****************************************************************
Function Name: jsIsComboUnselected
Purpose: To check combo selected or not.
Written By: Ramamohan
Written On: 1/7/2009 1:52 PM
*****************************************************************/
function jsIsComboUnselected(obj,objname)
{ 
	if (obj.value == "" || obj.value == " " || obj.value == "0" || obj.value == 0 || obj.value == '-1')
	{
		output = display('UNSELECTED_COMBOBOX',objname);
		return output;
	}
}
/****************************************************************
Function Name: fnChkSplChars
Purpose: To check special characters entered or not.
Written By: Ramamohan
Written On: 1/7/2009 2:32 PM
*****************************************************************/
function fnChkSplChars(obj,msg)
{
	var objValue=obj.value;
	var characters=" ~`!@#$%^&*()_+|{}[]:;\"'?.,=-";
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)>=1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = '- Invalid&nbsp;'+msg;
		return output;
	}		
	else
		return ;
}
/****************************************************************
Function Name: isWhitespace
Purpose: To check white spaces.
Written By: Ramamohan
Written On: 1/7/2009 2:33 PM
*****************************************************************/
function isWhitespace(str,msg) 
{
	 reWhiteSpace = new RegExp(/^\s+$/);
	 if (reWhiteSpace.test(str)) 
	 {
		 output = ' - Spaces are not allowed for '+msg+'';
		  return output;
	 }
}
/*****************************************************
Function Name: fnCheckSpacesBeforeAndAfter
Purpose: To Check Spaces Before And After Entered string .
Written By: Firoja
Written On: 2/19/2009 3:33 PM
*****************************************************/
function fnCheckSpacesBeforeAndAfter(title)
{
	var lastcharno	=	title.length - 1;
	if(title.charAt(0)==" " || title.charAt(lastcharno)==" ") {
		return 1;
	}
	else
	{
		return 2;
	}
}
/*****************************************************
Function Name: SelectMoveRows
Purpose: To send options in multi select box.
Written By: Ramamohan
Written On: 1/8/2009 12:28 PM
*****************************************************/
function SelectMoveRows(SS1,SS2)
{
	var a=SS1.options.length - 1;
    var SelID='';
    var SelText='';
	if(SS1.options.length!='0')
	{
		if(SS1.options.selectedIndex == -1)
		{
			alert("Please select atleast one record!");
		}
	}
	else if(SS1.options.length=='0')
	{
		alert("There is no data to transfer!");
	}
	// Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
		
       if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
   SelectSort(SS2);
	
}
/*****************************************************
Function Name: SelectSort
Purpose: To set options in sort.
Written By: Ramamohan
Written On: 1/8/2009 12:28 PM
*****************************************************/
function SelectSort(SelList)
{
	var a=SelList.length;
    var ID='';
    var Text='';
	//alert(SelList.length);
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}
/*****************************************************
Function Name: SelectedBoxList
Purpose: To set selected option ids in hidden field.
Written By: Ramamohan
Written On: 1/8/2009 12:28 PM
*****************************************************/
function SelectedBoxList(selid, setid)
{ 
	var Values = '';   
	var selectBox = document.getElementById(selid).options;  
	for(var i=0; i<selectBox.length; i++)
	{ 
		if(Values=='')
			Values = selectBox[i].value;
		else
			Values += "," + selectBox[i].value; 
	}  
	document.getElementById(setid).value=Values;
	return true;
	//alert(document.getElementById(setid).value);
}
function fnUnderConstruction()
{
	alert("This module/page is under construction. Please visit later!");
	return false;
}
/****************************************************************
Function Name: fnCkSplChars
Purpose: To check special characters entered or not.
Written By: Ramamohan
Written On: 1/9/2009 10:03 AM
*****************************************************************/
function fnCkSplChars(obj,msg)
{
	var objValue=obj.value;
	var characters=" ~`!@#$%^&*_+|{}[]:;\"'?.,=";
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)>=1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = '- Invalid&nbsp;'+msg;
		return output;
	}		
	else
		return ;
}
/*****************************************************
Function Name: showWaitingImage
Purpose: To show waiting image while processing
Written By: Ramamohan
Written On: 11/6/2008 4:33 PM
*****************************************************/
function showWaitingImage(divId) {
	var progres_str="<div class=\"mm h100 progress\"><p class=\"hS5\">&nbsp;</p><div><br/><strong><img src=\""+SITE_URL+"images/admin/animated_processing.gif\"></strong></div></div>";
  	document.getElementById(divId).align ="center";
	document.getElementById(divId).innerHTML = progres_str;
}
/*****************************************************
Function Name: getGridData
Purpose: To fetch grid data using ajax
Written By: Ramamohan
Written On: 12/26/2008 10:50 AM
*****************************************************/
function getGridData(section,page,file)
{
	var frmname="frmPost";
	document.getElementById('page').value=page;
	document.getElementById('section').value=section;
	var chval=new Ajax.Updater(section, file, { parameters: $(frmname).serialize(true), onLoading: showWaitingImage(section),evalScripts: true});	
}
/*****************************************************
Function Name: fnShowResult
Purpose: To fetch grid data with selected values.
Written By: Ramamohan
Written On: 12/26/2008 10:50 AM
*****************************************************/
function fnShowResult(file,grid,frmname)
{
	document.getElementById('page').value=1;
	document.getElementById('section').value=grid;
	var chval=new Ajax.Updater(grid, file, { parameters: $(frmname).serialize(true), onLoading: showWaitingImage( grid ),evalScripts: true});
}
/*****************************************************************************
Function Name: fnGoToPage
Purpose: To show result of exact page number. And also contains validation.
Written By: Ramamohan
Written On: 12/26/2008 10:50 AM
*******************************************************************************/
function fnGoToPage(section,file)
{
	var maxpages=eval(document.getElementById('maxpages').value);
	var pgnumber=eval(document.getElementById('txtpageNo').value);

	if((document.getElementById('txtpageNo').value!='') && (maxpages>0))
	{
		if((pgnumber>maxpages) || (pgnumber=='0'))
		{
			alert("Please enter page number between 1 to "+maxpages+".");
			pgnumber="";
			document.getElementById('txtpageNo').focus();
			return false;
		}
		else
		{
			var page=pgnumber;
			getGridData(section,page,file);
			return false;
		}
	}
	else
	{
		document.getElementById('txtpageNo').focus();
		return false;
	}
}
/*****************************************************
Function Name: fnSetOrder
Purpose: To set order of the colomn
Written By: Ramamohan
Written On: 1/8/2009 2:13 PM
*****************************************************/
function fnSetOrder(ordby,grid,file)
{
	if(document.getElementById('hidOrder').value=="ASC")
		document.getElementById('hidOrder').value="DESC";
	else if(document.getElementById('hidOrder').value=="DESC")
		document.getElementById('hidOrder').value="ASC";
	document.getElementById('hidOrderBy').value=ordby;
	document.getElementById('page').value=document.getElementById('page').value;
	document.getElementById('section').value=grid;
	var chval=new Ajax.Updater(grid, file,{ parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),evalScripts: true});
}
function fnGetType(utype)
{
	var sel_usr_type;
	switch(utype)
	{
		case '1':
			sel_usr_type='LL';
		break;
		case '2':
			sel_usr_type='TT';
		break;
		case '3':
			sel_usr_type='LM';
		break;
		case '4':
			sel_usr_type='ADM';
		break;
	}
	return sel_usr_type;
}
/*****************************************************
Function Name: fnpopulateTo
Purpose: To populate  Textboxes with selected emailid.
Written By: Firoja K
Written On: 2/24/2009 5:16 PM
****************************************************/
function fnpopulateTo(grid,file)
{
	if(document.getElementById('hidIds').value!="")
	{
		var ids=document.getElementById('hidIds').value;
		document.getElementById('txtRecipients').value=ids;
		var usr_type=document.getElementById('uTp').value;
		var Utype=fnGetType(usr_type);
		//var Utype =document.getElementById('uTp').value;
		var url='admin/ajx_send_mail.php?AJAX=true';
		url=url + '&pact=getList&Utype='+Utype;
		var randomno = parseInt(Math.random()*99999999);  // cache buster	
		url=url + "&rand=" + randomno;
		http.open("GET", url, false);
		http.send(null);
		var chval=http.responseText;
		document.getElementById('dynawillgenerate').innerHTML=chval;
		fnHdnPopup('landlord_grid');
	}
	else
	{
		alert(NO_RECS);
		return false;
	}

}

/*****************************************************
Function Name: fnSave
Purpose: To save email notification.
Written By: Firoja K
Written On: 2/19/2009 12:53 PM
****************************************************/
function fnSave(grid,file)
{
	
	if(document.getElementById('hidIds').value!="")
	{
		
		if(confirm(EMAIL_TEMPLATE))
		{
			var chval=new Ajax.Updater(grid, file+'?pgaction=save', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
			if(chval!="")
			{
				if(grid=='email_not_grid_indv')
					fnSetMsg('6');
				else
					fnSetMsg('2');
				document.getElementById(grid).focus();
			}
		}
	}
	else
	{
		if(confirm("Are you sure you want to unsubscribe this notification(s)?"))
		{
			var chval=new Ajax.Updater(grid, file+'?pgaction=save', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
			if(chval!="")
			{
				if(grid=='email_not_grid_indv')
					fnSetMsg('6');
				else
					fnSetMsg('2');
				document.getElementById(grid).focus();
			}
		}
	}
}
/*****************************************************************************
Function Name: fnDelete
Purpose: To delete record confirm validation.
Written By: Ramamohan
Written On: 1/5/2009 10:43 AM
*******************************************************************************/
//fnDelete Button
function fnDelete(grid,file)
{
	if(document.getElementById('hidIds').value!="")
	{
		var id=document.getElementById('hidIds').value;
		if(file=="admin/ajx_Recipe_search.php")
		{
			var flagurl = "admin/chkResStatus.php?recipeid="+id+"&status=inactive"; 
			var myRandom = parseInt(Math.random()*99999999);  // cache buster	
			flagurl=flagurl + "&rand=" + myRandom;
			http.open("GET", flagurl, false);
			http.send(null);			
			var chval=http.responseText;
			//alert(chval);
			//return false;
			if(chval == 0)
			{
				if(confirm(CONFIRM_MSG))
				{
					var chval=new Ajax.Updater(grid, file+'?delaction=delete', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
					if(chval!="")
					{
						fnSetMsg('3');
						document.getElementById(grid).focus();
					}
				}
			}
			if(chval > 0)
			{
				alert(_RECIPE_PRODUCT_DELPART_);
				return false;
			}
		}
		else if(file=="admin/ajx_Restaurants_search.php")
		{
			var flagurl = "admin/chkResStatus.php?restaurantid="+id+"&status=inactive"; 
			var myRandom = parseInt(Math.random()*99999999);  // cache buster	
			flagurl=flagurl + "&rand=" + myRandom;
			http.open("GET", flagurl, false);
			http.send(null);			
			var chval=http.responseText;
			if(chval == 0)
			{
				if(confirm(CONFIRM_MSG))
				{
					var chval=new Ajax.Updater(grid, file+'?delaction=delete', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
					if(chval!="")
					{
						fnSetMsg('3');
						document.getElementById(grid).focus();
					}
				}
			}
			if(chval >= 1)
			{
				alert(_RESTAURANT_CHEF_DELPART_);
				return false;
			}
		}
		else if(file=="admin/ajx_product_search.php")
		{
			var flagurl = "admin/chkResStatus.php?prodid="+id; 
			var myRandom = parseInt(Math.random()*99999999);  // cache buster	
			flagurl=flagurl + "&rand=" + myRandom;
			http.open("GET", flagurl, false);
			http.send(null);			
			var chval=http.responseText;
			if(chval == 0)
			{
				if(confirm(CONFIRM_MSG))
				{
					var chval=new Ajax.Updater(grid, file+'?delaction=delete', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
					if(chval!="")
					{
						fnSetMsg('3');
						document.getElementById(grid).focus();
					}
				}
			}
			if(chval >= 1)
			{
				alert(_PRODUCT_CHEF_DELPART);
				return false;
			}
		}
		else
		{
			if(confirm(CONFIRM_MSG))
			{
				var chval=new Ajax.Updater(grid, file+'?delaction=delete', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
				if(chval!="")
				{
					fnSetMsg('3');
					document.getElementById(grid).focus();
				}
			}
		}
	}
	else
	{
		alert(NO_RECS);
		return false;
	}
}
/*****************************************************************************
Function Name: fnStatus
Purpose: To change status active or inactive.
Written By: Ramamohan
Written On: 1/5/2009 11:27 AM
Updated By: Ramamohan
Updated On: 3/19/2009 8:57 PM
*******************************************************************************/
function fnStatus(grid,file)
{
	if(document.getElementById('hidIds').value!="")
	{
		if(file=="admin/ajx_static_search.php")
		{
			if(confirm(CONFIRM_MSG_STATUS))
			{
				document.getElementById('pgaction').value='status';
				var chval=new Ajax.Updater(grid, file, { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
				if(chval!="")
				{
					fnSetMsg('4');
					document.getElementById(grid).focus();
				}
			}
		}
		else if(file=="admin/ajx_search_desc_mang.php")
		{
			if(confirm(CONFIRM_MSG_STATUS))
			{
				document.getElementById('pgaction').value='status';
				var chval=new Ajax.Updater(grid, file, { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
				if(chval!="")
				{
					fnSetMsg('4');
					document.getElementById(grid).focus();
				}
			}
		}
		else
		{
			if(confirm(CONFIRM_MSG_STATUS))
			{
				var chval=new Ajax.Updater(grid, file+'?pgaction=status', { parameters: $('frmPost').serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
				if(chval!="")
				{
					fnSetMsg('4');
					document.getElementById(grid).focus();
				}
			}
		}
	}
	else
	{
		alert(NO_RECS);
		return false;
	}
}
/*****************************************************
Function Name: fnDispResult
Purpose: To fetch grid data with selected values.
Written By: Ramamohan
Written On: 12/26/2008 10:50 AM
*****************************************************/
function fnDispResult(file,grid,frmname)
{
	document.getElementById('page').value=1;
	document.getElementById('section').value=grid;
	var chval=new Ajax.Updater(grid, file, { parameters: $(frmname).serialize(true), onLoading: showWaitingImage( grid ),	evalScripts: true});
	return 1;
}
/*****************************************************
Function Name: fnfrmDispResult
Purpose: To fetch grid data with selected values.
Written By: Ramamohan
Written On: 2/2/2009 1:32 PM
*****************************************************/
function fnfrmDispResult(file,grid,frmname)
{
	document.getElementById('page').value=1;
	document.getElementById('section').value=grid;
	var chval=new Ajax.Updater(grid, file, { parameters: $(frmname).serialize(true),evalScripts: true});
	return 1;
}
/****************************************************************
Function Name: fnCkAlphabets
Purpose: To check alphabetic characters entered or not.
Written By: Ramamohan
Written On: 1/20/2009 10:34 AM
*****************************************************************/
function fnCkAlphabets(obj,msg)
{
	 reWhiteSpace = new RegExp(/^([a-zA-Z]+)$/);
	 if (!reWhiteSpace.test(obj)) 
	 {
		  output = ' - '+msg+' contains non alphabetic characters.';
		  return output;
	 }
}
/*****************************************************************************
Function Name: fnPopupDiv
Purpose: To show content in a popup.
Written By: Ramamohan
Written On: 1/21/2009 7:54 AM
*******************************************************************************/
function fnPopupDiv(fwidth,fheight,file,pgact,id)
{
	var fTop='90';	
	var scr_width=screen.width;
	var scr_height=screen.height;
	var thewidth=fwidth;
	var topPos=fTop;
	var leftPos=(scr_width-thewidth)/2;
	var tipobj=document.getElementById("popup_container");
	if (typeof thewidth!="undefined") 
		tipobj.style.width=thewidth + "px";
	
	if(id!='')
	{
		if(file=='user/edit_tenant.php')
		{
			var ttids=document.getElementById('hdnTTIds').value;
			var url = _SITEURL_+file+'?AJAX=true&recid='+id+'&pgaction='+pgact+"&allids="+ttids;
		}
		else if(pgact=='home_maintain_view')
		{
			var url = _SITEURL_+file+'?AJAX=true&recid='+id+'&pgaction='+pgact+"&allids="+ttids+'&viewtype=home';
		}
		else if(file=="user/tt_reports.php")
		{
			var seltime=document.getElementById('selTime').value;
			var url = _SITEURL_+file+'?AJAX=true&recid='+id+'&pgaction='+pgact+'&seltimecombo='+seltime;
		}
		/*else if(file=="admin_lm/ll_tt_reports.php")
		{
			var seltime=document.getElementById('selTimeTT').value;
			var url = _SITEURL_+file+'?AJAX=true&recid='+id+'&pgaction='+pgact+'&seltimecombo='+seltime;
		}*/ 
		else
		{
			var url = _SITEURL_+file+'?AJAX=true&recid='+id+'&pgaction='+pgact;
		}
	}
	else
	{
		var url = _SITEURL_+file+'?AJAX=true&pgaction='+pgact;
	}
	var randomno = parseInt(Math.random()*99999999);  // cache buster	
	url=url + "&rand=" + randomno;
	http.open("GET", url, false);
	http.send(null);
	
	var chval=http.responseText;
	
	if(http.readyState=='4')
	{
		tipobj.innerHTML="<div class=\"mm\">"+chval+"</div>";
		if(id!='')
		{
			document.getElementById("recid").value=id;
			document.getElementById("pgaction").value=pgact;
		}
	}
	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	var popupHeight = document.getElementById('popup_container').offsetHeight; 
	var maskHeight = document.getElementById('thispage').offsetHeight;
	if(popupHeight < maskHeight)
	{
	  document.getElementById("maskdiv").style.height = maskHeight + 'px';
	  document.getElementById("selectblocker").style.height = maskHeight + 'px';
	}
	else
	{
	  document.getElementById("maskdiv").style.height = popupHeight + 'px';
	  document.getElementById("selectblocker").style.height = popupHeight + 'px';
	}
	document.getElementById("maskdiv").style.width ="100%";
	document.getElementById("selectblocker").style.width ="98%";
	document.getElementById("maskdiv").style.display = "block";
	document.getElementById("selectblocker").style.display = "block";
	tipobj.style.visibility="visible";
}


/****************************************************************
Function Name: stripHTML
Purpose: To Strip all html from string
Written By: Mahesh
Written On: Wednesday, January 21, 2009
*****************************************************************/
function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++)
   {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>')
		{
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
			  }
			  else
			  {
			 	inTag = false;
				i++;
			   }
		}
        if(!inTag) newString += oldString.charAt(i);
   }
   return newString;
}
function fnSetMsg(msgid)
{
	var Output;
	switch (msgid)
		{
			case "1":
				Output=ADDED_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "2":
				Output=UPDATED_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "3":
				Output=DEL_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "4":
				Output=STATUS_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "5":
				Output=SET_SEQ_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "6":
				Output=UPDATED_SUC;
				document.getElementById('eml_msg_list').className=SUC_MSG_CLS;
				document.getElementById('eml_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "7":
				Output=MAIL_SUC;
				document.getElementById('err_msg_list').className=SUC_MSG_CLS;
				document.getElementById('err_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
		}
}
function fnAccrSetMsg(msgid)
{
	var Output;
	switch (msgid)
		{
			case "1":
				Output=ADDED_SUC;
				document.getElementById('amnt_msg_list').className=SUC_MSG_CLS;
				document.getElementById('amnt_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "2":
				Output=UPDATED_SUC;
				document.getElementById('amnt_msg_list').className=SUC_MSG_CLS;
				document.getElementById('amnt_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "3":
				Output=DEL_SUC;
				document.getElementById('amnt_msg_list').className=SUC_MSG_CLS;
				document.getElementById('amnt_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "4":
				Output=STATUS_SUC;
				document.getElementById('amnt_msg_list').className=SUC_MSG_CLS;
				document.getElementById('amnt_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
			case "5":
				Output=DEL_SUC;
				document.getElementById('mr_msg_list').className=SUC_MSG_CLS;
				document.getElementById('mr_msg_list').innerHTML="<div class=\"pad_left28\">"+Output+"</div>";
				break;
		}
}
/*****************************************************************************
Function Name: fnSetSeqence
Purpose: To set sequence.
Written By: Ramamohan
Written On: 1/22/2009 1:59 PM
*******************************************************************************/
function fnSetSeqence(section,file,frmname)
{
	//alert(section);
	//alert(file);
	//alert(frmname);
	document.frmPost.action='SeqBrands'; 
	document.frmPost.submit();
	/*//document.getElementById('srch').style.display="none";
	//document.getElementById('frtitle').style.display="none";
	//document.getElementById('sequence').innerHTML="<a href=\"FaqSearch\">Search FAQ</a>";
	//document.getElementById('grid_tiltle').innerHTML="Set Sequence";
	//document.getElementById('err_msg_list').className="dispN";
	document.getElementById('section').value=section;
	var chval=new Ajax.Updater(section, file, { parameters: $(frmname).serialize(true), onLoading: showWaitingImage(section),evalScripts: true});
	else
	{
		document.frmPost.pgaction.value='save_prod'; 
	}*/
}
//added by firoja
function fnSetCatSeqence(section,file,frmname)
{
	document.frmPost.action='SeqCategories'; 
	document.frmPost.submit();
}
function fnSetProSeqence(section,file,frmname)
{
	document.frmPost.action='SeqProducts'; 
	document.frmPost.submit();
}
/*****************************************************************************
Function Name: makelist
Purpose: To set sequence id string.
Written By: Ramamohan
Written On: 1/22/2009 5:52 PM
*******************************************************************************/
function makelist()
{
 objlist=document.getElementById('cbmFaq');
 objorderA=document.getElementById('hidorder');
 for(i=0;i<objlist.length;i++)
  {
   if(objorderA.value!='')
     objorderA.value+=","+objlist.options[i].value;
    else
	   objorderA.value=objlist.options[i].value;
  }
  document.getElementById('act').value="update";
  document.getElementById('frmPost').submit();
}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}
function moveOptionDown(obj) {
	//alert(obj.options.length);
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}

function resizeFrame(f) {
	f.style.height = f.contentWindow.document.body.scrollHeight + "px";
}
/*****************************************************************************
Function Name: fnShowPopupDiv
Purpose: To show content in a popup.
Written By: Ramamohan
Written On: 2/2/2009 10:49 AM
*******************************************************************************/
function fnShowPopupDiv(fwidth,fheight,divid,pgact,id)
{
	var fTop='260';	
	var scr_width=screen.width;
	var scr_height=screen.height;
	var thewidth=fwidth;
	var topPos=fTop;
	var leftPos=(scr_width-thewidth)/2;
	var tipobj=parent.document.getElementById("popup_container");
	if (typeof thewidth!="undefined") 
		tipobj.style.width=thewidth + "px";
	//document.getElementById(divid).className="dispB";
	var chval=document.getElementById(divid).innerHTML;
	tipobj.innerHTML="<div class=\"mm\">"+chval+"</div>";
	if(id!='')
	{
		parent.document.getElementById("recid").value=id;
		parent.document.getElementById("pgaction").value=pgact;
	}
	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	var popupHeight = parent.document.getElementById('popup_container').offsetHeight; 
	var maskHeight = parent.document.getElementById('thispage').offsetHeight;
	if(popupHeight < maskHeight)
	{
	  parent.document.getElementById("maskdiv").style.height = maskHeight + 'px';
	  parent.document.getElementById("selectblocker").style.height = maskHeight + 'px';
	}
	else
	{
	  parent.document.getElementById("maskdiv").style.height = popupHeight + 'px';
	  parent.document.getElementById("selectblocker").style.height = popupHeight + 'px';
	}
	parent.document.getElementById("maskdiv").style.width ="100%";
	parent.document.getElementById("selectblocker").style.width ="98%";
	parent.document.getElementById("maskdiv").style.display = "block";
	parent.document.getElementById("selectblocker").style.display = "block";
	tipobj.style.visibility="visible";
}
function getContainerWith(node, tagName) {
// Starting with the given node, find the nearest containing element with the specified tag name and style class.
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName) {return node;}
    node = node.parentNode;
  }
  return node;
}
function acrPopup(event,thetext, thewidth, leftPos, topPos) {
	/************setting up top,left positions as per the screen resolution************/
	var scr_width=screen.width;
	var scr_height=screen.height;
	thewidth=thewidth;
	leftPos=(scr_width-thewidth)/2;
	/**********************************************************************************/
	topPos=260;
	var tipobj=document.getElementById("popup_container");
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth + "px";

	tipobj.innerHTML=document.getElementById('popup_' + thetext).innerHTML;
	
	enabletip=true
	var item, menu, x, y;

	item = (browser.isIE) ? getContainerWith(window.event.srcElement, "A"):event.currentTarget;
	
	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	var popupHeight = document.getElementById('popup_container').offsetHeight; 
	var maskHeight = document.getElementById('thispage').offsetHeight;
	if(popupHeight < maskHeight)
	{
	  document.getElementById("maskdiv").style.height = maskHeight + 'px';
	}
	else
	{
	  document.getElementById("maskdiv").style.height = popupHeight + 'px';
	}
	document.getElementById("maskdiv").style.width ="100%";
	document.getElementById("maskdiv").style.display = "block";
	tipobj.style.visibility="visible";
	//var ttid=document.getElementById('tt_id').value;
	//document.getElementById('tenant_popup').src=_SITEURL_+"admin_lm/tenant_popup.php?ttid="+ttid;
}
function fnUpdate(section,llname,ttid,event,thetext, thewidth, leftPos, topPos)
{
	document.getElementById('tt_section').value=section;
	document.getElementById('tt_llname').value=llname;
	document.getElementById('tt_id').value=ttid;
	acrPopup(event,thetext, thewidth, leftPos, topPos);
}
function fnFrameDiv(fwidth,fheight,divid,file,pgact,id)
{
	var fTop='260';	
	var scr_width=screen.width;
	var scr_height=screen.height;
	var thewidth=fwidth;
	var topPos=fTop;
	var leftPos=(scr_width-thewidth)/2;
	var tipobj=document.getElementById("popup_container");
	if (typeof thewidth!="undefined") 
		tipobj.style.width=thewidth + "px";
	
	var chval=new Ajax.Updater(divid, file, { parameters: $("frmPost").serialize(true), evalScripts: true});

	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	var popupHeight = document.getElementById('popup_container').offsetHeight; 
	var maskHeight = document.getElementById('thispage').offsetHeight;
	if(popupHeight < maskHeight)
	{
	  document.getElementById("maskdiv").style.height = maskHeight + 'px';
	  document.getElementById("selectblocker").style.height = maskHeight + 'px';
	}
	else
	{
	  document.getElementById("maskdiv").style.height = popupHeight + 'px';
	  document.getElementById("selectblocker").style.height = popupHeight + 'px';
	}
	document.getElementById("maskdiv").style.width ="100%";
	document.getElementById("selectblocker").style.width ="98%";
	document.getElementById("maskdiv").style.display = "block";
	document.getElementById("selectblocker").style.display = "block";
	tipobj.style.visibility="visible";
}
function funshowxy(e,objname)
{
	if(document.getElementById('hdnDivName').value!='')
	{
		var dn=document.getElementById('hdnDivName').value;
		document.getElementById("cal_sec_"+dn).innerHTML="";
		document.getElementById("cal_sec_"+dn).style.display="none";
	}
	document.getElementById('hdnDivName').value=objname;
	var IE = document.all?true:false;
	if (!IE) 
		document.captureEvents(Event.CLICK);
	var tempX = 0;
	var tempY = 0;
	if (IE) 
	{
		tempX = parseInt(e.x-50);
		/*scrollPos=parseInt(document.body.parentElement.scrollTop);
		if(scrollPos!=0)
			tempY = e.y+document.body.parentElement.scrollTop;
		else*/
			tempY = e.y;
	}
	else 
	{
		tempX = parseInt(e.pageX-50);
		tempY = e.pageY;
	}
	if(objname=="dtcharg" || objname=="lcb1")
		tempX=tempX-100;
	else
		tempX=tempX;
	ds_sh(document.getElementById(objname),tempX,tempY);
}
//to convert decimal format
function formatNumber(obj)
{
	var num = obj.value;
	var result = num;
	obj.value = result;
}

function fnCheckNull(obj)
{
	if(obj.value=='')
	{
		//alert("Amount should not be empty.");
		obj.value=0;
	}
	else if(obj.value<='0')
	{
		//alert("Amount should be greater than zero.");
		obj.value=0;
	}
}

/*****************************************************
Function Name: jsValidatePhoneFax for userside login
Purpose: To valid phone fax numbers
Written By: Mahesh
Written On: Friday, March 13, 2009 12:30 PM
*****************************************************/
function jsValidatePhoneFax2(obj,msg)
{
	var objValue=obj.value;
	var characters=" -(.)+1234567890"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = " - Invalid Phone Number "+"<br/>";
		output = output + "&nbsp;( Only numeric characters with - +()). ";
		return output;
	}		
	else
		return ;

}


/*****************************************************
Function Name: fnPropPopupDiv
Purpose: popup for  showing property unit details
Added By: Varsha
Written On: 3/16/2009
*****************************************************/

function fnPropPopupDiv(fwidth,fheight,file,pgact,propname,propid)
{
	var fTop='80';	
	var scr_width=screen.width;
	var scr_height=screen.height;
	var thewidth=fwidth;
	var topPos=fTop;
	var leftPos=(scr_width-thewidth)/2;
	var tipobj=document.getElementById("popup_container");
	if (typeof thewidth!="undefined") 
		tipobj.style.width=thewidth + "px";
	if(propname!='')
	{
		var url = _SITEURL_+file+'?AJAX=true&uniname='+encodeURIComponent(propname)+'&propid='+propid+'&pgaction='+pgact;
	}
	else
	{
		var url = _SITEURL_+file+'?AJAX=true&pgaction='+pgact+'&propid='+propid;
	}
	var randomno = parseInt(Math.random()*99999999);  // cache buster	
	http.open("GET", url, false);
	http.send(null);
	var chval=http.responseText;
	if(http.readyState=='4')
	{
		tipobj.innerHTML="<div class=\"mm\">"+chval+"</div>";
		if(propname!='')
		{
			document.getElementById("unitname").value=propname;
			document.getElementById("pgaction").value=pgact;
		}
	}
	if(leftPos >=0 && topPos >=0)
	{
		tipobj.style.left=leftPos+"px";
		tipobj.style.top=topPos + "px";
	}
	var popupHeight = document.getElementById('popup_container').offsetHeight; 
	var maskHeight = document.getElementById('thispage').offsetHeight;
	if(popupHeight < maskHeight)
	{
	  document.getElementById("maskdiv").style.height = maskHeight + 'px';
	  document.getElementById("selectblocker").style.height = maskHeight + 'px';
	}
	else
	{
	  document.getElementById("maskdiv").style.height = popupHeight + 'px';
	  document.getElementById("selectblocker").style.height = popupHeight + 'px';
	}
	document.getElementById("maskdiv").style.width ="100%";
	document.getElementById("selectblocker").style.width ="93%";
	document.getElementById("maskdiv").style.display = "block";
	document.getElementById("selectblocker").style.display = "block";
	tipobj.style.visibility="visible";
}

/*****************************************************
Function Name: isValidDateDiff
Purpose: To compare dates
Written By: Ramamohan
Written On: 3/18/2009 10:30 AM
*****************************************************/
function isValidDateDiff(smalldate,bigdate)
{
	var smalldatearr =smalldate.split("-");
	var bigdatearr   =bigdate.split("-");  	  
	if((parseInt(bigdatearr[2])) > (parseInt(smalldatearr[2],10)))
	 return true;
	else if((parseInt(bigdatearr[2],10)) == (parseInt(smalldatearr[2],10)))
	{
		if((parseInt(bigdatearr[0],10)) > (parseInt(smalldatearr[0],10)))
			  return true;
		else if((parseInt(bigdatearr[0],10)) == (parseInt(smalldatearr[0],10)))
		 {	
		   if((parseInt(bigdatearr[1],10)) > (parseInt(smalldatearr[1],10)))    
					return true;
				else 
					return false;   
		 }
		 else
			 return false;
	}  
	else
		return false;
}
/*****************************************************
Function Name: fnGetNMDate
Purpose: To get next month date
Written By: Ramamohan
Written On: 3/20/2009 12:16 AM
*****************************************************/
function fnGetNMDate(obj)
{
	var strdate=document.getElementById(obj).value;
	if(strdate!='')
	{
		var url = 'admin_lm/ll_manage_lease.php?AJAX=true&pgaction=getDt&stdt='+strdate;
		var randomno = parseInt(Math.random()*99999999);  // cache buster	
		url=url + "&rand=" + randomno;
		http.open("GET", url, false);
		http.send(null);
		var chval=http.responseText;
		if(http.readyState=='4')
		{
			document.getElementById('hdnEndDate').value=chval;
		}
	}
}

//}

/******************************************************************
Function Name: fnChkSplCharsName
Purpose: To check special characters Except(' and space)entered or not.
Written By: Blesy Paul
Written On: 03/23/2009 4:15 PM
*****************************************************************/
function fnChkSplCharsName(obj,msg)
{
	var objValue=obj.value;
	var characters="~`!@#$%^&*()_+|{}[]:;\"?.,=-";
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)>=1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = '- '+msg;
		return output;
	}		
	else
		return ;
}
/******************************************************************
Function Name: jsValidateSSN
Purpose: To check SSN Number.
Written By: Blesy Paul
Written On: 03/23/2009 4:25 PM
*****************************************************************/
function jsValidateSSN(obj,msg)
{
	var objValue=obj.value;
	var characters="1234567890"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = '- '+msg;
		return output;
	}		
	else
		return ;
}
/******************************************************************
Function Name: fnChkZipCode
Purpose: To check ZipCode
Written By: Blesy Paul
Written On: 03/23/2009 4:30 PM
*****************************************************************/
function fnChkZipCode(obj,msg)
{
	var objValue=obj.value;
	var characters="~`!@#$%^&*()_+|{}[]:;\"'?.,=";
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)>=1)
			lTag = 1
	}
	if(lTag == 1)
	{
		output = '- '+msg;
		return output;
	}		
	else
		return ;
}

/******************************************************************
Function Name: fnIfNumber.
Purpose: To check whether digits only
Written By: Varsha P
Written On: 03/23/2009 4:30 PM
*****************************************************************/
function isValidNum(str,objname) 
{
   var reg = (/(^[0-9\)]+)$/);
    if(reg.test(str) == false) 
	 {
		 output = display('INVALID_NUMERIC',objname);
		 return output;
	 }
	else
		return ;
}
function fnGoHome()
{
	document.frmPost.action=_SITEURL_+'admin/manage_menu.php';
	document.frmPost.submit();
}
/*****************************************************
Function Name: fnGetNMDate
Purpose: To get next month date
Written By: Ramamohan
Written On: 3/20/2009 12:16 AM
*****************************************************/
function fnGetNMDate_user(obj)
{
	var strdate=document.getElementById(obj).value;
	if(strdate!='')
	{
		var url = 'user/ll_manage_lease.php?AJAX=true&pgaction=getDt&stdt='+strdate;
		var randomno = parseInt(Math.random()*99999999);  // cache buster	
		url=url + "&rand=" + randomno;
		http.open("GET", url, false);
		http.send(null);
		var chval=http.responseText;
		if(http.readyState=='4')
		{
			document.getElementById('hdnEndDate').value=chval;
		}
	}
}
function fnSetDays(m)
{
	var days;
	var y=document.getElementById('cboYear').value;
	var d=document.getElementById('cboDay').value;
	if(m!='0')
	{
		if (m == '01' || m == '03' || m == '05' || m == '07' || m == '08' || m == '10' || m == '12') 
		{
			days = 31;
		} 
		else if (m == '04' || m == '06' || m == '09' || m == '11') 
		{
			days = 30;
		} 
		else if(m == '02') 
		{
			if(y!=0)
			{
				days = (y % 4 == 0) ? 29 : 28;
			}
			else
			{
				days = 28;
			}
		}
		var url = 'includes/common/ajxcal.php?AJAX=true&days='+days;
		var randomno = parseInt(Math.random()*99999999);  // cache buster	
		url=url + "&rand=" + randomno;
		http.open("GET", url, false);
		http.send(null);
		var chval=http.responseText;
		document.getElementById('days').innerHTML=chval;
		document.getElementById('cboDay').value=d;
	}
}
function fnSetYDays(y)
{
	var days;
	if(y!='0')
	{
		var m=document.getElementById('cboMonth').value;
		var d=document.getElementById('cboDay').value;
		if(m!='0')
		{
			if (m == '01' || m == '03' || m == '05' || m == '07' || m == '08' || m == '10' || m == '12') 
			{
				days = 31;
			} 
			else if (m == '04' || m == '06' || m == '09' || m == '11') 
			{
				days = 30;
			} 
			else if(m == '02') 
			{
				days = (y % 4 == 0) ? 29 : 28;
			}
		}
		else
		{
			days = 31;
		}
		var url = 'includes/common/ajxcal.php?AJAX=true&days='+days;
		var randomno = parseInt(Math.random()*99999999);  // cache buster	
		url=url + "&rand=" + randomno;
		http.open("GET", url, false);
		http.send(null);
		var chval=http.responseText;
		document.getElementById('days').innerHTML=chval;
		document.getElementById('cboDay').value=d;
	}
}
function fnShowImage(Imgurl,img)
{
	var imglink=Imgurl+'uploadimg/'+img;
	window.open(imglink,'','resizable=yes,scrollbars=no,width=500,height=200,left=200,top=200');
}
function fnShowThumbImage(Imgurl,img)
{
	var imglink=Imgurl+'uploadimg/thumb/'+img;
	window.open(imglink,'','resizable=yes,scrollbars=no,width=500,height=200,left=200,top=200');
}
function fndelimage(id)
{ 	
	if(confirm("Are you sure you want to delete this file"))
	{
		document.frmPost.pgaction.value='delete';
		document.frmPost.action="BrandsAdd?bid="+id;
		document.frmPost.submit();
	}
}
function isValidURL(obj) 
{ 
	var v = new RegExp(); 
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+[A-Za-z0-9-_%&\?\/.=]"); 
    if (!v.test(obj))
        return false; 
    else
		return true;
} 
//******************** For Menu 8/21/2009 3:04 PM

function trim(pstrString)
{
  var intLoop=0;
  for(intLoop=0; intLoop<pstrString.length; )
  {
      if(pstrString.charAt(intLoop)==" ")
         pstrString=pstrString.substring(intLoop+1, pstrString.length);
      else
         break;
  }

  for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
  {
      if(pstrString.charAt(intLoop)==" ")
         pstrString=pstrString.substring(0,intLoop);
      else
         break;
  }
  return pstrString;
}
function is_empty(obj, str)
{
  if ( (obj.type=="text") || (obj.type=="password") || (obj.type=="textarea") || (obj.type=="file"))
  {
    
     if(trim(obj.value)=="")
     {
	   alert('Please enter ' + str +'.');
	   obj.focus();
	   return true;
     }
  }
	
  if (obj.type=="select-one")
  {
	  if (obj.selectedIndex==0)
	  {
		  alert('Please select ' + str+ '.' );
		  obj.focus();
		  obj.select;
		  return true;
	  }
  }
  return false;
}
function bMout1(divid, parentmenu) {
	
	//alert(document.getElementById("activemenudiv").value+"  = > "+divid);
	//alert(divid);

	if(document.getElementById(divid)) {
		//alert("test");
		document.getElementById(divid).style.display = "none";
		if(document.getElementById("activemenudiv").value != divid )
			document.getElementById(parentmenu).className = "";

		}

			//document.getElementById(parentmenu).className = "";
	
}


function bMovr1(divid,parentmenu)
{	
	if(document.getElementById(divid))
	{
		var top1 = 0;
		var x1 =0;
	
		var x = getPageOffsetLeft(document.getElementById(parentmenu));

		//if(document.getElementById(divid).offsetParent != null)
			//x1 = document.getElementById(divid).offsetParent.offsetClient;

		if(document.getElementById(parentmenu) && !isNaN(document.getElementById(divid).style.left) && document.getElementById(divid).style.left != '') 
		{
			x1 = parseInt(document.getElementById(divid).style.left, 10);
			top1 = parseInt(document.getElementById(parentmenu).style.top, 10);
		}
		//alert("tst.......");
		var lft = document.getElementById(parentmenu).offsetLeft;
		var tp = document.getElementById(parentmenu).offsetHeight;
		var topHt = parseInt(document.getElementById('header').offsetHeight, 0)

		//document.getElementById(divid).style.top = (topHt + tp + top1) +"px";
		document.getElementById(divid).style.top = "83px";		
		document.getElementById(divid).style.left = (x + x1 + 15) +"px";		
		//document.getElementById(divid).style.left = x +"px";
		document.getElementById(divid).style.display = "block";
		
	}
	document.getElementById(parentmenu).className = "mov";
	//alert(document.getElementById(parentmenu).className);
}

function getPageOffsetLeft(el) {
 var x = el.offsetLeft;
  if (el.offsetParent != null){x += getPageOffsetLeft(el.offsetParent);}
  return x;

}

function dispSubmenu(divid, parentmenu) {

	var lft = document.getElementById(parentmenu).offsetWidth;
	
	if(document.getElementById(divid)) {
		//document.getElementById(divid).style.left = (lft)+"px";
		document.getElementById(divid).style.display = "block";
	}

}

function hideSubmenu(divid) {
	if(document.getElementById(divid))
		document.getElementById(divid).style.display = "none";
}

function CountLeft(field, count, max) 
{ 
	if (field.value.length > max) {
		field.value = field.value.substring(0, max); 
		alert("Description exceeds the length");
	}
	else 
	    count.value = max - field.value.length; 
} 
/******************************************************
Added by Firoja
*******************************************************/
function textarealimit(obj,limit)
{
	
	if(obj.value.length > limit)
	{
		alert("Maximum limit of summary is "+limit);
		
		return true;
	}

}
function getpage(pg)
{	
	document.frmPost.pageno.value=pg;
	document.frmPost.submit();
	//location.href=location.href+"&pageno="+pg;
}

