﻿// Function Name - Parameters - Return Value - Funcationality or allowed fomat of value

// ChangeToCaps - Field - returns the caps value of content
// CheckFloatValue - Field,Label,ValueAfterFraction  - True/False - Checks Floating value with number of decimal places
// CheckLength - Field,Label,MinimumLength,MaximumLength - True/False - Checks Minimum and Maximum Length of field
// CheckOnlyAlpha - Field,Label - True/False - a-z,A-Z  
// CheckPhoneNumber - Field,Label - True/False - 0-9, '-' ','
// CheckForAlpha - Field,Label - True/False - a-z,A-Z,' '  '.'
// CheckForEmpty - Field,Label,True/False - True/False
// CheckWithCurrentDate - DateField,MonthField,YearField - True/False - True when the Date Greater than or equal to Current date
// CheckForNumericWithLength - Field,Label, Allowed Length of Field - True/False - Allow only numeric of exact length length
// CheckForNumeric - Field,Label, True/False - Allow only numeric 
// CheckForWholeNumber=Field,Label,True/False-Number without decimal
// trim - FieldValue - FieldValue - Remove the extra space in value
// emailCheck - FieldValue - True/False - Check ffff@ff.co format of email id
// CheckforZero-Field,Lable,True/False-check whether zero is entered
// CompareSTDAndPhone-stdField,PhoneField-compare whether std entered and pnone number not enterred and viceversa
// CheckForEmptyCombo-Field,Lable,True/False-check whether items are selected from combo

var fullImgURL = "";
// changes the content into caps
function ChangeToCaps(objField)
{
	var Value
	Value=objField.value
	Value=Value.toUpperCase();
	objField.value=Value;
}

// check float value with number of decimal places
function CheckFloatValue(objField,strLabel,intFractionLength)
{
	var intDotCount=0
	var intDotIndex=0
	var intValueAfterDot
	var intLength
	var intValue
	var intLoop
	var ch
	
	intValue=objField.value;
	intLength=intValue.length
	for(intLoop=0;intLoop<intLength;intLoop++)
	{
		ch= intValue.charAt(intLoop);
		if(!((ch>='0' && ch<='9') || (ch=='.')))
		{
			alert("Enter only Numeric values in "+strLabel)
			objField.focus();
			return false
		}
		if(ch=='.')
		{
			if(intDotCount<1)
			{
				intDotCount=intDotCount+1
				intDotIndex=intLoop
				intValueAfterDot=intValue.substring(intDotIndex,intLength)
				if(intFractionLength!="")
				{
					if(((intValueAfterDot.length-1)>intFractionLength))
					{
						alert("Only "+intFractionLength+" decimal places are allowed in "+strLabel)
						objField.focus();
						return false;
					}
				}
			}
			else
			{	
				alert("Float Value can have only one . in "+strLabel)
				objField.focus();
				return false;
			}
		}
	}
	return true
}



