﻿//* -------------------- COMMON FUNCTIONS ----------------------------------
/* Function to check if required field is blank or not, if field is 
   blank then error message is displayed
*/

//~ Checks to see if a required field is blank.  If so, an error message is displayed.(Common Function)
//////function ForceDataEntry(objField, strFieldName)
//////{
////// // To find out the Value of the control
////// var strFieldValue=trimAll(objField.value); 
////// if ((strFieldValue == null) || (strFieldValue.length==0))
////// {
//////  alert("You need to enter information for " + strFieldName);
//////  objField.focus();
//////  return false;
////// }
////// return true;
//////}

//===================================================
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
//-------------------------------------------------
function FD(obj)
{
   //debugger;
    var id = obj.id;
    value = obj.value;
    len = value.length;
    if(Number(len)==11)
    {
      if(Number(event.keyCode) == 190 || Number(event.keyCode) == 8 || Number(event.keyCode) == 46)
      {
        return true;
      }
      else
      { 
        if((event.keyCode >= 96 && event.keyCode <= 105) ||
        (event.keyCode > 32 && event.keyCode < 48) ||
        (event.keyCode > 57 && event.keyCode < 65) ||
        (event.keyCode > 90 && event.keyCode < 96) ||
        (Number(event.keyCode) == 189 || Number(event.keyCode) == 109))
        {
            return true; 
        }
        else
        {
            if(Number(event.keyCode) == 9)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
      }
    }
    else
    {
        //if(Number(event.keyCode) == 190)
        //{
            var value = obj.value;
            var len = value.length;
            var index = value.indexOf('.');
            if (Number(index)!= -1)
            {
                value = value.substring(Number(index)+1,Number(len));
                len = value.length;
                if (len>1)
                {
                     if(Number(event.keyCode) == 8 || Number(event.keyCode) == 46)
                    {
                        return true;
                    }
                    else
                    {
                        if((event.keyCode >= 96 && event.keyCode <= 105) ||
                        (event.keyCode > 32 && event.keyCode < 48) ||
                        (event.keyCode > 57 && event.keyCode < 65) ||
                        (event.keyCode > 90 && event.keyCode < 96) ||
                        (event.keyCode == 189 || event.keyCode == 109))
    
                        {
                            return true; 
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
           }
        return true;
    }
    return true;
}
//*------------------------------------------------u
function onReset()
{
//debugger;
    document.getElementById("txtOldPassword").focus();
    document.getElementById("lblMessage").innerText='';
}
//=================================================
function resetRTE()
{
//debugger;
    //document.getElementById("rtEditor").innerText='';
    //document.getElementById("rtEditor").innerHTML='';
    //document.getElementById("rtEditor").innerHTML=document.getElementById("hdnRTE").value
    
}
//==================================================
function RTE()
{
    //debugger;
    var rte=document.getElementById("rtEditor").innerHTML;
    document.getElementById("hdnRTE").value=rte;
}
//===================================================
function noCopyKey(e) 
{
    var forbiddenKeys = new Array('c','x','v');
	var isCtrl;

        if(window.event) {
		if(window.event.ctrlKey)
			isCtrl = true;
		else
			isCtrl = false;
        }
        else {
                if(e.ctrlKey)
                	isCtrl = true;
                else
                	isCtrl = false;	}

	if(isCtrl) {
		for(i=0; i < forbiddenKeys.length; i++) {
			if(forbiddenKeys[i] == String.fromCharCode(window.event.keyCode).toLowerCase()) {
				alert('You can not copy and paste here');
				return false;
			}
        		}
	}
	return true;
}
//===================================================
function noCopyMouse(e) 
{
//debugger;
    var message="";
	if (event.button == 2 || event.button == 3) 
	{
	    //this.focus();
		alert('You can not copy and paste here');
		return false;
    }
	return true;
}

//=================================================
//# Function for restricting Multiline textbox length to 255 characters
function check()
{
//debugger;
    var value=document.getElementById("txtComments").innerText;  
    var len = value.length;
    if(Number(len)>255)
    {
      if((event.keyCode >= 96 && event.keyCode <= 105) ||
      (event.keyCode > 32 && event.keyCode < 48) ||
      (event.keyCode > 57 && event.keyCode < 65) ||
      (event.keyCode > 90 && event.keyCode < 96) ||
      (event.keyCode == 189 || event.keyCode == 109))
    
        {
            return true; 
        }
         else
        {
             return false;
        }
    }
    else
    {
        return true;
    }
}
//==================================================
function CheckKeyCode()
{
//debugger;
  if((event.keyCode >= 96 && event.keyCode <= 105) ||
      (event.keyCode > 32 && event.keyCode < 48) ||
      (event.keyCode > 57 && event.keyCode < 65) ||
      (event.keyCode > 90 && event.keyCode < 96) ||
      (event.keyCode == 189 || event.keyCode == 109))
    
  {
    return true; 
  }
  else
  {
    return false;
  }
}
//===================================================
//# Function to restrict user to Add any Detail in
//Book form if he/she has not the permission to add
function PermissionAdd()
{
    //debugger;
    if(document.getElementById("hdnUserName").value.toLowerCase() !=("Admin").toLowerCase())
    {
         if(document.getElementById("hdnAdd").value.toLowerCase()==("True").toLowerCase())
         {
             return true;
         }
         else
         {
             alert("You are not authorised to Add the Details");
             return false;
         }
    }
}
//--------------------------------------------------
//# Function to restrict user to Add any Detail in
//Book form if he/she has not the permission to add
function PermissionView()
{
    //debugger;
    if(document.getElementById("hdnUserName").value.toLowerCase()!=("Admin").toLowerCase())
    {
         if(document.getElementById("hdnView").value.toLowerCase()==("True").toLowerCase())
         {
             return true;
         }
         else
         {
             alert("You are not authorised to View the Details");
             return false;
         }
    }
}
//--------------------------------------------------
function ForceDataEntry(objField, strFieldName)
{
	// To find out the Value of the control
	var strFieldValue=objField.value;
	if (trimAll(objField.value) == '0' || trimAll(objField.value) == '0.00' || trimAll(objField.value) == '') 
	{
		alert("You need to enter information for " + strFieldName);
		objField.focus();
		return false;
	}
	else if (IsEmpty(strFieldValue))
	{
		alert("You need to enter information for " + strFieldName);
		objField.focus();
		return false;
	}
	return true;
}
 //^ Function for trim any string
function trimAll( strValue )
{				
	var objRegExp = /^(\s*)$/;
     //check for all spaces
	if(objRegExp.test(strValue))
	 {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
			return strValue;
		 }
     //check for leading & trailing spaces
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) 
     {
    	//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	 }
		return strValue;
}
 
//=========================================


//* Check whether a given string is empty or not.
function IsEmpty(strTxtBoxValue)
{   if ((strTxtBoxValue == null) || (strTxtBoxValue.length == 0))
	{
		return true;			
	}	
}

//===============================================================================================================

//~ Check whether a given DropDown value is empty or not.
function IsComboEmpty(ddlValue)
{ 
    if  ((ddlValue == 0) || (ddlValue == '--Select--'))
    {
    return true; //^ Returning True, if Empty Text Box found
    } 
}
//===============================================================================================================
//~ Checks to see if a DropDownList is empty. If so, an error message is displayed.
function ForceComboItems(ddlName, strDdlName)
{
	// To find out the Value of the control0.
	var ItemCount=ddlName.value;
	if (IsComboEmpty(ItemCount))
		{
			alert("First Select the " + strDdlName);
			ddlName.focus();
			return false;
		}
	return true;
}
//===============================================================================================================
function isDecimalValue(fieldName, fieldLabel)
{
    var decallowed = 2;  // how many decimals are allowed?
    var fieldValue = fieldName.value;
    
    if (isNaN(fieldValue) || fieldValue == "") 
    {
        alert(fieldLabel + " is not a valid number.");
        fieldName.select();
        fieldName.focus();
        return false;
    }
    else 
    {
        if (fieldValue.indexOf('.') == -1) fieldValue += ".";
           var dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
    
        if (dectext.length > decallowed)
        {
            alert (fieldLabel + " allows up to " + decallowed + " decimal places only.");
            fieldName.select();
            fieldName.focus();
            return false;
        }
        else 
        {
            return true;
        }
    }
}
//================================================================================================================
//^ Returns true if the string passed is a valid decimal value
//^ Also enforces a value > 0
function ForceDecimalEntry(fieldName, fieldLabel)
{
    decallowed = 2;  // how many decimals are allowed?
    fieldValue = fieldName.value;
    
    if (isNaN(fieldValue) || fieldValue == "") 
    {
        alert(fieldLabel + " is not a valid decimal value.");
        fieldName.select();
        fieldName.focus();
        return false;
    }
    else 
    {
        if (fieldValue.indexOf('.') == -1) fieldValue += ".";
            dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
    
        if (dectext.length > decallowed)
        {
            alert (fieldLabel + " allows up to " + decallowed + " decimal places only.");
            fieldName.select();
            fieldName.focus();
            return false;
        }
        
    }
    
    //if it is a Valid Decimal value, then it must be > 0		
    var strLength = fieldValue.length;
    var intLoopCounter = 0;
    var ZeroValue = "Y";
    
    while (intLoopCounter < strLength)
    {
            if (fieldValue.charAt(intLoopCounter) == '0' || fieldValue.charAt(intLoopCounter) == '.')
            {
                intLoopCounter = intLoopCounter + 1;
            }
            else
            {
                ZeroValue = "N"  
                break ;
            }
    }
    if (ZeroValue == "Y")
    {
		alert(fieldLabel + " must be greater than 0");
		fieldName.focus();
		return false;
    }
    
	return true;

}
// ---------------------------------------------------------------------------------------
//# Specific for project
//^ Returns true if the string passed is a valid decimal value
//^ Also enforces a value > 0
function ForceDecimalEntryNew(fieldName, fieldLabel)
{
    decallowed = 2;  // how many decimals are allowed?
    //fieldValue = fieldName.value;
    fieldValue = fieldName;
    
    //if (isNaN(fieldValue) || fieldValue == "") 
    //{
    //    alert(fieldLabel + " is not a valid decimal value.");
        //fieldName.select();
        //fieldName.focus();
    //    return false;
   // }
   // else 
   // {
        if (fieldValue.indexOf('.') == -1) fieldValue += ".";
            dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
    
        if (dectext.length > decallowed)
        {
            alert (fieldLabel + " allows up to " + decallowed + " decimal places only.");
            //fieldName.select();
            //fieldName.focus();
            return false;
        }
        
    //}
    
    //if it is a Valid Decimal value, then it must be > 0		
    var strLength = fieldValue.length;
    var intLoopCounter = 0;
    var ZeroValue = "Y";
    
    while (intLoopCounter < strLength)
    {
            if (fieldValue.charAt(intLoopCounter) == '0' || fieldValue.charAt(intLoopCounter) == '.')
            {
                intLoopCounter = intLoopCounter + 1;
            }
            else
            {
                ZeroValue = "N"  
                break ;
            }
    }
    if (ZeroValue == "Y")
    {
		alert(fieldLabel + " must be greater than 0");
		//fieldName.focus();
		return false;
    }
    
	return true;

}
//========================================================================================

//~ Check whether a given Email is Valid or not.
function IsEmailValid(objField, strFieldName,IsMandatory)
{
 // To find out the Value of the control
 var strFieldValue=objField.value;
 if (IsMandatory=="T")
    {
        if (IsEmpty(strFieldValue))
        {
            alert(strFieldName + " can not be left blank");
            objField.focus();
            return false;
        }    
    }
    if (IsMandatory=="F")
    {
        if (IsEmpty(strFieldValue))
        {
            return true;
        }
    }
    var at="@";
    var dot=".";
    var underscore="_";
    var lat=strFieldValue.indexOf(at);
    var lstr=strFieldValue.length;
    var ldot=strFieldValue.indexOf(dot);
    var lastdot=strFieldValue.lastIndexOf(dot);
    var lunderScore=strFieldValue.indexOf(underscore);
    var lastunderScore=strFieldValue.lastIndexOf(underscore);
    var i,d=0,s=0,ui=0,countDot=0,countUS=0;
    var count=0;
 
    if (strFieldValue.indexOf(at)==-1)
    {
        alert("Email should be in abc@xyz.com format");
       objField.focus();
       return false;
    }
    if (strFieldValue.indexOf(at) == -1 || strFieldValue.indexOf(at) == 0 || strFieldValue.indexOf(at) == lstr)
    {
       alert("Email should be in abc@xyz.com format");
       objField.focus();
       return false;
    }
    if (strFieldValue.lastIndexOf(dot)== lstr-1 || strFieldValue.indexOf(dot)== -1 || strFieldValue.indexOf(dot)== 0  )
    {
       alert("Email should be in abc@xyz.com format");
       objField.focus();
       return false;
    }
 
    if(!((strFieldValue.charCodeAt(0)>=65 && strFieldValue.charCodeAt(0)<=90) || (strFieldValue.charCodeAt(0)>=97 && strFieldValue.charCodeAt(0)<=122)))
    {   
        alert(" First letter should be character ");
         objField.focus();
         return false;
     }
 
    if ((ldot+1)  == lstr)
    {
 
        alert("Email should be in abc@xyz.com format");
        objField.focus();
        return false;
    }
     if (strFieldValue.indexOf(at,(lat+1))!= -1)
     {
        alert("Email should be in abc@xyz.com format");
        objField.focus();
        return false;
     }
     if (strFieldValue.substring(lat-1,lat) == dot || strFieldValue.substring(lat+1,lat+2)== dot)
     {
       alert("Email should be in abc@xyz.com format");
       objField.focus();
       return false;
     }
 
     if (strFieldValue.indexOf(dot,(lat+2))== -1)
     {
        alert("Email should be in abc@xyz.com format");
        objField.focus();
        return false;
     }
 
     if (strFieldValue.indexOf(" ")!= -1)
     {
         alert("Email should be in abc@xyz.com format");
         objField.focus();
         return false;
     }
      
     
     for(i=lat;i<lstr;i++)
     {
     if(strFieldValue.charAt(i)== dot)
     count=count+1;
     }
     if(count>2)
     { 
     alert("Email should be in abc@xyz.com format");
         objField.focus();
         return false;
     }
 

    for(i=strFieldValue.lastIndexOf(dot)+1;i<lstr;i++)
    {
    d=d+1;
    if(!((strFieldValue.charCodeAt(i)>=65 && strFieldValue.charCodeAt(i)<=90) || (strFieldValue.charCodeAt(i)>=97 && strFieldValue.charCodeAt(i)<=122)))
    { 
     alert("Domain should be only characters");
         objField.focus();
         return false;
     }
    }
    if(d>5)
    { 
     alert("Domain should not be more than 5 characters");
         objField.focus();
         return false;
     }
 

    for(i=strFieldValue.indexOf(at)+1;i<=strFieldValue.lastIndexOf(dot);i++)
    {
    s=s+1;
    if(!((strFieldValue.charCodeAt(i)>=65 && strFieldValue.charCodeAt(i)<=90) || (strFieldValue.charCodeAt(i)>=97 && strFieldValue.charCodeAt(i)<=122) || (strFieldValue.charAt(i)>=0 && strFieldValue.charAt(i)<=9) || (strFieldValue.charAt(i)==dot)))
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
     }     
    if(s>20)
    {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
     if(strFieldValue.charAt(lastdot-1)==dot)
     {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
         if(strFieldValue.charAt(lastunderScore-1)==underscore)
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
         if(strFieldValue.charAt(lunderScore+1)==dot)
     {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
         if(strFieldValue.charAt(ldot+1)==underscore)
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
         if(strFieldValue.charAt(lat-1)==underscore)
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
         
         if(strFieldValue.charAt(lat-1)==dot)
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
     
    for(i=0;i<lat;i++)
    {
    if(strFieldValue.charAt(i)==dot)
    {
    countDot=countDot+1;
    }
    ui=ui+1;
    }
    if(ui>30)
    {   
             alert(" User name should be less than 30 character ");
             objField.focus();
             return false;
     }
     if(countDot>1)
    {   
             alert(" User name should not contain more than one dot");
             objField.focus();
             return false;
     }
 

    for(i=0;i<lat;i++)
    {
    if(strFieldValue.charAt(i)==underscore)
    {
    countUS=countUS+1;
    }
    }
 
    if(countUS>2)
    {
    alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
     }
        
     for(i=1;i<lstr;i++)
     {
        if(!((strFieldValue.charCodeAt(i)>=65 && strFieldValue.charCodeAt(i)<=90) || (strFieldValue.charCodeAt(i)>=97 && strFieldValue.charCodeAt(i)<=122) || (strFieldValue.charAt(i)== '_') || (strFieldValue.charAt(i)>=0 && strFieldValue.charAt(i)<=9) || (strFieldValue.charAt(i)==dot) || (strFieldValue.charAt(i)==at)))
        {   
             alert(" Email should be in abc@xyz.com format ");
             objField.focus();
             return false;
         }
      }
   return true;     
       
}

 //===============================================================================================================
//===============================================================================================================
//^ Returns true if the string passed is a valid non-decimal numeric value
//^ no characters except a -ve sign at the begining is accepted
//^ otherwise, it displays an error message
//^ Also Forces the user to enter a value > 0

function ForceNumericEntry(objField, strFieldName,IsMandatory)
{
	var strFieldValue = new String(objField.value);
    var intLoopCounter = 0;
    
    //^ If mandatory field => testing for blank or spaces
    if (IsMandatory=="T")
    {
        if (IsEmpty(strFieldValue))
        {
            alert(strFieldName + " can not be left blank");
            objField.focus();
            return false;
        }
    }
    else    //^ If non-mandatory field => blank or spaces is ignored
    if (IsMandatory=="F")
    {
        if (IsEmpty(strFieldValue))
        {
            return true;
        }
    }

    // Checking for spaces at the begining of text.
    if (strFieldValue.indexOf(" ")!= -1)
    {
        alert(strFieldName + " must be a valid No.");
        objField.focus();
        return false;
    }

    // Validating for a numeric non-decimal value.
	for (intLoopCounter = 0; intLoopCounter < strFieldValue.length; intLoopCounter++)
	{
		//if ((strFieldValue.charAt(intLoopCounter) < '0' || strFieldValue.charAt(intLoopCounter) > '9') && (strFieldValue.charAt(0) != '-'))
		if  (strFieldValue.charAt(intLoopCounter) == '.')
		{
			alert(strFieldName + " does not accept a decimal value.");
			objField.focus();
			return false;
		}
		if  ((strFieldValue.charAt(intLoopCounter) > '9') && (strFieldValue.charAt(0) != '-'))
		{
			alert(strFieldName + " must be a valid numeric value.");
			objField.focus();
			return false;
		}
	}
		
    //^ Validating for the Valid Numeric value to be > 0		
    var strLength = strFieldValue.length;
    intLoopCounter = 0;
    var ZeroValue = "Y";
    
    while (intLoopCounter < strLength)
    {
            if (strFieldValue.charAt(intLoopCounter) == '0')
            {
                intLoopCounter = intLoopCounter + 1;
            }
            else
            {
                ZeroValue = "N"  
                break ;
            }
    }
    if (ZeroValue == "Y")
    {
		alert(strFieldName + " must be greater than 0");
		objField.focus();
		return false;
    }
    
	return true;
}



//===============================================================================================================
//^ Function for trim any string
function trimAll( strValue )
{				
	var objRegExp = /^(\s*)$/;
     //check for all spaces
	if(objRegExp.test(strValue))
	 {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
			return strValue;
		 }
     //check for leading & trailing spaces
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) 
     {
    	//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	 }
		return strValue;
}

//# --------- Function to Validate Upload RTE Image ---------------- 
function ValidateUploadImage()
 {
//debugger;
	elem1  = document.getElementById("htmUploadImg");
    if(trimAll(elem1.value) == "")
	{	
		    alert("Please browse Upload Image.");
			elem1.focus();
			return false
	}
	return true;
 }
 //---------------------------------------------------------------------------------------------------------------

//*****************************END HERE *************************************

 //& ---------------- VALIDATE LOGIN FORM ----------------------------------------
  function ValidateLogin()
{
//debugger;
    //& Check for Login Name 
	if (!ForceDataEntry(document.Login.txtLoginId,'Login Id')) return false;
	//& Check for Password
	if (!ForceDataEntry(document.Login.txtPassword,'Password')) return false;
}
//& -----------------------------------------------------------------------------

//& ---------------- VALIDATE CHANGE PASSWORD FORM ----------------------------------------
function checkOldPassword()
{
    if(document.ChangePwd.txtOldPassword.value!='')
    {
        if(document.ChangePwd.txtOldPassword.value!=document.ChangePwd.hdnPwd.value)
	    {
	     alert("Old Password is not correct");
	     document.getElementById("txtOldPassword").focus();
	     return false;
	    }
	    //else
	        //return true;
    }
    return true;
 }
    
function checkNewPassword()
{
   // debugger;
    if(document.ChangePwd.txtNewPassword.value!='')
    {
       if(document.ChangePwd.txtOldPassword.value==document.ChangePwd.txtNewPassword.value)
    	{
    	    alert("Old Password and New Password can not be same");
    	    document.getElementById("txtNewPassword").focus();
    	    return false;
    	}
    	
    	if(document.ChangePwd.hdnLogin.value==document.ChangePwd.txtNewPassword.value)
    	{
    	    alert("Login Id and entered New Password are same, Again change your Password");
    	    document.getElementById("txtNewPassword").focus();
    	    return false;
    	}
    	var pwd = document.ChangePwd.txtNewPassword.value;
    	var len = trimAll(pwd).length; 
    	if(Number(len)<8)
    	{
    	    alert("Password should be of 8 characters atleast");
    	    document.getElementById("txtNewPassword").focus();
    	    return false;
    	}
    	 
    	//else
    	   // return true;
    }
   return true;
 }
 
 function checkConfirmPassword()   
 {
    if(document.ChangePwd.txtConfirmPassword.value!='')
    {
        if(document.ChangePwd.txtNewPassword.value!=document.ChangePwd.txtConfirmPassword.value)
        {
	     alert("New Password and Confirm Password should be same");
	     document.getElementById("txtConfirmPassword").focus();
	     return false;
	    }
	   // else
	    //    return false;
    }
    return true;
   
  }
  
function ValidateChangePassword()
{
    //debugger;
    //& Check for Old Password 
	if (!ForceDataEntry(document.ChangePwd.txtOldPassword,'Old Password')) return false;
	if (!checkOldPassword()) return false;

	//& Check for New Password
	if (!ForceDataEntry(document.ChangePwd.txtNewPassword,'New Password')) return false;
	if (!checkNewPassword()) return false;

	//& Check for New Password
	if (!ForceDataEntry(document.ChangePwd.txtConfirmPassword,'Confirm Password')) return false;
	if (!checkConfirmPassword()) return false;
	//& Check for Mismatch b/w New Password & Confirm Password
	/*elem1= trimAll(document.getElementById("txtNewPassword"));
	elem2= trimAll(document.getElementById("txtConfirmPassword"));
    if(elem1.value!=elem2.value)
    {
	    alert("New Password and Confirm Password should be same");
	    document.getElementById("txtConfirmPassword").focus();
	    return false;
	}*/
}
//* -------------------------------------------------------------------------------------------------------

//& Function to Validate Category FORM ----------------------------------------
function ValidateCategory ()
{
   // & Category Name
   if (!ForceDataEntry (document.frmCategory.txtCategoryName,'Category Name')) return false;
   elem2  = document.getElementById("htmUploadImg");
        h1_Sw = document.getElementById("lblGalleryImage").innerText;
        if (h1_Sw.length==0)
	{   
	   if(trimAll(elem2.value) == "")
		{	
		    alert("Please browse Image for Category.");
			elem2.focus();
			return false;
		}
	}
}
//---------------------------------------------------------------------------------------------------------------


//&  Function to Validate Press Release ---------------- 
function ValidatePressReleaseForm()
{
//    if (!ForceComboItems(document.frmAddPressRelease.ddlLanguage,'Language')) return false;
//    if (!ForceComboItems(document.frmAddPressRelease.ddlYear, 'Year')) return false;
    if (!ForceDataEntry(document.frmAddPressRelease.txtHeading, 'Heading')) return false;
    chkNews=document.getElementById("chkNews") ;
	if(chkNews.checked){}
	else
	{
	    if (!ForceDataEntry(document.frmAddPressRelease.txtLink, 'Hyperlink')) return false;
	}
    if (!ForceDataEntry(document.frmAddPressRelease.txtPressName, 'Journal/Magazine')) return false;
    if (!ForceDataEntry(document.frmAddPressRelease.txtPublishDate, 'Publish Date')) return false;
    if (!showValue())return false;
    
    if(document.frmAddPressRelease.txtLink.value!="" && chkNews.checked==true)
        {
            alert("Either enter Hyperlink or select Firc in News, only one option is allowed");
            return false;
        }
//    if (!ForceDataEntry(document.frmAddPressRelease.txtPublishCity, 'Publish City')) return false;
}
//---------------------------------------------------------------------------------------------------------------

//& Function to Validate PhotoGallery----------------------------------------------------------------------------

function ValidatePhotoGallery()
{
    if (!ForceComboItems (document.frmAddPhotoGallery.ddlCategory,'Category')) return false;
    if (!ForceDataEntry (document.frmAddPhotoGallery.txtDescription,'Image Description')) return false;
        elem2  = document.getElementById("htmUploadImg");
        h1_Sw = document.getElementById("lblGalleryImage").innerText;
        if (h1_Sw.length==0)
	{   
	   if(trimAll(elem2.value) == "")
		{	
		    alert("Please browse Image for PhotoGallery.");
			elem2.focus();
			return false;
		}
	}
}
//----------------------------------------------------------------------------------------------------------------

//& Function to Validate MusicClip--------------------------------
function ValidateMusicClip()
{
 if (!ForceDataEntry (document.frmAddMusicClip.txtMusicCaption,'Music Clip Name')) return false;
    elem2  = document.getElementById("htmUploadClip");
    h1_Sw=document.getElementById("lblMusicFileName").innerText;
    //* -- Validation for Upload Software
	if (h1_Sw.length==0)
	{
	   if(trimAll(elem2.value) == "")
		{	
	        alert("Please browse file for Upload Music File.");
			elem2.focus();
			return false;
		}
	}
}
//----------------------------------------------------------------------------------------------------------------

//& Function to Validate Movie--------------------------------
function ValidateMovie()
{
   //debugger;
 if (!ForceDataEntry (document.frmAddMovie.txtMovieName,'Movie Clip Name')) return false;
    elem2  = document.getElementById("htmUploadMovie");
    h1_Sw=document.getElementById("lblMovieName").innerText;
    //* -- Validation for Upload Software
	if (h1_Sw.length==0)
	{
	   if(trimAll(elem2.value) == "")
		{	
	        alert("Please browse file for Upload Movie File.");
			elem2.focus();
			return false;
		}
	}
	
}
//----------------------------------------------------------------------------------------------------------------

 //# Function to Validate First Level Menu Form

function ValidateFirstLeveleMenu()
{
    //debugger;
     if (!ForceDataEntry (document.form1.txtMenuName,'Menu Name')) return false;
     if(document.form1.chkMenu.checked==true)
     {
        if(document.form1.chkQueryForm.checked==true)
        {
            if (!ForceDataEntry (document.form1.txtQueryPath,'Query Form Name')) return false;
        }
     }
}
//----------------------------------------------------------------------------------------------------------------

 //# Function to Validate Second Level Menu Form

function ValidateSecondLeveleMenu()
{
    //debugger;
    if (!ForceComboItems(document.form1.ddlMainMenu,'First Level Menu'))return false;
     if (!ForceDataEntry (document.form1.txtMenuName,'Menu Name')) return false;
     if(document.form1.chkMenu.checked==true)
     {
        if(document.form1.chkQueryForm.checked==true)
        {
            if (!ForceDataEntry (document.form1.txtQueryPath,'Query Form Name')) return false;
        }
     }
     
}
//----------------------------------------------------------------------------------------------------------------
//# Function to Validate Second Level Menu Form in Edit case

function ValidateScdLvlEditMenu()
{
    //debugger;
     if (!ForceDataEntry (document.form1.txtMenuName,'Menu Name')) return false;
     
}
//----------------------------------------------------------------------------------------------------------------
//# Function to Validate Third Level Menu Form

function ValidateThirdLeveleMenu()
{
    //debugger;
    if (!ForceComboItems(document.form1.ddlMainMenu,'First Level Menu'))return false;
    if (!ForceComboItems(document.form1.ddlSecondLevelMenu,'Second Level Menu'))return false;
    if (!ForceDataEntry (document.form1.txtMenuName,'Menu Name')) return false;
      
        if(document.form1.chkQueryForm.checked==true)
        {
            if (!ForceDataEntry (document.form1.txtQueryPath,'Query Form Name')) return false;
        }
    
}
//----------------------------------------------------------------------------------------------------------------
//# Function to Validate Third Level Menu Form in Edit Case

function ValidateThdLvlMenuEdit()
{
    //debugger;
    if (!ForceDataEntry (document.form1.txtMenuName,'Menu Name')) return false;
}
//----------------------------------------------------------------------------------------------------------------
//# Function to Validate Bookd Details form
function ValidateBooks()
{
//debugger;
    if (!ForceDataEntry (document.form1.txtTitrePropre,'Titre Propre / Title')) return false;
    //if (!ForceDataEntry (document.form1.txtTitreOriginal,'Titre Original')) return false;
//    if (!ForceDataEntry (document.form1.txtResponsablePrincipal,'Author (s) 1')) return false;
//    //if (!ForceDataEntry (document.form1.txta2ndResponsable,'a2nd Responsable')) return false;
//    //if (!ForceDataEntry (document.form1.txta3emeResponsable,'a3eme Responsable')) return false;
//    if (!ForceDataEntry (document.form1.txtEditeur,'Editeur / Publisher')) return false;
//   // if (!ForceComboItems (document.form1.ddlEdition,'Annee Edition / Year')) return false;
    if(document.form1.txtEdition.value!="")
    {
        if (!ForceNumericEntry(document.form1.txtEdition,'Annee Edition / Year')) return false;
    }    
//    if (!ForceDataEntry (document.form1.txtISBN,'ISBN')) return false;
//    if (!ForceDataEntry (document.form1.txtPrixIndicatif,'Prix Indicatif / Price')) return false;
//    //debugger;
   if(trim(document.form1.txtPrixIndicatif.value)!='NC')
    {
    
//        if(trim(document.form1.txtPrixIndicatif.value)=='$' || trim(document.form1.txtPrixIndicatif.value)=='')
//        {
//            alert("You need to enter information for Prix Indicatif / Price");
//            document.form1.txtPrixIndicatif.focus();
//            return false;
//        }
        var val = trim(document.form1.txtPrixIndicatif.value);
        var sign = val.substring(0,1);
//        if(trim(sign)!='$')
//        {
//            alert("First letter must be $ in Prix Indicatif / Price");
//            document.form1.txtPrixIndicatif.focus();
//            return false;
//        }
        var len = val.length;
        //var index = val.indexOf('$');
        //val = val.substring(Number(index)+1,Number(len));
        val = val.substring(0,Number(len));
        if (isNaN(val))
        {
            alert("Prix Indicatif / Price must be a valid number");
            document.form1.txtPrixIndicatif.focus();
            return false;
        }
        
            var value = document.form1.txtPrixIndicatif.value;
            var len = value.length;
            var index = value.indexOf('.');
            if (Number(index)!= -1)
            {
                value = value.substring(Number(index)+1,Number(len));
                len = value.length;
                if (len>2)
                {
                    alert("Prix Indicatif / Price can have value upto 2 decimal places only");
                    document.form1.txtPrixIndicatif.focus();
                    return false;
                }
             }
        /*if(!ForceDecimalEntryNew(val,'Prix Indicatif'))
        {
            document.form1.txtPrixIndicatif.focus();
            return false;
         }*/
    }
    //if(!ForceNumericEntry(document.form1.txtPrixIndicatif,'Prix Indicatif',"T"))return false;
    //if(!isDecimalValue(document.form1.txtPrixIndicatif,'Prix Indicatif'))return false;
    if (!ForceDataEntry (document.form1.txtGenre,'Genre')) return false;
    if (!ForceDataEntry (document.form1.txtNiveau,'Niveaue / Level')) return false;
//    if (!ForceDataEntry (document.form1.txtLangueOrigine,'Langue Origine / Language of Origin')) return false;
//    if (!ForceDataEntry (document.form1.txtNoticeSaisieLe,'Notice Saisie Le / Entered On')) return false;
//    if (!ForceDataEntry (document.form1.txtNoticeSaisiePar,'Notice Saisie Par / Entered By')) return false;
}
//---------------------------------------------------------------------------------------------------------------
//# Function for validating User Creation Form
function ValidateUserCreation()
{
    //debugger;
    var mode = document.form1.hdnMode.value;
    if(mode!="E")
    {
        if (!ForceDataEntry (document.form1.txtUserName,'User Name')) return false;
        if (!ForceDataEntry (document.form1.txtPassword,'Password')) return false;
        var pwd = document.form1.txtPassword.value;
       	var len = pwd.length; 
    	if(Number(len)<8)
        {
    	    alert("Password should be of 8 characters atleast");
    	    document.getElementById("txtPassword").focus;
    	    return false;
    	}
        if (!ForceDataEntry (document.form1.txtCPassword,'Confirm Password')) return false;
        if(document.form1.txtPassword.value != document.form1.txtCPassword.value)
        {
         alert("Password and Confirm Password should be same");
         document.getElementById("txtCPassword").focus;
         return false;
        }
    }
    else if(mode=="E")
    {
        if(document.form1.txtPassword.value!="")
        {
            var pwd = document.form1.txtPassword.value;
        	var len = pwd.length; 
        	if(Number(len)<8)
            {
         	    alert("Password should be of 8 characters atleast");
        	    document.getElementById("txtPassword").focus;
        	    return false;
        	}
            if (!ForceDataEntry (document.form1.txtCPassword,'Confirm Password')) return false;
            if(document.form1.txtPassword.value != document.form1.txtCPassword.value)
            {
                alert("Password and Confirm Password should be same");
                document.getElementById("txtCPassword").focus;
                return false;
            }
        }
    }
}
//---------------------------------------------------------------------------------------------------------------
//# Function for validating User Creation Form in Edit Case
function ValidateUserCreationEdit()
{

    if (!ForceDataEntry (document.form1.txtPassword,'Password')) return false;
    var pwd = document.form1.txtPassword.value;
    	var len = pwd.length; 
    	if(Number(len)<8)
    	{
    	    alert("Password should be of 8 characters atleast");
    	    document.getElementById("txtPassword").focus;
    	    return false;
    	}
    if (!ForceDataEntry (document.form1.txtCPassword,'Confirm Password')) return false;
    if(document.form1.txtPassword.value != document.form1.txtCPassword.value)
    {
        alert("Password and Confirm Password should be same");
        document.getElementById("txtCPassword").focus;
        return false;
    }
}
//---------------------------------------------------------------------------------------------------------------
//# Function to Validate Upload News letter
function ValidateNewsLetter()
{
  //* -- Validation for Upload News Letter
  //debugger;
    elem2  = document.getElementById("htmUploadNewsLetter");
     h1_Sw=document.getElementById("lblLetterImage").innerText;
    //* -- Validation for Upload Software
	if (h1_Sw.length==0)
	{
	       if(trimAll(elem2.value) == "")
		   {	
		    alert("Please browse a Image to upload.");
			elem2.focus();
			return false;
		}
    }
}
//----------------------------------------------------------------------------------------------------------------
//& Function to validate Basic Search 
function ValidateBasicSearch()
{
    //* -- Validation for Search Text
   if (!ForceDataEntry (document.getElementById("FrmSearchControl1_txtsearch"),'Book Title to search')) return false;
}
//----------------------------------------------------------------------------------------------------------------
//& Function to validate Advance Search 
/*function ValidateAdvanceSearch()
{
    //debugger;
   //& Validation for search dropdown
   if(!ForceComboItems((document.frmSearch1.ddlField),'Search Field')) return false;
    //& -- Validation for Search Text
    if(Number(document.frmSearch1.ddlField.value)< 4)
    {
        if (!ForceDataEntry ((document.frmSearch1.txtsearch),'text to search')) return false;
    }
   
}*/
//----------------------------------------------------------------------------------------------------------------
//$ Function to Disable search text field
function DisableText()
{   
    //debugger;     
    if(Number(document.frmSearch1.ddlField.value)==4)
    {
        document.frmSearch1.txtsearch.disabled=true;
        document.frmSearch1.txtsearch.value="";
    }
    else
    {
     document.frmSearch1.txtsearch.disabled=false;
    }
}
//----------------------------------------------------------------------------------------------------------------

//$ Function to Validate QueryForm
function ValidateQueryForm()
{
    if (!ForceComboItems (document.frmQueryform.ddlSalutaion,'Salutation Mark')) return false;
    if (!ForceDataEntry(document.frmQueryform.txtFirstName,'First Name')) return false;
    if (!ForceDataEntry(document.frmQueryform.txtLastName,'Last Name')) return false;
    if (!ForceDataEntry(document.frmQueryform.txtAddress1,'Address1')) return false;
    if (!ForceNumericEntry(document.frmQueryform.txtPhone,'Phone','T')) return false;
    if (!ForceNumericEntry(document.frmQueryform.txtMobile,'Mobile','F')) return false;
    if (!IsEmailValid(document.frmQueryform.txtEmail,'Email','T')) return false;
    if (!ForceDataEntry(document.frmQueryform.txtComments,'Comments')) return false;
}

//------------------------------------------------------------------------------------------------------------------
//$ Function to Validate UI Newsletter
function ValidateUINewsletter()
{
    if (!IsEmailValid(document.frmUINewsletter.txtemail,'Email-Id','T')) return false;
}

//------------------------------------------------------------------------------------------------------------------

function showValue()
{
       myregexp = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/
        mymatch = myregexp.exec(document.frmAddPressRelease.txtPublishDate.value)
        if(mymatch==null)
        {
            alert('please Enter date in dd/mm/yyyy format');
            document.frmAddPressRelease.txtPublishDate.focus();
            return false;
        }
        
	  else 
        return true;
 }
 //================================================================================================================
 //^ ---------------- VALIDATE Add Events Form ----------------------------------------
function ValidateAddEventsForm()
{
    if (!ForceComboItems(document.AddEventsForm.ddlYear, 'Event Year')) return false;
   
    if (!ForceDataEntry(document.AddEventsForm.txtEventName, 'Event Name')) return false;
     if (!ForceDataEntry(document.AddEventsForm.txtEventDate,'Event Date'))return false;
    if (!ForceDataEntry(document.AddEventsForm.txtLocation, 'Location'))return false;
}
//=================================================================================================================

function ValidateEventOnHome()
{
    if (document.getElementById("hlEventImage")==null)
    {
        if(document.getElementById("htmUploadEventImg").value=='')
        {
            alert("You need to enter information for Upload Event Image");
            document.getElementById("htmUploadEventImg").focus();
            return false;
        }
     }
     if (!ForceDataEntry(document.EventonHomeForm.txtEventId,'Event ID'))return false;
     if (!ForceNumericEntry(document.EventonHomeForm.txtEventId,'Event ID','F')) return false;
     
}

//=================================================================================================================

function ValidateLeftImageOnHome()
{
    if (document.getElementById("hlLeftImage")==null)
    {
        if(document.getElementById("htmUploadLeftImg").value=='')
        {
            alert("You need to enter information for Upload Left Image");
            document.getElementById("htmUploadLeftImg").focus();
            return false;
        }
     }
     if (!ForceDataEntry(document.LeftImageonHomeForm.txtLink,'Image Link'))return false;
      
}
//=================================================================================================================

function ValidatePage()
{
//debugger;
    if (!ForceDataEntry(document.form1.txtHeading, 'Heading')) return false;
    if(document.getElementById("hdnMode").value!='E')
    {
    if(document.getElementById("htmlUploadPage").value=='')
    {
        alert("You need to enter information for Upload Page");
        document.getElementById("htmlUploadPage").focus();
        return false;
    }
    }
}
//* Check Fir in News
function FricInNews()
{
//debugger;
	chkNews=document.getElementById("chkNews") ;
	if(chkNews.checked)
	{
//		document.getElementById("txtlink").Enabled=false;
        document.getElementById("txtLink").disabled=true;
	    document.getElementById("Editor").Enabled=false;
	}
	else
	{	
    	document.getElementById("Editor").Enabled=true;
		//document.getElementById("txtlink").Enabled=true;
        document.getElementById("txtLink").disabled=false;
	}
}

//* Function to Validate Contact Us

//$ Function to Validate QueryForm
function ValidateContacts()
{
    if (!ForceDataEntry(document.form1.txtFirstName,'First Name')) return false;
    
   if (!IsEmailValid(document.form1.txtEmail,'Email','T')) return false;
 
    if (!ForceDataEntry(document.form1.txtComments,'Message')) return false;
    if(document.form1.txtComments.value.length >255)
    {
        alert("Message could not exceed 255 characters.");
        return false; 
    }
}

//* ---------------- VALIDATE Exhibition ----------------------------------------
function ValidateExhibition()
{
     if (!ForceDataEntry(document.AddExhibition.txtExhibitionName, 'Exhibition Name')) return false;
     if (!ForceNumericEntry(document.AddExhibition.txtExample,'Example','T')) return false;
     if (!ForceDataEntry(document.AddExhibition.txtLanguage,'Language'))return false;
     if (!ForceDataEntry(document.AddExhibition.txtDescription, 'Description'))return false;
     if(document.AddExhibition.txtDescription.value.length >255)
     {
        alert("Description could not exceed 500 characters.");
        return false; 
    }
}

//# Function to Validate Bookd Details form
function ValidateSearchBooks()
{
//debugger;
 
    var count=0;
        if(document.form1.txtTitrePropre.value!="")
            {
            count=count+1;
            }
            
        if(document.form1.txtTitreOriginal.value!="")
            {
            count=count+1;
            }    
        if(document.form1.txtResponsablePrincipal.value!="")
            {
            count=count+1;
            }   
        if(document.form1.txta2ndResponsable.value!="")
            {
            count=count+1;
            }   
        if(document.form1.txta3emeResponsable.value!="")
            {
            count=count+1;
            } 
            
       if(document.form1.txtEditeur.value!="")
            {
            count=count+1;
            }
            
        if(document.form1.txtEdition.value!="")
            {
            count=count+1;
            }    
        if(document.form1.txtISBN.value!="")
            {
            count=count+1;
            }   
        if(document.form1.txtPrixIndicatif.value!="")
            {
            count=count+1;
            }   
        if(document.form1.txtGenre.value!="")
            {
            count=count+1;
            }  
         if(document.form1.txtNiveau.value!="")
            {
            count=count+1;
            }
            
        if(document.form1.txtLangueOrigine.value!="")
            {
            count=count+1;
            }    
//        if(document.form1.txtNoticeSaisieLe.value!="")
//            {
//            count=count+1;
//            }   
//        if(document.form1.txtNoticeSaisiePar.value!="")
//            {
//            count=count+1;
//            }   
//        
        if(count>1)
            {
                alert("Please enter in only one Field");
                return false;
            }  
        else if(count==0)
            {
                alert("Please enter in one Field atleast");
                return false;
            }                                   
                    
    if (!ForceNumericEntry(document.form1.txtEdition,'Annee Edition / Year','F')) return false;
  
    if(trim(document.form1.txtPrixIndicatif.value)!='')
    {
        if (!ForceDecimalEntry(document.form1.txtPrixIndicatif,'Indicatif / Price','F')) return false;
    }
  
}

function ValidateSearchBooksFrontEnd()
{
      if (!ForceComboItems (document.SearchBook.ddlSearchBooks,'Book Search Criteria')) return false;
      if (!ForceDataEntry(document.SearchBook.txtSearchBooks, 'Book Details')) return false;
      if(document.SearchBook.txtSearchBooks.value.length<4)
                {
                    alert("You need to enter atleast 4 characters to search.");
                    return false; 
                }
   
}