MANDATORY=1;
NONMANDATORY=0;
NUMERIC=2;
EMAIL=3;
TEXT=4;
FLOAT=5;
DATE=6;
FILE=7;
COMBO=8;
LSTBOX= 17;
CHKVAL=9;
BLANK_FILTER="";
INTEGER= 12;
DATETIME=19;
TIME=20;
PHONE = 25;
CUSTOM = 18;
var invalidMessage=" is invalid";
var numericMessage=" should be Numeric";
var integerMessage = " should be Integer";



function isEmpty(s)
{  
   s=trim(s);
   return ((s == null) || (s.length == 0))
}

function AddError(strErrorList, strErrorMsg)
 {
	strErrorMsg = trim(strErrorMsg);
	
	if (strErrorMsg.length != 0)
	{
		strErrorList = strErrorList + "<li>" + strErrorMsg + "</li>" ;
	}
	
	return strErrorList;
 }
 
function trim( str1 )
{
	string = new String (str1);
	string = string.replace(regexp1, "");
	return string.replace(regexp2, "");
}


function check(element,label,mandatory,type,MAXLENGTH,MINLENGTH,element2,ShowCustomMsg)
{

	var field = eval("document.forms[0]." + element) ;
	field.value=trim(field.value);
	
	//check for INSERT VALUE LENGTH
	if(mandatory==CHKVAL)
    {

        if (isFinite(field.value))
        {
	        if (field.value>99999) 
	        {
		        return "Please Enter " + label + " Less Than 99999."+"\n";
	        }
	        else if (field.value < 0) 
	        {
		        return "Enter valid data in " + label +".\n";
	        }
        }	 
    }
	   
	//check for MANDATORY
    if(mandatory==MANDATORY)
    {
        if(isEmpty(field.value))
        {
		    if(ShowCustomMsg == 1)
		    {
		        return label;
		    }
		    else
		    {
		        return label + " is mandatory."+"\n";
		    }
        }
    }

	  //check for MAXLENGTH
	  if(MAXLENGTH!=-1)
	  {
		  if(trim(field.value).length>MAXLENGTH)
		   {
			 return label+" exceeds the limit of "+MAXLENGTH+"  characters.\n";
			}
		}
	  //check for content
	  if(type==TEXT)
	  {
			var controlValue = field.value;
			var iChars = "34,60,62,338,339,8364,124"; //"\"<>€œŒ";
				for (i = 0; i < iChars.split(",").length; i++)  
				{
					if (controlValue.indexOf(String.fromCharCode(iChars.split(",")[i])) != -1) 
					{
					return "Some special characters  like " + String.fromCharCode(34,44,32,60,44,32,62,44,32,124,44,32,338,44,32,339)+" and "+String.fromCharCode(8364) + " are not allowed  in "+ label +".\n";
					}
				}
	  }
	  
      if(type==EMAIL)
	  {
		if(!isEmpty(field.value))
		{
				if(!isEmail(field.value))
					return label+" "+invalidMessage+".\n";
		}
	  }
	  
	 
	  if(type==INTEGER)
	  {
		  if(!isEmpty(field.value))
		   {
			  if(!isInteger(field.value))
			  return label+" " + integerMessage + ".\n";
			} 
	  }
	  
	  if(type==NUMERIC)
	  {
		  if(!isEmpty(field.value))
		   {
			  if(!isNumeric(field.value))
			  return label+" "+numericMessage+".\n";
			} 
	  }

	  
	  
	  if(type==FLOAT)
	  {
		  if(!isEmpty(field.value))
		   {
			  if(isNaN(field.value))
			  return label+" "+invalidMessage+".\n";
			} 
	  }


	  if(type==DATE)
	  {
		  if(!isEmpty(field.value))
		   {
			   if(checkDateFormat(field.value)==false)
				{
				        return label+" "+invalidMessage+".\n";
				  }
			 }
	    }
        if(type==TIME)
	    {
            if(!isEmpty(field.value))
            {
                if(!checkTimeFormat(field.value))
                {
                    return label+" "+invalidMessage+".\n";
                }
            }
        }
//	  //CIMII:validtes for datetime
        if(type==DATETIME)
	    {
		    if(!isEmpty(field.value))
		    {
		
		        var strDatetime =field.value;
                var strDatePart=strDatetime.substr(0, (strDatetime.indexOf(':')-3));  
                strDatetime=strDatetime.substr((strDatetime.indexOf(':')-3), strDatetime.length);
                strError= checkDate(trim(strDatePart),"Date and Time")
                if (strError=="")
                {
                    strError=IsValidTime(trim(strDatetime)) 
                }
                if(strError!="")
                    strError = "Invalid date time.please enter " + label +" as mm/dd/yyyy hh:mm"; 
                return strError;
			  
		    }
	    }
	 
	 if(type==LSTBOX)
	  {
	  if(field.selectedValue == "")
		   {
			return label+" is mandatory."+"\n";
		   }
	  }

    if(type==COMBO)
	{
	    if(field.selectedIndex == 0)
        {
            if(ShowCustomMsg==1)
                return label;
            else
                return label+" is mandatory."+"\n";
        }
    }
	  
	 
	
	  //in case every thing went well
    return "";

 }