// Check for only alphabet
function CheckOnlyAlpha(objField,strLabel)
{
	// Allows only alphabets
	var strValue
	var intLength
	var Loop
	
	strValue	=	objField.value;
	intLength	=	strValue.length;
	for(Loop=0;Loop<intLength;Loop++)
	{
		ch	=	strValue.charAt(Loop)
		if(!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z")))
		{
			alert("The Characters allowed in "+strLabel+" are A-Z, a-z")
			objField.focus();
			return false;
		}
	}	
	return true;
}


// Check Phonenumber and Fax Number
function CheckPhoneNumber(objField,strLabel)
{
	// check for numeric and the allowed special characters are '-',','
	var strValue
	var intLength
	var Loop
	
	strValue	=	objField.value;
	intLength	=	strValue.length;
	ch=strValue.charAt(0)
	if (!(ch>="0" && ch<="9"))
	{
		alert("The First character of "+strLabel+" must be number")
		objField.focus();
		return false
	}
	ch	=	strValue.charAt(intLength-1)
	if(!(ch>="0" && ch<="9"))
	{
		alert("The Last charcter of "+strLabel+" must be number")
		objField.focus();
		return false
	}
	for(Loop=1;Loop<intLength-1;Loop++)
	{
		ch	=	strValue.charAt(Loop)
		if(!((ch>="0" && ch<="9")))
		{
			alert("The Characters allowed in "+strLabel+" are 0-9")
			objField.focus();
			return false;
		}
	}
	return true;	
}



// Check for Non numeric fields
function CheckForAlpha(objField,strLabel)
{
 
  // This funcation allow only a-z, A-Z,.," " 
	var strValue		
	var intLength
	var Loop
	
	strValue	=	objField.value;
	intLength	=	strValue.length;

	for(Loop=0;Loop<intLength;Loop++)
	{
		ch	=	strValue.charAt(Loop)
		if(!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z") || (ch==" ") || (ch==".")))
		{
			alert("The Characters allowed in "+strLabel+" are A-Z, a-z, . ' '")
			objField.focus();
			return false;
		}
	}	
	return true;
}


//Check for empty
function CheckForEmpty(objField,strLabel,bMandatory)
{

    var Value;

	Value	=	objField.value;
	if (bMandatory==true)
	{
		if(Value=="")
		{
			alert("Please Enter the "+strLabel);
			objField.focus();
			return false;
		}
	}
	return true;
}


// Checking the date with current date
function CheckWithCurrentDate(objDate,objMonth,objYear)
{
	
	// receives the controls
	// Only the greaterthan or equal value is allowed not the lesser date
	// Checks the year, month and date separately	
	
	var strDate		=	objDate.value
	var strMonth	=	objMonth.value
	var strYear		=	objYear.value
	var sysDate
	var sysMonth
	var sysYear
	var CurrentDate	=	new Date();
	var bFlag				=	true;
	sysDate					=	CurrentDate.getDate();
	sysMonth				=	CurrentDate.getMonth()+1;
	sysYear					=	CurrentDate.getYear();
	
	// Check whether the year is less the current year or not
			if (strYear<sysYear)
			{
				bFlag	=	false;
				alert("Enter Year greater that currentYear");
				objYear.focus();
			}
	// check whether the month is less the current month or not		
			if(bFlag==true)
			{
				if(strMonth<sysMonth)
				{
					bFlag	=	false;
					alert("Enter month greater than current month")
					objMonth.focus();
				}
			}
	// check whether the date is less than the current date or not 
			if(bFlag==true)
			{
				if(strDate<sysDate)
				{
					bFlag	=	false;
					alert("Enter date greater than current date")
					objDate.focus();
				}
			}
			if(bFlag==true)
				return true;
			else
				return false;
	
}


//Checking numeric field
function CheckForNumericWithLength(objField,strLabel,intExactSize)
{
	
	// Check for the numeric value
	// The exact length of the value is got as parameter
	// whent the exact size parameter is empty then the zero length is allowed
	
	var intLength;
	var intValue;
	var bFlag	=	true;
	var intLoop
	var ch
	intValue	=	objField.value;
	intLength	=	intValue.length;
	if (intExactSize!="")
	{
		if (intLength!=intExactSize)
		{
			alert("The Length of "+strLabel+" value must be "+intExactSize)
			objField.focus();
			return false;
		}
	}
	
	for (intLoop=0;intLoop<intLength;intLoop++)
	{
		ch	=	intValue.charAt(intLoop)
		if(!(ch>='0' && ch<='9'))
		{
			alert("Enter numbers in "+strLabel);
			objField.focus();
			return false;
		}
	}
	return true;
}


//Checking numeric field without length
function CheckForNumeric(objField,strLabel,bMandatory)
{
	
	// Check for the numeric value
	// The exact length of the value is got as parameter
	// whent the exact size parameter is empty then the zero length is allowed
	
	var intLength;
	var intValue;
	var bFlag	=	true;
	var intLoop
	var ch
	intValue	=	objField.value;
	intLength	=	intValue.length;
	
	for (intLoop=0;intLoop<intLength;intLoop++)
	{
		ch	=	intValue.charAt(intLoop)
		if(!((ch>='0' && ch<='9')))
		{
			alert("Characters allowed are 0-9 in "+strLabel)
			objField.focus();
			return false
		}
	}
	return true;
}



//Check for whole number-without decimal place
function CheckForWholeNumeric(objField,strLabel,intExactSize)
{
	
	var intLength;
	var intValue;
	var bFlag	=	true;
	var intLoop
	var ch
	intValue	=	objField.value;
	intLength	=	intValue.length;
		
	for (intLoop=0;intLoop<intLength;intLoop++)
	{
		ch	=	intValue.charAt(intLoop)
		if((ch=="."))
		{
			
			alert("Please enter without decimal in "+strLabel);
			objField.focus();
			return false;
		}
	}
	return true;
}



//Checking Null Value-trim
function trim(inputString)
 {
   
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch				= retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue	=	retValue.substring(1, retValue.length);
      ch				=	retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}


//Url Validate
function isURL(url) {
   var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
  return urlPattern.test(url.toLowerCase());

}


function checkURL(field) {
  if (!isURL(field.value))
  {
    alert('Invalid URL!');
    field.focus();
    field.select();
	return false
  }
  else
  	return true
}

//Check for Zero
function CheckForZero(objField,strLabel,bMandatory)
{
	var Value;
	Value	=	objField.value;
	
	if (bMandatory==true)
	{
		if(Value=="0")
		{
			alert("Please enter value greater than Zero")
			objField.focus();
			return false;
		}
	}
	return true;
}


//Compare stdcode and phone number
function CompareISTDAndSTDAndPhone(objISTDField,objSTDField,objPhoneField)
{
		// When STD code is entered then number is must
		// When STD code is not empty but the phone field is filled
		
		
		if(objSTDField.value!="" && objPhoneField.value=="" && objISTDField.value=="")
		{
			alert("Enter Phone Number and ISTD Code")
			objPhoneField.focus();
			return false
		}
		
		// When the STD code is empty but phone filed is empty
		if(objSTDField.value=="" && objPhoneField.value!="" && objISTDField.value=="")
		{
			alert("Enter STD Code and ISTD Code")
			objSTDField.focus();
			return false
		}
		
		if(objSTDField.value=="" && objPhoneField.value=="" && objISTDField.value!="")
		{
			alert("Enter STD Number and Phone Number")
			objISTDField.focus();
			return false
		}
		return true
}

	
//Check for emptyCombo
function CheckForEmptyCombo(objField,strLabel,bMandatory)
{
	var Value;
	Value	=	objField.value;
	if (bMandatory==true)
	{
		if(objField.selectedIndex==0)
		{
			alert("Please choose the "+strLabel)
			objField.focus();
			return false;
		}
	}
	return true;
}	


//Check for email
function CheckForEmail(objField,strLabel,bMandatory)
{
	var strValue;
	strValue = objField.value;
	if (bMandatory==true)
	{
		if(strValue =="")  
		{
			alert("Please Enter the "+strLabel)
			objField.focus();
			return false;
		}
		else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strValue)))
		{
			alert("Please Enter valid "+strLabel)
			objField.focus();
			return false;
		}
	}
	return true;
}


// Check  Maximum length of field
function CheckMaxLength(objField,strLabel,intMaxLen,bMandatory)
{
	var strValue;
	var intLength;
	
	strValue = objField.value;
	intLength = strValue.length;
	
	if (bMandatory==true)
	{
		if(strValue =="")  
		{
			alert("Please Enter the "+strLabel)
			objField.focus();
			return false;
		}
		else if (intMaxLen!="")
		{
			if(intLength>intMaxLen)
			{
				alert("Maximum Length allowed for "+strLabel+" is "+intMaxLen)
				objField.focus();
				return false;
			}
		}
	}
	return true;
}

// Check Minimum length of field
function CheckMinLength(objField,strLabel,intMinLen,bMandatory)
{
	var strValue;
	var intLength;
	
	strValue = objField.value;
	intLength = strValue.length;
	
	if (bMandatory==true)
	{
		if(strValue =="")  
		{
			alert("Please Enter the "+strLabel)
			objField.focus();
			return false;
		}
		else if (intMinLen!="")
		{		
			if(intLength < intMinLen)
			{
				alert("Minimum Length of "+strLabel+" must be "+intMinLen)
				objField.focus();
				return false;
			}
		}
	}
	return true;
}

//Check the valid Date
function CheckValidDate(objDay,objMonth,objYear)
{
	var DateVal = objMonth + "/" + objDay + "/" + objYear;
	var dt = new Date(DateVal);
	if(dt.getDate()!=objDay)
	{
		alert("Please select valid date");
		return false;
	}
	else if(dt.getMonth()!=objMonth-1)
	{
		alert("Please select valid date");
		return false;
	}
	else if(dt.getFullYear()!=objYear)
	{
		alert("Please select valid date");
		return false;
	}
	return true;
}
//To Enter Only the Numbers
 function CheckNumeric(e,obj)
        {
        
        var str = obj.value;
            var key //= (window.event) ? event.keyCode : e.which;
             if (window.event)
            key = event.keyCode
            else
            key = e.which
//            alert(key)
            // Was key that was pressed a numeric character (0-9) or backspace (8) or tab?
            if (key > 47 && key < 58 || key == 8 || key == 0)
            {
             if((key == 48) && (str < 1))
             {
            if (window.event)
                event.keyCode=null;
            else
                 e.preventDefault();
              }
             return; 
             }// if so, do nothing
            else 
             // otherwise, discard character

            if (window.event) //IE
             window.event.returnValue = null;     else //Firefox
            e.preventDefault();
            
           
        }
       
/*
 var emailPattern = /^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.
(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-
z])\b/;
*/

 function CheckisFloat(obj,evt)
{
    var periodPos=obj.value.toString().indexOf('.');
        var key=String.fromCharCode(((evt.which==null)?evt.keyCode:evt.which));

        if (key=='.' && periodPos==-1)
        {
         return;
         }
        else  
        {
       
         var charCode = (evt.which) ? evt.which : event.keyCode;
         
         if (charCode > 31 && (charCode < 48 || charCode > 57))
          {

          try
          {
          evt.preventDefault();                 
          }
          catch(e)
          {
          event.returnValue=false;
          }
          }
          else
          {
           if(periodPos>0)
          {

            var val= obj.value.split(".");
            var charCode = (evt.which) ? evt.which : event.keyCode;
            if( charCode==8)
            return true;
            if(val[1].length >1)
            {
            try
          {
          evt.preventDefault();                 
          }
          catch(e)
          {
          event.returnValue=false;
          }
            return false;
            }
          }

          }

          }    
 
}