function isEmail (s)
{   
     //========================= check special characters in Email : by krishan dated:21st May 2009
     var controlValue = s;
		var iChars = "34,60,62,338,339,8364,124"; //"\"<>€œŒ";
			for (i = 0; i < iChars.split(",").length; i++)  
			{
				if (controlValue.indexOf(String.fromCharCode(iChars.split(",")[i])) != -1) 
				{
				    return false;
				//return "Some special characters  like " + String.fromCharCode(34,44,42,44,32,60,44,32,62,44,32,124,44,32,338,44,32,339)+" and "+String.fromCharCode(8364) + " are not allowed  in Primary Contact Email.\n";
				}
		    }
	//=========================  End =====================================================
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
/*********************************************************************
Description				: This function used to check Integer value or Not
Author					: 
Creation Date			: April 4, 2005
Last Modified By		: 
Last Modified Date		:	 
Parameters				: object value
Return values			: True/False
Modification Comments	: 
*********************************************************************/
function isInteger (s)

{   var i;
	     
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

/*********************************************************************
Description				: This function used to check any digit value
Author					: 
Creation Date			: April 5, 2005
Last Modified By		: 
Last Modified Date		:	 
Parameters				: object value
Return values			: 
Modification Comments	: 
*********************************************************************/
function isDigit (c)
{  
 return ((c >= "0") && (c <= "9"))
}

/*********************************************************************
Description				: This function used to Trim the value
Author					: 
Creation Date			: April 5, 2005
Last Modified By		: 
Last Modified Date		:	 
Parameters				: object value
Return values			: string after trim
Modification Comments	: 
*********************************************************************/

regexp1 = /^\s+/gi;
regexp2 = /\s+$/gi;


/*********************************************************************
Description				: This function used for validate date value
Author					: 
Creation Date			: April 5, 2005
Last Modified By		: 
Last Modified Date		:	 
Parameters				: Object Value
Return values			: String
Modification Comments	: 
*********************************************************************/
function checkDate(st,label) 
{
	datest=""
	//var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/;								
	
	var datePat = /^(((\d{1,2})(\/)(\d{1,2})(\/)(\d{4}))|((\d{1,2})-(\d{1,2})-(\d{4})))$/;
	var matchArray =  datePat.test(st); //st.test(datePat); //datePat.test(st);
	if (!matchArray) {
        datest="Invalid date. Please enter "+label+" as mm/dd/yyyy";
        return datest;
    }
    
	if (matchArray == null)
	{
		datest="Date is not in a valid format.";
		return datest;
		
	}
	var dateArr
	
    if(st.indexOf("/")!=-1)
		dateArr=st.split("/");
	else
		dateArr=st.split("-");

    month = dateArr[0]; // parse date into variables
    day = dateArr[1];
    year = dateArr[2]
    
	//month = matchArray[1]; // parse date into variables
	//day = matchArray[3];
	//year = matchArray[4];
//
	if (month < 1 || month > 12)
	{ 
		// check month range
		datest="Month must be between 1 and 12"; 
	

	}

	if (day < 1 || day > 31)
	{
		datest="Day must be between 1 and 31"; 											
		
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
   {
		datest="Month "+month+" doesn't have 31 days" ;										
		
	}

	if (month == 2)
   { 
		// check for february 29th
		var g = parseInt(year / 4);
		if (day > 29 || (day == 29 && (year / 4) != g))
		{
			datest="February in "+year+" doesn't have "+day+" days";												
			
		}
	}

	return datest;
}

/*********************************************************************
Description				: This function used to implement the 
                          validation on passed control Name
Author					: 
Creation Date			: March 29, 2005
Last Modified By		: 
Last Modified Date		:	 
Parameters				:   Object Name,
                            Error Message,
                            Mandatory,
                            validation Type, 
                            Maxlength, 
						    MinLength, 
						    Object IInd to choice one
Return values			: Error Message
Modification Comments	: 
*********************************************************************/
  
 //CIMII:validates time---------------Palwi chugh
 function IsValidTime(timeStr) 
            {
                // Checks if time is in HH:MM:SS AM/PM format.
                // The seconds and AM/PM are optional.

                var timePat=/^(\d{1,2}):(\d{2})?(\))?$/;
                var matchArray = timeStr.match(timePat);
                if (matchArray == null) 
                {
                
                return "Time is not in a valid format(hh:mm).";
                }

                hour = matchArray[1];
                minute = matchArray[2];
                second = matchArray[4];
                ampm = matchArray[6];

                if (second=="") { second = null; }
                if (ampm=="") { ampm = null }

                if (hour < 0  || hour > 23) 
                {
               // alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
                return "Hour must be between 1 and 12. (or 0 and 23 for military time)";
                }
                if  (hour > 12 && ampm != null) 
                {
                alert("You can't specify AM or PM for military time.");
                return false;
                }
                if (minute<0 || minute > 59) 
                {
                return "Minute must be between 0 and 59.";
                }
                if (second != null && (second < 0 || second > 59)) 
                {
                return "Second must be between 0 and 59.";
                }
                return "";
        }

 ///////////////////////////////////////////////////////
  
/*********************************************************************
Description				: This function used to See if a passed value is numeric or not.
						  Valid values are 0123456789.-
Author					: 
Creation Date			: March 27, 2006
Last Modified By		: 
Last Modified Date		:	 
Parameters				: 
Return values			: Boolean value, if it fails then False else True
Modification Comments	: 
*********************************************************************/

 function isNumeric(strString)
{

	var strValidChars = "0123456789.-";
	var strOnlynumber = "0123456789";
	var strChar;
	var blnResult = true;
	var intDotCount
	var intHypenCount
	var intCheckOnlyNumber
	
	intDotCount = 0;
    intHypenCount = 0;
    intCheckOnlyNumber = 0;
    
    if (strString.length == 0) return false;
    
    for (i = 0;i < strString.length && blnResult == true;i++)
    {
        if (strString.charAt(i).indexOf(".") != -1)
        {
            intDotCount ++; 
        }
        
        if (strString.charAt(i).indexOf("-") != -1)
        {
            intHypenCount ++; 
        }
        
        if ((intDotCount > 1) || (intHypenCount > 1 ))
        {
            blnResult = false;
        }
    }    

    for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strOnlynumber.indexOf(strChar) != -1)
		{
			intCheckOnlyNumber ++;
		}
	}
    
    if (intCheckOnlyNumber == 0 ) return false;
     
    //  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
	
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			{
				blnResult = false;
			}
	}
   return blnResult;
}

 
/*********************************************************************
Description				: This function used to See if a passed value is numeric or not.
						  Valid values are 0123456789
Author					: 
Creation Date			: March 27, 2006
Last Modified By		: 
Last Modified Date		:	 
Parameters				: 
Return values			: Boolean value, if it fails then False else True
Modification Comments	: 
*********************************************************************/

 function isOnlyNumeric(strString)
{

	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;

    if (strString.length == 0) return false;
    
    //  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
	
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			{
				blnResult = false;
			}
	}
   return blnResult;
}
// Handling Async Failure/Success Error for DropDown Data
// krishan
 function DisplayddlErrors(strInnerHTML)
{
     var strMessage;
     var strError="";
     var strIndex="";
     strIndex="</table>".toLowerCase();
     strError= strInnerHTML;
     strError=strError.substring(0,strError.indexOf(strIndex))
     strError=strError+"</table></ul></td></tr></table>";
    if(document.getElementById("msgLabel") != null)
    {
             
        strMessage = "<table style='width :100%' cellpadding='1' cellspacing='1'>";
        strMessage = strMessage + "<tr><td class='ErrorLabel'><img src='../images/error.gif' alt='' />&nbsp;Server Error(s)</td></tr>";
        strMessage = strMessage + "</table>"
        strMessage = strMessage + strError ;
  	    document.getElementById("msgLabel").style.display="";
	    document.getElementById("msgLabel").className = "ErrorLabelClass"
	    document.getElementById("msgLabel").innerHTML = strMessage;
	    window.scroll(0,0);
	}
}



 function DisplayErrors(strInnerHTML,serverPath)
{
    var strMessage;
    if(document.getElementById("lblError") != null)
    {
        strMessage = "<table style='width :100%' cellpadding='1' cellspacing='1'>";
        if (serverPath==null)
            strMessage = strMessage + "<tr><td class='ErrorLabel'><img src='./images/error.gif' alt='' />&nbsp;Validation Error(s)</td></tr>";
        else
            strMessage = strMessage + "<tr><td class='ErrorLabel'><img src='"+serverPath+"/images/error.gif' alt='' />&nbsp;Validation Error(s)</td></tr>";
        strMessage = strMessage + "<tr><td><ul>" + strInnerHTML + "</ul></td></tr>";
        strMessage = strMessage + "</table>"
        
	    document.getElementById("lblError").style.display="";
	    document.getElementById("lblError").className = "ErrorLabelClass"
	    document.getElementById("lblError").innerHTML = strMessage;
	    window.scroll(0,0);
	}
}



 function DisplayServerMessages(strInnerHTML)
{
    var strMessage;
    if(document.getElementById("msgLabel") != null)
    {
        strMessage = "<table style='width :100%' cellpadding='1' cellspacing='1'>";
        strMessage = strMessage + "<tr><td class='ErrorLabel'><img src='../images/error.gif' alt='' />&nbsp;Server Message(s)</td></tr>";
        strMessage = strMessage + "<tr><td><ul>" + strInnerHTML + "</ul></td></tr>";
        strMessage = strMessage + "</table>"
        
	    document.getElementById("msgLabel").style.display="";
	    document.getElementById("msgLabel").className = "ErrorLabelClass"
	    document.getElementById("msgLabel").innerHTML = strMessage;
	    window.scroll(0,0);
	}
}


 function ClearErrorLabel()
{
    if(document.getElementById("msgLabel") != null)
    {
	    document.getElementById("msgLabel").innerHTML = BLANK_FILTER;
	    document.getElementById("msgLabel").style.display="none";
	}
}

 /*********************************************************************
Description				: This function used to check if the value is numeric
Author					: 
Creation Date			: 
Last Modified By		: 
Last Modified Date		:	 
Parameters				: objName,minval,maxval
Return values			: 
Modification Comments	: 
*********************************************************************/
//**************************************************************************
     // Check numeric bvalues
     function chkNumeric(objName,minval,maxval)
        {
        // only allow 0-9 be entered, plus any values passed
        // (can be in any order, and don't have to be comma, period, or hyphen)
        // if all numbers allow commas, periods, hyphens or whatever,
        // just hard code it here and take out the passed parameters
        var checkOK = "0123456789"
        var checkStr = objName;
        var allValid = true;
        var decPoints = 0;
        var allNum = "";
        
        //Loop through the value passed
        for (i = 0;  i < checkStr.length;  i++)
        {
            ch = checkStr.charAt(i);
            
            //Loop for all the permissible values
            
            for (j = 0;  j < checkOK.length;  j++)

                if (ch == checkOK.charAt(j))
                    break;
                    
                if (j == checkOK.length)
                {
                    allValid = false;
                    break;
                }
                if (ch != ",")
                    allNum += ch;
                }
                if (!allValid)
                {	
                    return (false);
                }
                
                // set the minimum and maximum
                var chkVal = allNum;
                var prsVal = parseInt(allNum);
                if (minval != -1 && maxval != -1)
                {    
                    if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
                        {
                            
                            return (false);
                        }
                       else
                       {
                            return true;
                       }
                }
                else
                    return true;
             }
             
/*********************************************************************
Description				: This function used to check if the value is decimal or not
Author					: 
Creation Date			: 
Last Modified By		: 
Last Modified Date		:	 
Parameters				: objName,minval,maxval,Precesion,Scale
Return values			: 
Modification Comments	: 
*********************************************************************/
//**************************************************************************
//**************************************************************************
// Check numeric bvalues
        function chkDecimal(objName,minval,maxval,Precesion,Scale)
        {
        // only allow 0-9 be entered, plus any values passed
        // (can be in any order, and don't have to be comma, period, or hyphen)
        // if all numbers allow commas, periods, hyphens or whatever,
        // just hard code it here and take out the passed parameters
        var checkOK = "0123456789."
        var checkStr = objName;
        var allValid = true;
        var decPoints = 0;
        var allNum = "";
        var intdec=0;
        var intDecimalPart ='';
        Precesion++;
        //Loop through the value passed
                
        //Checking for the negative 
        
//        if (minval < 0)
//        {
//            checkOK = "0123456789.-"
//        }
//        else
//        {   
//            checkOK = "0123456789."
//        }
//        


        for (i = 0;  i < checkStr.length;  i++)
        {
            ch = checkStr.charAt(i);
            
            //Loop for all the permissible values
             
            for (j = 0;  j < checkOK.length;  j++)
            {
                
                if (ch == checkOK.charAt(j))
                {
                    //Logic for decimal digit
                    if (intdec==0)
                    {
                        //Check for difits gr th prec.
                        if (i <= Precesion)
                        {
                            //Catch decimal position
                            if (ch == ".")
                            {
                                intdec=i;
                            }
                                        
                        }
                        else
                        {
                            return false;
                        }
                            
                    }
                    else
                    {
                        if(intdec!=0 && ch=='.')
                            return false;
                        else
                            intDecimalPart = intDecimalPart + ch;
                    }
                 break;
                }
                else if(minval < 0 && i == 0)
                {
                    if (ch == "-")
                        break;
                }
            }
            if (j == checkOK.length)
            {
                allValid = false;
                break;
            }
          
            if (ch != ",")
               allNum += ch;
            
        }
             
        if (!allValid)
        {	
            return (false);
        }
            
            // set the minimum and maximum
        var chkVal = objName;
        var prsVal = parseFloat(eval(objName));
       
        if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
            {
                
                return false;
            }
           else
           {
            return true
                
           }
               
        if((i-intdec)>Scale)
           {
            
            return false;
           
           }
    }             