//Check for Comparing (Compare Validator)
function CheckForCompare(objFieldCompare,objFieldValidate,strLabel,bMandatory)
{
   
	var strValueCompare;
	var strValueValidate;
	strValueCompare = objFieldCompare.value;
	strValueValidate = objFieldValidate.value;
    if (bMandatory==true)
	{
        if(strValueCompare.toLowerCase() != strValueValidate.toLowerCase())  
		{
			alert(strLabel);
			objFieldValidate.focus();
			return false;
		}
	}
	return true;
}

// Check the no of tags.
function CheckTagsCount(objTags)
{
    //alert(objTags.value);int a=0;
    var strTagsArray = objTags.value.split(",");
    if(strTagsArray.length<6)
        return true;
    else
    {
        alert("Only Five Tags are allowed");
        objTags.focus();
        return false;
    }
}
//Check  for http
function isWebsite(obj)
{
    if (obj.value!="")
    {
    var fieldval = obj.value;
    var regex = new RegExp ("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&amp;=]*)?");
    return regex.test(fieldval);
    }
    else
    return true;
}

//Check for numeric in keypress -- cart
function isNumeric(evt)
{
    
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if( charCode==8)
      return true;
     var key=getKey(evt);
     if ((('1234567890').indexOf(key)==-1))
      try{evt.preventDefault();}catch(e){event.returnValue=false;}
}

function getKey(evt)
{
	return String.fromCharCode(((evt.which==null)?evt.keyCode:evt.which));
}
//Check for Email -- cart
function isEmail(obj)
{
    if (obj.value!="")
    {  
        var fieldval = obj.value;
        var regex = new RegExp (/^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i);
        return regex.test(fieldval); 
    }
    else
        return false;
}
//check for the description
function limitTextarea(textarea, maxlength,evt)
{

   alert("Hi");
   if (textarea.value.length >= maxlength)
   {
       try{
       if (key!=8) 
       evt.preventDefault();
       }
       catch(e)
       {         
           event.returnValue=false;
       }
   }

}

function DoKeyPress(control,evt)
 {
 
      maxLength = control.attributes["maxLength"].value;
      
      value = control.value;
      if(maxLength && value.length > maxLength-1)
      {
       try{evt.preventDefault();}catch(e){event.returnValue = false;}
       maxLength = parseInt(maxLength);
      }
 }
 

 
 // Cancel default behavior
 function DoBeforePaste(control,evt)
 {
      maxLength = control.attributes["maxLength"].value;
      if(maxLength)
      {
       try{evt.preventDefault();}catch(e){event.returnValue = false;}
      }
 }
 
 // Cancel default behavior and create a new paste routine
 function DoPaste(control,evt)
 {
      maxLength = control.attributes["maxLength"].value;
      value = control.value;
      if(maxLength)
      {
       try{evt.preventDefault();}catch(e){event.returnValue = false;}
       maxLength = parseInt(maxLength);
       var oTR = control.document.selection.createRange();
       var iInsertLength = maxLength - value.length + oTR.text.length;
       var sData = clipboardData.getData("Text").substr(0,iInsertLength);
       oTR.text = sData;
      }
 }
 

//Paste with numeric --cart
function doPasteOnlyWithNumeric(control,evt){
    
  var value=clipboardData.getData("Text");

  var sData="";
  for(var index=0;index<value.length;index++)
  {
   var character=value.substr(index,1);

   if ("123456789".indexOf(character) > -1) 
    sData += character;

  var oTR = control.document.selection.createRange();
  oTR.text = sData;
  clipboardData.setData("Text",sData)
 
 }
 }
 
 function PrintDoc() {
    if (window.print) {

        window.print() ;  

    } 
    else {

        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  

    }
}
function GetMaxLength(targetField)
{
return targetField.exMaxLen;
}
//Added By Kavitha M
//
// Limit the text input in the specified field.
//
function LimitInput(targetField, sourceEvent)
{
    
    var isPermittedKeystroke;
    var enteredKeystroke;
    var maximumFieldLength;
    var currentFieldLength;
    var inputAllowed = true;
    var selectionLength = parseInt(GetSelectionLength(targetField));
    
    if ( GetMaxLength(targetField) != null )
    {
     // Get the current and maximum field length
     currentFieldLength = parseInt(targetField.value.length);
        maximumFieldLength = parseInt(GetMaxLength(targetField));

        // Allow non-printing, arrow and delete keys
enteredKeystroke = window.event ? sourceEvent.keyCode : sourceEvent.which;
        isPermittedKeystroke = ((enteredKeystroke < 32)                                // Non printing
                     ||(enteredKeystroke >= 33 && enteredKeystroke <= 40)    // Page Up, Down, Home, End, Arrow
                     ||(enteredKeystroke == 46))                            // Delete

        // Decide whether the keystroke is allowed to proceed
        if ( !isPermittedKeystroke )
        {
            if ( ( currentFieldLength - selectionLength ) >= maximumFieldLength )
            {
                inputAllowed = false;
            }
        }
        
        // Force a trim of the textarea contents if necessary
        if ( currentFieldLength > maximumFieldLength )
        {
            targetField.value = targetField.value.substring(0, maximumFieldLength)
        }
    }
    
    sourceEvent.returnValue = inputAllowed;
    return (inputAllowed);
}