//==================================================================
function DateCompare(valDate1, valDate2) 
{
    
    if (Date.parse(valDate1.value) <= Date.parse(valDate2.value)) 
    
    {
       return true; 
    }
    else 
    {
        return false;
    }
}
function formatCurency(nStr)
{
        nStr += '';
        x = nStr.split('.');
        var x1 = x[0];
        var x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1))
        {
	       x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
        
}
//==================================================================

function CheckValForNumeric(txtctrlid, strCaption,blnNegative)
{
    
    if (blnNegative)
    {
        if (!chkDecimal(trim(document.getElementById(txtctrlid).value),"-99999999.99","999999999.99","9","2"))
            {
            
              return "\n" + strCaption + " should be Numeric 99999999.99, greater than equal to -99999999.99 and less than equal to 999999999.99"
            
            }			        
        else
            {
                return "";
            }          
        
    }
    else
    {
        if (!chkDecimal(document.getElementById(txtctrlid).value,"0","999999999.99","9","2"))
            {
            
              return "\n" + strCaption + " should be Numeric 999999999.99, greater than equal to 0 and less than equal to 999999999.99"
            
            }			        
        else
            {
                return "";
            }          
    }        
}

//==================================================================
 function SetSelectedItems(strBaseString,StrCtrlName)
    {
        var listbox=document.getElementById(StrCtrlName);
        var strHidMapping = new String();
        strHidMapping  = strBaseString.split(",");
        for (intOuter=0;intOuter < listbox.options.length; intOuter++)
        {
           for(intInner=0;intInner < strHidMapping.length ; intInner++)
            {
               if (listbox[intOuter].value == strHidMapping[intInner])
                {
                    listbox.options[intOuter].selected = true;
                }
            }
            
        }
      
    }
    
    //=====================================================================================
    //Converts first character of each word to upper case.
    //=====================================================================================
    function ConvertFirstUpper(strValue)
    {
        var pos=0;
        strValue =" "+ strValue
        var chrPos = strValue.indexOf(" ",pos)
        while(chrPos!=-1)
        {
           strValue= strValue.replace(" "+strValue.charAt(chrPos+1)," "+strValue.charAt(chrPos+1).toUpperCase());
            chrPos = strValue.indexOf(" ",chrPos+1);
        }
        return  trim(strValue);
    }
    function GetDiffInDays(valDate1,valDate2)
    {
       return ((Date.parse(valDate1.value) - Date.parse(valDate2.value))/86400000)
    }    
          
    function validatePhone(strPhone)
    {
        if(!isEmpty(strPhone))
        {
            var validPhone = true;
            var original = trim(strPhone); 
            var phone = original.replace(/[(]/,"").replace(/[)]/,"").replace(/-/,"").replace(/ /g,"")
            if(phone.length!=10 || isNaN( phone)==true ||phone.indexOf("+")>0||phone.indexOf("-")>0||phone.indexOf(".")>0)
            {    
                validPhone = false;
            }
            else
            {
                //checking position of "("
                if(original.indexOf("(")>0)
                {
                    validPhone = false;
                }
                else
                {
                     //checking position of ")"
                    phone = original.replace(/[(]/,"").replace(/-/,"").replace(/ /g,"")
                    if(phone.indexOf(")")!=3 && phone.indexOf(")")!=-1) 
                    {
                        validPhone = false;
                    }
                    else
                    {
                        //checking position of "-"
                        phone = original.replace(/[(]/,"").replace(/[)]/,"").replace(/ /g,"")
                        if(phone.indexOf("-")!=6 && phone.indexOf("-")!=-1)
                        {
                            validPhone = false;
                        }
                        else
                        {
                            //checking position of space
                            phone = original.replace(/[(]/,"").replace(/[)]/,"").replace(/-/,"")
                            var expression = /^(\d{3}[" "]\d{3}[" "]\d{4})|(\d{6}[" "]\d{4})|(\d{3}[" "]\d{7})|(\d{10})$/;
                            if(original.indexOf("( ")>=0||original.indexOf(" )")>=0||original.indexOf("- ")>=0||original.indexOf(" -")>=0||!expression.test(phone))
                            {
                                validPhone = false;
                            }
                        }
                    }
                }
            }       
            if(validPhone == false)
                return "Phone should be in following format (nnn) nnn-nnnn"; 
        }
        return "";
    }

    function AddtoExp(variable,parameter)
    {
        var hdnvalue=parent.fraToolbar.document.getElementById(variable).value;
        if(hdnvalue.indexOf(parameter)<0)
        {
            hdnvalue =hdnvalue + parameter+"|";
        }
        parent.fraToolbar.document.getElementById(variable).value=hdnvalue;
    }

    function RemfmExp(variable,parameter)
    {
        var hdnvalue=parent.fraToolbar.document.getElementById(variable).value;
        if(hdnvalue.indexOf(parameter+"|")>=0)
        {
            hdnvalue =hdnvalue.replace(parameter+"|","");
        }
        parent.fraToolbar.document.getElementById(variable).value=hdnvalue;
    }


    function SetExp(img,vari,par)
    {
        staticize();
        var imageSrc=document.getElementById(img).src;
        if(imageSrc.indexOf("/images/minus.gif")>=0)
            RemfmExp(vari,par);
        else
            AddtoExp(vari,par);
    }

    function staticize(DivName)
    {
        if(DivName)
            DivName=DivName;
        else 
            if(strProcessImg)
                DivName=strProcessImg;
            else
                DivName="divImage";
            
        if(document.getElementById(DivName))
        {
            w= .5*ietruebody().offsetWidth-50;
            h= .5*ietruebody().offsetHeight;
            w2=ietruebody().scrollLeft+w;
            h2=ietruebody().scrollTop+h;
            document.getElementById(DivName).style.left=w2;
            document.getElementById(DivName).style.top=h2;
        }
    }

    function ietruebody()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
    }


    function filRemarks(strMasterValue, strCtrlName, strStatus)
    {   
        var intOuter;
        if (strMasterValue.length > 0) 
        {
           var listitem=document.getElementById(strCtrlName);
            listitem.innerHTML = '';
            var blnflag;
        
            var strRemarksMapping = new String();
            strRemarksMapping = strMasterValue.split("#@#");
            blnflag = "false";
            
            for (intOuter=0; intOuter < strRemarksMapping.length; intOuter++)
            {
                var strRemark = strRemarksMapping[intOuter].split("|");
                if ((strRemark[1] == strStatus) && (strStatus != ""))
                {
                    if (blnflag == "false") 
                    {
                        var newDefaultOpt = document.createElement("option");
                        newDefaultOpt.text = "Select";
                        newDefaultOpt.value= "";
                        listitem.add(newDefaultOpt);
                        blnflag = 'true';
                    }                        
                    var newOpt = document.createElement("option");
                    newOpt.text = strRemark[0];
                    newOpt.value = strRemark[0];                                
                    listitem.add(newOpt);                                
                    newOpt.selected = true; 
                }
            }
        }
        return false;
    }