//
// Limit the text input in the specified field.
//
function LimitPaste(targetField, sourceEvent)
{
    var clipboardText;
    var resultantLength;
    var maximumFieldLength;
    var currentFieldLength;
    var pasteAllowed = true;
    var selectionLength = GetSelectionLength(targetField);

    if ( GetMaxLength(targetField) != null )
    {
     // Get the current and maximum field length
     currentFieldLength = parseInt(targetField.value.length);
        maximumFieldLength = parseInt(GetMaxLength(targetField));

        clipboardText = window.clipboardData.getData("Text");
        resultantLength = currentFieldLength + clipboardText.length - selectionLength;
        if ( resultantLength > maximumFieldLength)
        {
            pasteAllowed = false;
        }    
    }    
    
    sourceEvent.returnValue = pasteAllowed;
    return (pasteAllowed);
}

//
// Returns the number of selected characters in
// the specified element
//
function GetSelectionLength(targetField)
{

    if ( targetField.selectionStart == undefined )
    {
        return document.selection.createRange().text.length;
    }
    else
    {
        return (targetField.selectionEnd - targetField.selectionStart);
    }
} /* This sample code is provided by Annsa Ltd. for information only. */ // Simple helper to return the "exMaxLen" attribute for // the specified field. Using "getAttribute" won't work // with Firefox. function GetMaxLength(targetField) { return targetField.exMaxLen; } // // Limit the text input in the specified field. // function LimitInput(targetField, sourceEvent) { var isPermittedKeystroke; var enteredKeystroke; var maximumFieldLength; var currentFieldLength; var inputAllowed = true; var selectionLength = parseInt(GetSelectionLength(targetField)); if ( GetMaxLength(targetField) != null ) { // Get the current and maximum field length currentFieldLength = parseInt(targetField.value.length); maximumFieldLength = parseInt(GetMaxLength(targetField)); // Allow non-printing, arrow and delete keys enteredKeystroke = window.event ? sourceEvent.keyCode : sourceEvent.which; isPermittedKeystroke = ((enteredKeystroke < 32) // Non printing ||(enteredKeystroke >= 33 && enteredKeystroke <= 40) // Page Up, Down, Home, End, Arrow ||(enteredKeystroke == 46)) // Delete // Decide whether the keystroke is allowed to proceed if ( !isPermittedKeystroke ) { if ( ( currentFieldLength - selectionLength ) >= maximumFieldLength ) { inputAllowed = false; } } // Force a trim of the textarea contents if necessary if ( currentFieldLength > maximumFieldLength ) { targetField.value = targetField.value.substring(0, maximumFieldLength) } } sourceEvent.returnValue = inputAllowed; return (inputAllowed); } // // Limit the text input in the specified field. // function LimitPaste(targetField, sourceEvent) { var clipboardText; var resultantLength; var maximumFieldLength; var currentFieldLength; var pasteAllowed = true; var selectionLength = GetSelectionLength(targetField); if ( GetMaxLength(targetField) != null ) { // Get the current and maximum field length currentFieldLength = parseInt(targetField.value.length); maximumFieldLength = parseInt(GetMaxLength(targetField)); clipboardText = window.clipboardData.getData("Text"); resultantLength = currentFieldLength + clipboardText.length - selectionLength; if ( resultantLength > maximumFieldLength) { pasteAllowed = false; } } sourceEvent.returnValue = pasteAllowed; return (pasteAllowed); } // // Returns the number of selected characters in // the specified element // function GetSelectionLength(targetField) { if ( targetField.selectionStart == undefined ) { return document.selection.createRange().text.length; } else { return (targetField.selectionEnd - targetField.selectionStart); } }

 function isNumber(input)
{
    if(input.value.length > 0 && !input.value.match(/^[0-9]+$/g))
    {
    input.value = input.value.replace(/[^0-9]*/g,'');
    }
}


		 
function CheckForNames(objField,strLabel)
{
 
  // This funcation allow only a-z, A-Z,.," " 
	var strValue		
	var intLength
	var Loop
	
	strValue	=	trim(objField.value);
	intLength	=	strValue.length;

	for(Loop=0;Loop<intLength;Loop++)
	{
		ch	=	strValue.charAt(Loop)
		if(!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z") || (ch==" ") || (ch==".")))
		{
			alert("The Characters allowed in "+strLabel+" are A-Z, a-z, . ' '")
			objField.focus();
			return false;
		}
	}	
	return true;
}

// Only for User Name creation
function isAlphaNumeric(obj,lblObj)
{
            var first;
            var next;
            var val;
            var lblObj;
            //alert("FIrst"+trim(obj.value));
            val = obj.value;
            val = trim(val);
            //alter("Second"+val);
            //lblObj = document.getElementById("<%= lblCheckAvailability.ClientID %>");
            if (val.match(/^[a-zA-Z]{1}(\s|[a-zA-Z0-9._])*$/))
            {
                first = val.indexOf("_",0);
                next = val.indexOf("_",(first+1));
                 if(next!=null)
                 {
                    if((next-first)==1)
                    {
                        alert("No consecutive underscores allowed in username");
                        obj.focus();
                        lblObj.style.display = "none";
                        return false;
                    }
                 }
                 first = val.indexOf(".",0);
                 next = val.indexOf(".",(first+1));
                 if(next!=null)
                 {
                    if((next-first)==1)
                    {
                        alert("No consecutive dots allowed in username");
                        obj.focus();
                        lblObj.style.display = "none";
                        return false;
                    }
                 }
                return true;
            }
            else
            {
                 alert("Please enter valid user id");
                 obj.focus();
                 lblObj.style.display = "none";
                 return false;
            } 
}

function SetFocus(idNo)
{
    var currentObj = document.getElementById("topMenu");
    var tmp;
    var i;
    for(i=0;i<9;i++)
    {
        tmp = document.getElementsByTagName('li')[i]
        if(i==idNo)
        {
            tmp.className = "current";
            //alert(tmp.id);
        }
        else
        {
            tmp.className = "";
        }
    }
}
        
        /* Notification Box*/
          function closeBox(toClose) {
          
    document.getElementById(toClose).style.display = "none";
   
}

function loadMsg(msgClass) {

    msg = document.getElementsByTagName("div");
    for (i=0; i<msg.length; i++) {
        if(msg[i].className == msgClass) {
            if(document.cookie.indexOf(msg[i].id) == -1) {
                msg[i].style.display = "block";
            }
        }
    }

}

// function to validate Decimal number

function extractNumber(obj, decimalPlaces, allowNegative)
{
	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 blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	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);
}

/* added by Priya Y
   Date : 26/12/2008
*/

// Function to check for telephone and fax 
function ValidatePhone(strPhone)
{
        //var regPhone = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
               var regPhone = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
        
        if (!strPhone.value.match(regPhone))
        {
            strPhone.value = strPhone.value.replace(/[^0-9 ()+-]/g,'')    
        }
}

function replaceURLWithHTMLLinks(text) 
{
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
    return text.value.replace(exp,''); 
}


//function ValidateWebsite(obj)
//{
//    var regex = new RegExp ("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&amp;=]*)?");
//    if(!obj.value.match(regex))
//    {
//        return obj.value.replace(http(s)?:/\/([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&amp;=]*)?,'');
//    }
//}

// To Hide Notification Box
//function HideControl(elementId)
//{
//     //alert("I am Working");
//     setTimeout('HidePartnerNotification('+elementId+')', 5000)
//}
//function HidePartnerNotification(elementId)
//{
//     //alert(elementId.id);
//     //var notification = document.getElementById(elementId.id);
//     //alert(notification.id);
//     elementId.style.display = 'none';
//}  


    closeErrorWindow = function(sectionId)
    {    
        var sectionControl  =document.getElementById (sectionId);
        var controlName = sectionId + "_ErrorBlock";
        var errorBlock = document.getElementById(controlName);
        if (errorBlock && errorBlock.tagName) {
            errorBlock.innerHTML  = "";
        }
        sectionControl.removeChild(errorBlock)
    }
    
    showErrors = function(sectionId,errorObjects)
    {    
        var blockId  = sectionId + "_ErrorBlock";
    	var errorBlock = document.createElement("div");
    	var sectionControl  =document.getElementById (sectionId);
    	errorBlock.id = blockId;
    	errorBlock.className = "error";
    	//var message = "";
    	var message = "<div class=\"error-window-close\" onclick=\"javascript:closeErrorWindow('"+ sectionId +"');\">";
    	//message += "<a href=\"javascript:closeErrorWindow('"+ sectionId +"');\" title=\"Close\" id=\"lnkClose\">X</a>";
    	message += "</div>";
    	if (errorObjects.length){
    	    message += "<ul>";
    	    for (var i=0,iL=errorObjects.length;i<iL;i++) {
				message += "<li><label"
				if (errorObjects[i].control) message  += " for=\""+errorObjects[i].control+"\"";
				message += ">"+errorObjects[i].message+"</label></li>";
			}
			message  += "</ul>";
			errorBlock.innerHTML  = message;
	        errorBlock.style.display = "";
    	}else errorBlock.style.display = "none";
    
        if (sectionControl && sectionControl.tagName) {
            if( document.getElementById(blockId))    
                sectionControl.removeChild(document.getElementById(blockId))
            sectionControl.insertBefore(errorBlock,sectionControl.firstChild);
        }
    
    }
    clearErrors = function(sectionId)
    {
        var controlName = sectionId + "_ErrorBlock";
        var errorBlock = document.getElementById(controlName);
        if (errorBlock && errorBlock.tagName) {
            errorBlock.innerHTML  = "";
        }
    }
 function showOrHide(img){  
        //debugger;
        var li=img.parentNode.parentNode;
        var ul=li.parentNode;
        if (li.className==="open"){
            li.className="close";
            ul.className="";
        }
        else{       
            li.className="open";
            ul.className="";            
        }
    }
    
    
    