///////////////////////////////////////////////////////////////////////////////////////
function checkDateFormat(val)
{
    // regular expression to match required date format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;

    if(val != '') 
    {
        if(regs = val.match(re)) 
        {
            if(regs[1] < 1 || regs[1] > 31) 
            {
                return false;
            }
            if(regs[2] < 1 || regs[2] > 12) 
            {
              return false;
            }
            if(regs[3] < 1902 || regs[3] > (new Date()).getFullYear()) 
            {
              return false;
            }
        } 
        else 
        {
            return false;
        }
    }
    return true;
}
function checkTimeFormat(val)
{    // regular expression to match required time format
    re = /^(\d{1,2}):(\d{2})([ap]m)?$/;

    if(val != '') 
    {
        if(regs = val.match(re)) 
        {
            if(regs[3]) 
            {
                if(regs[1] < 1 || regs[1] > 12) 
                {
                    return false;
                }
                } else 
                {
                    if(regs[1] > 23) 
                    {
                        return false;      
                     }
                }
                if(regs[2] > 59) 
                {
                    return false;      
                }
            } else 
            {
                return false;
            }
        }

    
    return true;
}

function formatdate(dateval)
{
    var newDate;
    newDate = dateval.split("/")[1] +"/" +dateval.split("/")[0] ;
    for (i = 2; i < dateval.split("/").length; i++)  
	{
	    newDate = newDate+"/"+dateval.split("/")[i];
	}			
    return newDate
}


function AddDays(myDate,days) 
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}



function GetToday() 
{
    var date1 = new Date();
    var returnDate = date1.getDate()+"/"+eval(date1.getMonth()+1)+"/"+date1.getYear();
    return returnDate+" 00:00";
}