function GetDetail(sender,value)
{
    var Search= trim(sender.value);
    if(Search =="")
    {
       sender.value=value;
    }
}
function trim(str)
{
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function RemoveDefault(target,value)
{
    var objValue = target.value;    
    if(objValue == value)
    {
       target.value = "";
    }
}
function AskInviteConfirmation()
{
    var comfirmValue = confirm("Are you sure you want to send this Invite?");
    return comfirmValue;
}

function SelectAll(CheckBoxControl,grd) 
{
    if (CheckBoxControl.checked == true) 
    {
        var i;
        for (i=0; i < document.forms[0].elements.length; i++) 
        {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf(grd) > -1)) 
            {
                document.forms[0].elements[i].checked = true;
            }
        }
    }      
    else 
    {
        var i;
        for (i=0; i < document.forms[0].elements.length; i++) 
        {
            if ((document.forms[0].elements[i].type == 'checkbox') && 
            (document.forms[0].elements[i].name.indexOf(grd) > -1)) 
            {
                document.forms[0].elements[i].checked = false;
            }
        }
    }
}


function isNumberKey(evt)
{
 
     var charCode = (evt.which) ? evt.which : evt.keyCode
     if (charCode > 31 && (charCode < 47 || charCode > 57))
        return false; 
     return true;       
}

//*******  For feed back div display **********///
var canShowUserFeedback = 0;
var isChildUserFeedbackDivClicked=0;
function divChildUserFeedbackClick()
{
    isChildUserFeedbackDivClicked = 1;
}
function hideUserFeedback()
{
    if(isChildUserFeedbackDivClicked==0)
    {
	    document.getElementById('divChildUserFeedback').style.visibility = 'hidden';
	    document.getElementById('divMainUserFeedback').style.visibility = 'hidden';
	    document.getElementById('divMainUserFeedback').className = 'UserFeedbackDivHideOverlay';
	    document.getElementById('divThanks').style.display = 'none';
	}
	else
	{
	    isChildUserFeedbackDivClicked = 0;
	}
}

function closeUserFeedback()
{
    isChildUserFeedbackDivClicked = 0;
    hideUserFeedback();
    return false;    
}

function hideFeedBack()
{
    canShowUserFeedback=1;
    document.getElementById('divThanks').style.display = 'inline';
    document.getElementById('divFeedBack').style.display = 'none'; 
}

function closeShippingAddressLightBox()
{
    isChildUserShippingAddressDivClicked = 0;
    hideUserShippingAddress();
    return false;
}


function showUserFeedback()
{
    if(canShowUserFeedback!=0)
    {
	    document.getElementById('divChildUserFeedback').style.visibility = 'visible';
	    document.getElementById('divMainUserFeedback').style.visibility = 'visible';			    
	    document.getElementById('divMainUserFeedback').className = 'UserFeedbackDivOverlay';	
	    
	    //added by Mohan to hide the thanks
	    document.getElementById('divThanks').style.display = 'none';
        document.getElementById('divFeedBack').style.display = 'inline';  
	}	
}
showUserFeedback();

function showUserFeedbackLightBox()
{
    canShowUserFeedback = 1;
    showUserFeedback();
    return false;
}	

//****  Feed back end ********///////


//********  For Quick login div *********//

var canShowSignIn = 0;
var isChildSigninDivClicked=0;
function divChildSigninClick()
{
    isChildSigninDivClicked = 1;
}
function hideSignIn()
{   
    if(isChildSigninDivClicked==0)
    {
	    document.getElementById('divChildSignIn').style.visibility = 'hidden';
	    document.getElementById('divMainSignIn').style.visibility = 'hidden';
	    document.getElementById('divMainSignIn').className = 'Signin_divHideOverlay';
	    
	}
	else
	{
	    isChildSigninDivClicked = 0;
	}
}

function showSignIn()
{
    if(canShowSignIn!=0)
    {
	    document.getElementById('divChildSignIn').style.visibility = 'visible';
	    document.getElementById('divMainSignIn').style.visibility = 'visible';			    
	    document.getElementById('divMainSignIn').className = 'Signin_divOverlay';
	    scrollTo(0,50);			    
	}
}
showSignIn();

function showLightBox()
{   
    canShowSignIn = 1;
    showSignIn();
    return false;
}		
		
		
//****      Quick login end  *************//			

//********  For Product image enlarge div *********//
var canShowProductImage = 0;
var isChildUserProductImageClicked=0;
function divChildProductImage()
{
    isChildUserProductImageClicked = 1;
}
function hideProductImage()
{
    if(isChildUserProductImageClicked==0)
    {
	    document.getElementById('divChildProductImage').style.visibility = 'hidden';
	    document.getElementById('divMainProductImage').style.visibility = 'hidden';
	    document.getElementById('divMainProductImage').className = 'ProductImageDivHideOverlay';
	}
	else
	{
	    isChildUserProductImageClicked = 0;
	}
	return false;
}

function closeProductImage()
{
    isChildUserProductImageClicked = 0;
    hideProductImage();
    return false;
}

function showProductImage()
{
    if(canShowProductImage!=0)
    {
	    document.getElementById('divChildProductImage').style.visibility = 'visible';
	    document.getElementById('divMainProductImage').style.visibility = 'visible';			    
	    document.getElementById('divMainProductImage').className = 'ProductImageDivOverlay';
	    document.getElementById('imgFullProductImage').src = fullImgURL;
	}
}
showProductImage();

function showProductImageLightBox()
{
    canShowProductImage = 1;
    showProductImage();
    return false;
}		
		
//****      product image enlarge end  *************//			
// Function to limit text entered in Text Area
function LimitTextArea(limitField, limitNum)
 {
      if(limitField.value.length > limitNum)
       {
               limitField.value = limitField.value.substring(0, limitNum);
       } 
 } 

 
 function DeleteGroupVideoConfirmation()
    {   
        return confirm("Are you sure you want to delete this Video?");
    }
    
    
    
 function DeleteGroupRideConfirmation()
    {   
        return confirm("Are you sure you want to delete this Ride?");
    }
    
function DeleteGroupDiscussionTopicConfirmation()
{   
    return confirm("Are you sure you want to delete this Discussion Topic?");
}

function DeleteGroupPhotoConfirmation()
{   
    return confirm("Are you sure you want to delete this Photo?");
}

function DeleteGroupTopicCommentConfirmation()
{   
    return confirm("Are you sure you want to delete this Topic Comment?");
}

function DeleteRideDetailsConfirmation()
{   
    return confirm("Are you sure you want to delete this Ride?");
}

function deleteAddressConfirmation()
{
    return confirm("Are you sure you want to delete this Shipping Address?");
}

function deleteBillingAddressConfirmation()
{
    return confirm("Are you sure you want to delete this Billing Address?");
}
function DeleteGroupConfirmation()
{
    return confirm("Are you sure you want to delete this group?");
}
//To Enter Only the Numbers
function CheckZipCode(e,obj)
{
    var str = obj.value;
    var key //= (window.event) ? event.keyCode : e.which;
     if (window.event)
    key = event.keyCode
    else
    key = e.which
    // Was key that was pressed a numeric character (0-9) or backspace (8) or tab?
    if (key > 47 && key < 58 || key == 8 || key == 0||key == 45)
    {
         if(key == 45)
         {
            /*var first = obj.value.indexOf("-",0);
            var next = obj.value.indexOf("-",(first+1));
             if(next!=null)
             {
                alert(first+":"+next);
                if (window.event)
                    event.keyCode=null;
                else
                    e.preventDefault();
             }*/
             return;
         }
         if((key == 48) && (str < 1))
         {
            if (window.event)
                event.keyCode=null;
            else
                e.preventDefault();
          }
        return; 
     }// if so, do nothing
    else 
     // otherwise, discard character
    if (window.event) //IE
     window.event.returnValue = null;     
    else //Firefox
    e.preventDefault();  
}

// Check for Non numeric fields
function ReplaceNumericInCharacterValue(e,obj)
{
  var str = obj.value;
    var key //= (window.event) ? event.keyCode : e.which;
     if (window.event)
    key = event.keyCode
    else
    key = e.which
  if (key > 64 && key < 91 ||key > 96&& key < 123 ||key == 8 || key == 0 || key==32)
    {
         if((key == 48) && (str < 1))
         {
            if (window.event)
                event.keyCode=null;
            else
                e.preventDefault();
          }
        return; 
     }// if so, do nothing
    else 
     // otherwise, discard character
    if (window.event) //IE
     window.event.returnValue = null;     
    else //Firefox
    e.preventDefault();
}

//General Confirmation function
function GeneralConfirmation(getConfirmationFor)
{
    return confirm("Are you sure you want to "+getConfirmationFor+"?");
}
