

//*******************************************************************************
//								PAGE HISTORY
//*******************************************************************************
//     Project Name  : vimoth jewels
//     Module Name   : Validations
//     Developed By  : vimoth team 
//     Department    : Software Development.
//     Degignation   : Programmer
//     Company       : avanten Solutions
//     StartDate     : 
//     Scope         : this module contains javascript validations for client side script
//                       
//						
// 
//************************----------UPGRADATION---------**********************// 
//			 Name			|	Date	|			Remarks  
//	1. 						|			|	
//							|			|
//****************************************************************************//
//**************************************************************************************
// only Numbers
//**************************************************************************************

function numbersOnly(field, event)
 {
	var key, keychar;

	if (window.event)
	key=window.event.keyCode;
	else if (event)
	key=event.which;
	else 
	return true;

	keychar=String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
	return true;
	else if ((("0123456789.").indexOf(keychar) > -1))
	return true;
	else if ((("%%").indexOf(keychar) > -1))
  		return false;
	else if ((("//").indexOf(keychar) > -1))
	{
		alert("Enter Fractions As A Percent (Example: Enter 25 instead of 1/4)");  
  		return false
  	} 
	else 
	{
		alert("Please Enter Only Numbers"); 
		return false
	}
}


//**************************************************************************************
// Restriction The Length of TextArea
//**************************************************************************************
		function textLimit(txtAddress, maxlen)	
		{
			if (txtAddress.value.length > maxlen + 1)
			alert('your input has been Exceeded the Limit!');
			if (txtAddress.value.length > maxlen)
			txtAddress.value = txtAddress.value.substring(0, maxlen);
		}




//**************************************************************************************************//
  //It Accepts Only Alphabets not any single space and special characters in starting or in mid also
  //
  //**************************************************************************************************//
function IsAlpha(str)
{
    
	var reg =/^([a-zA-Z])+$/;
	 
	    if (!reg.test(str))
	    {
		return false;
        }
	    return true;
	 
}
//*************************************************************************************************//
  //Alphabets with only one space in middle not in starting.
  //not accepting any special characters. 
 
//*************************************************************************************************//

function IsAlphaIphen(str)
{
	var reg=/^[a-zA-Z]([-]?[a-zA-Z])+$/
	//var reg=/^([a-zA-Z][ ]?)*$/;
  
   if (!reg.test(str)) 
		return false; 
   return true;
   
}
//*************************************************************************************************//
  //Alphabets with only one space in middle not in starting.
  //not accepting any special characters. 
 
//*************************************************************************************************//

function IsAlphaSpace(str)
{
	//var reg=/^[a-zA-Z]([ ]?[a-zA-Z])+$/
	var reg=/^[a-zA-Z]([ ]?[a-zA-Z]{0,30})+\s*$/
	//var reg=/^([a-zA-Z][ ]?)*$/;
  
   if (!reg.test(str) )
		return false;
   return true;
   
}
//*************************************************************************************************//
  //Alphabets with  dot(.) without space  
  //it accepts only single dot in anywhere of text not in starting 
  //not accepts single space also in middle or in starting of text
//*************************************************************************************************//
function IsAlphaDot(str)
{
	
	var reg =/^[a-zA-Z]+[\.]?[a-zA-Z]+$/
	
   if (!reg.test(str))
		return false;
	return true;
}

//************************************************************************************************//
  //Alphabets with only one space in middle not in starting and also it accepts dot(.)
//************************************************************************************************//
function IsAlphaDotSpace(str)
{
var reg=/^[a-zA-Z](([ ]|[\.])?[a-zA-Z])*$/
	
   if (!reg.test(str))
		return false; 

	return true;
}


//*************************************************************************************************//
  //	only numbers  with out space
  // ex1:00000000000000000 ex:21287687000000 ex3:00008766575
  //dont have any conditions and any limits for this function 
  //not accepts single space also in middle or in starting of numbers
//*************************************************************************************************//

function IsNumeric(str)
{
	var reg =/^[0-9]+$/;

	if(!reg.test(str))
		return false;
		  
	return true;
}

//*************************************************************************************************//
  //	only numbers with singlespace eg:-(00 0000 0000)
  //it not accepting continuous space anywhere in mid 
  //not accepting single space also in starting
//*************************************************************************************************//
function IsNumericSpace(str)
{
	var reg=/^[0-9]([ ]?[0-9])*$/

	//var reg=/^([0-9][ ]?)+$/;

	if(!reg.test(str))
		return false;
	return true;
}


//*************************************************************************************************//
//		Alpha Numeric WithOutSpace
//must start with alphsbets first ex:abc6757jhgu87
//not accepting single space also in middle or in starting
//*************************************************************************************************//
function IsAlphaNumeric(str)
{
	reg = /^[a-zA-Z][a-zA-Z0-9]*$/;
    
	if (!reg.test(str)) 
		return false;
	return true;
}


//**************************************************************************************************//
//		Alpha Numeric WithSpace
//it accepts single space in mid not in starting and also it not taking continuous spaces
//ex:ggjkh87 yg87   ex:hjiu ghiu 876 jgh87
//**************************************************************************************************//
function IsAlphaNumericSpace(str)
{
	
	var reg=/^[a-zA-Z]+([ ]?[a-zA-Z0-9])*$/;
	//var reg=/^[a-zA-Z]+([ ]?(\.|\/|#|,|:|\&|\_|\-|\'|\@|\RM\*))+([ ]?(\.|\/|#|,|:|\&|\_|\-|\'|\@|\RM\*)[a-zA-Z0-9])*$/; 
	//var reg=/^[a-zA-Z0-9][ ]?((\.|\/|#|,|:|\&|\_|\-|\'|\@|\RM\*)?[a-zA-Z0-9\s]|[\.])*$/;
	if (!reg.test(str))
			return false;
	return true;
}

 
 //***********************************************************************************************//
//             IsNumericDecimal  
//ex:324.8877  or  766.0000  or 8776.0980 or 1234 
//after . must give 4 digits compulsary
//it accepts integers only not any spaces in mid or in starting also                                                    */
//***********************************************************************************************//

function IsNumericDecimal(id)
{
var reg=/^([0-9][1-9][0-9])+[\.]?[0-9]{1,2}$/;
var reg1=/^([1-9][0-9][0-9])+[\.]?[0-9]{1,2}$/;
var reg2=/^([0-9][0-9][1-9])+[\.]?[0-9]{1,2}$/;
var reg4=/^([0-9][1-9])+[\.]?[0-9]{1,2}$/;
var reg5=/^([1-9][0-9])+[\.]?[0-9]{1,2}$/;
var reg6=/^([0-9])+[\.]?[0-9]{1,2}$/;
var reg7=/^([1-9])+[\.]?[0-9]{1,2}$/;
var reg3 =/^[0-9]$/;

	if(reg.test(id) || reg1.test(id)|| reg2.test(id) || reg3.test(id)|| reg4.test(id) || reg5.test(id)|| reg6.test(id) || reg7.test(id))
		return true;
	return false;
}
//***************************************************************************************************//
//  Restaurant Name validations use of ( . / # , : & - ) and space//ramesh
// this function accepts alphabets and numeric values and also some special characters as given above
//***************************************************************************************************//
function IsRestaurantName(str)
{
	var reg1=/^[a-zA-Z0-9]((\.|\/|#|,|:|\&|\_|\-|\'|\@|\RM\*)?[a-zA-Z0-9\s]|[\.])*$/;
	//var reg =/^\S([a-zA-Z0-9\s][a-zA-Z0-9\s#\_\-\/\.\\:,\;\(\)\[\]\"\']?)+$/;
	if (!reg1.test(str))
		return false;
	return true;
//    var reg = /^((0|1)+(1|2)+\:+(([0-5][0-9])|[6][0])+([A|a]|[P|p])+[m|M])*$/;
//    if(reg.test(str))
//    return true;
//    return false;
}
//*************************************************************************************************//
//Alphabets with only one space in middle not in starting.       VALIDATION--12
//not accepting any special characters except -(hypen) .(dot) and ,(comma)
//COUNTRY (ALPHASPACE AND CAN ACCEPT -,. IN BETWEEN)
 //*************************************************************************************************//
function IsCountry(str)
{
   var reg=/^([a-zA-Z][ ]?[\-]?[\,]?[\.]?)*$/;
   	
	if (!reg.test(str))
   	return false;
	return true;
   
}

//***************************************************************************************************//
//  Country Name  validations use of (  - ) and space///ramesh.
// this function accepts alphabets and numeric values and also some special characters as given above
//***************************************************************************************************//
//function IsCountryName(str)
//{
//	var reg1=/^[a-zA-Z]((\-)?[a-zA-Z\s]|[\.])*$/;
//	//var reg =/^\S([a-zA-Z0-9\s][a-zA-Z0-9\s#\_\-\/\.\\:,\;\(\)\[\]\"\']?)+$/;
//	if (!reg1.test(str))
//		return false;
//	return true;
//} 



//***************************************************************************************************//
//  Address validations use of ( . / # , : ; - ) and space
// this function accepts alphabets and numeric values and also some special characters as given above
//***************************************************************************************************//
function IsAddress(str)
{
	//var reg1=/^[a-zA-Z0-9]((\.|\/|#|,|:|\;|\_|\-)?[a-zA-Z0-9\s]|[\.])*$/;
	//var reg =/^\S([a-zA-Z0-9\s][a-zA-Z0-9\s#\_\-\/\.\\:,\;\(\)\[\]\"\']?)+$/;
	var reg1=/^[a-zA-Z0-9]((\.|\/|#|,|:|\;|\_|\-|[ ])?[a-zA-Z0-9]|[\.])*\s*$/;
	if (!reg1.test(str))
		return false;
	return true;
}

//************************************************************//
function IsPlotNo(str)
{
    var reg = /^[a-zA-Z]*$/;
    //var reg1=/^[a-zA-Z0-9]((\.|\/|#|,|:|\;|\_|\-|[ ])?[a-zA-Z0-9]|[\.])*\s*$/;
    var reg1=/^[\#]?[a-zA-Z0-9]((\.|\/|\#|-|\,|[ ])?[a-zA-Z0-9])*\s*$/;
    if(str.length>3)
	{
    if ((!reg.test(str))&&(reg1.test(str)))
		return true;
	return false;
	}
}
   
   //**************************************************************************************************//
//DATE VALIDATIONS in dd/mm/yyyy    
//**************************************************************************************************//
function IsValidDate(obj)
{
   var validNum ="0123456789/";
   var fax = obj.value;
   len = fax.length;
   var ssnChar;
   var status=true;

   if(len==0)
   {
     return false;
   }
 
   else if((fax.indexOf('/') == "-1"))
   {    
     return false;
   }

   for(i=0;i<len;i++)
   {
        ssnChar = fax.charAt(i);

     if (validNum.indexOf(ssnChar) == "-1")
     {
	      return false;
     }
  }
   if(IsCheckDate(obj))
   {
		return true;
   }
   else
	{
		return false;
	}
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 

{
	for (var i = 1; i <= n; i++)
	 {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
      }
   return this
}

function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function IsCheckDate(obj)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=3000;

	dtStr = obj.value;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1)
		strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1)
		strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	 {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	
	day=parseInt(strDay)
	month=parseInt(strMonth)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
	{
		obj.value=""
		return false;

	}
	if (strMonth.length<1 || month<1 || month>12){
		obj.value=""
		return false;

	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		obj.value=""
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		obj.value=""
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr,
dtCh))==false){
		obj.value=""
		return false;
	}
	return true
}

function validateDates(obj, objectLable)
{
	var bool = true;
	bool = checkDateNonNumeric(obj);
	if(bool)
	{
		var checkDates=checkingDates(obj.value, systemDateFormat);
		if(checkDates==0)
		{
			return true;
		}
		else
		{
			obj.value="";
			obj.focus();
			return false;
		}
	}
	 else
	{
		return false;
	}
}

function validateDates1(obj, objectLable)
{
	var bool = true;
	bool = checkDateNonNumeric(obj);
	if(bool)
	{
		var checkDates=checkingDatesForGTThanCurrDate(obj.value,
systemDateFormat);
		if(checkDates==0)
		{
			return true;
		}
		else
		{
			obj.value="";
			obj.focus();
			return false;
		}
	}
	else
	{
		return false;
	}
}
	
function checkingDates(dateToBeCompared, systemDate)
{
	var dateToBeComparedArray=dateToBeCompared.split("/");
	var dateToBeComparedObject=new Date();
	dateToBeComparedObject.setMonth(dateToBeComparedArray[0]-1);
	dateToBeComparedObject.setDate(dateToBeComparedArray[1]);
	dateToBeComparedObject.setYear(dateToBeComparedArray[2]);

	var systemDateArray=systemDate.split("/");
	var systemDateObject=new Date();
	systemDateObject.setMonth(systemDateArray[0]-1);
	systemDateObject.setDate(systemDateArray[1]);
	systemDateObject.setYear(systemDateArray[2]);
	if(systemDateObject.valueOf()>=dateToBeComparedObject.valueOf())
	{
	 	return false;
	}
	else
	{
		return true;
	}
}

function validateDates1(obj, objectLable)
{
	var bool = true;
	bool = checkDateNonNumeric(obj);
	if(bool)
	{
		var checkDates=checkingDatesForGTThanCurrDate(obj.value,
systemDateFormat);
		if(checkDates==0)
		{
			return true;
		}
		else
		{
			obj.value="";
			obj.focus();
			return false;
		}
	}
	else
	{
		return false;
	}
}

function checkingDatesForGTThanCurrDate(dateToBeCompared, systemDate)
{
	var dateToBeComparedArray=dateToBeCompared.split("/");
	var dateToBeComparedObject=new Date();
	dateToBeComparedObject.setMonth(dateToBeComparedArray[1]-1);
	dateToBeComparedObject.setDate(dateToBeComparedArray[0]-1);
	dateToBeComparedObject.setYear(dateToBeComparedArray[2]);
	
	var systemDateArray=systemDate.split("/");
	var systemDateObject=new Date();
	systemDateObject.setMonth(systemDateArray[1]);
	systemDateObject.setDate(systemDateArray[0]-1);
	systemDateObject.setYear(systemDateArray[2]);
	if(dateToBeComparedObject.valueOf()>systemDateObject.valueOf())
	{
	 	return false;
	}
	else
	{
		return true;
	} 
	return true;
}
//**************************************************************************************************//
//                     Validation for Date
////************************************************************************************************//
function IsDate(dateToBeCompared)
{
	var dateToBeComparedArray=dateToBeCompared.split("/");
	if(dateToBeComparedArray.length != 3)
		return false;
	var dateobj=new Date();
	dateobj.setFullYear(dateToBeComparedArray[2],dateToBeComparedArray[0]-1,dateToBeComparedArray[1])
	if(!(dateobj.getDate() == dateToBeComparedArray[1]))
		return false;
	if(!(dateobj.getMonth() == dateToBeComparedArray[0]-1))  
		return false;
	if( (dateobj.getFullYear() != dateToBeComparedArray[2]) || (dateToBeComparedArray[2] < 1900) || (dateToBeComparedArray[2] > 2500) )
		return false;
	return true;  
} 

//*************************************************************************************************//
//                     Compare StartDate With End Date
////***********************************************************************************************// 
function CompareDates(StartDate,EndDate)
{
	var StartDateArray = StartDate.split("/");
	var Sdate=new Date();
	Sdate.setFullYear(StartDateArray[2],StartDateArray[1]-1,StartDateArray[0])
	var EndDateArray=EndDate.split("/");
	var Edate=new Date();
	Edate.setFullYear(EndDateArray[2],EndDateArray[1]-1,EndDateArray[0])
	if(Sdate > Edate)
	 	return false;
	return true;
}
//**************************************************************************************************//
//                     Compare Date With Current Date
////************************************************************************************************//
function CompareDatewithCurrentDate(dateToBeCompared)
{
	var dateToBeComparedArray=dateToBeCompared.split("/");
	var dateobj=new Date();
	dateobj.setFullYear(dateToBeComparedArray[2],dateToBeComparedArray[1]-1,dateToBeComparedArray[0])
	var today = new Date();
	if(dateobj <= today)
		return true;
	return false;
}

//****************************************************************************************************//
//EmailID     ex:  xxxxx@yahoo.com and xxxxxxxxx@yahoo.co.in and jhguyjyj@876687.com jhbjhg@jhg977.com
//****************************************************************************************************//
function IsValidEmailID(id)
{ 
	 //var reg =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+$/;                                          
     //var reg1 =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+([\.])[a-zA-Z]+$/;                                          
    //var reg =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+$/;                                          
     //var reg1 =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+([\.])[a-zA-Z]+$/;     
     var reg =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+$/;                                          
     var reg1 =/^[a-zA-Z][a-zA-Z0-9]+([\_\-\.]?[a-zA-Z0-9]+)@[a-zA-Z0-9]+([\.])[a-zA-Z]+([\.])[a-zA-Z]+$/;    
	
	if(reg.test(id) || reg1.test(id))
		return true;
	return false; 
}

//**************************************************************************************************//
 //	only numbers with out space in middel or in starting and accepts only one zero(numWithOutContiZeros)
 //eg(0800000000000000) and 00876645000000
 // it accepts starting maximum 2 zeros only
 //*************************************************************************************************//
function IsValidPhoneNumber(str)
{	
	//var reg  = /^[1-9][0-9][ ]?[1-9][0-9]+$/;
	//var reg1 = /^[0-9][1-9]([ ]?[0-9][0-9][ ]?[0-9])+$/;
	//var reg2 = /^[1-9][0-9][ ]?[1-9][0-9][ ]?[0-9]+$/;
	//var reg3 = /^[0-9][0-9][ ]?[1-9][0-9][ ]?[0-9]+$/;
	//var reg  = /^([\+]|[1-9])([0-9][ ]?|[\-][1-9][0-9])+$/;
	//var reg1 = /^([\+]|[0-9])([1-9]([ ]?|[\-][0-9][0-9][ ]?[0-9]))+$/;
	//var reg2 = /^([\+]|[1-9])([0-9][ ]?|[\-][1-9][0-9][ ]?[0-9])+$/;
	//var reg3 = /^([\+]|[0-9])([0-9][ ]?|[\-][1-9][0-9][ ]?[0-9])+$/;
	
	/*var reg  = /^(([0-9][0-9][1-9])+([0-9]{7,13}))+$/;
	var reg1 = /^(([0-9][1-9][0-9])+([0-9]{7,13}))+$/;
	var reg2 = /^(([1-9][0-9][0-9])+([0-9]{7,13}))+$/;

	
	if(str.length>4 && str.length<=16)
	{
	if(reg.test(str)||reg1.test(str)||reg2.test(str))
	 
		{
		return true;
		}
		return false;
	}
	return false;*/

	
	var reg  = /^(([0-9][0-9][1-9])+([0-9]{7,13}))+$/;
	var reg1 = /^(([0-9][1-9][0-9])+([0-9]{7,13}))+$/;
	var reg2 = /^(([1-9][0-9][0-9])+([0-9]{7,13}))+$/;

	if(reg.test(str)||reg1.test(str)||reg2.test(str))
		return true;
	return false;
	
	
}
//**************************************************************************************************//
//CONTACT NUMBER (NUMERICSPACE CAN ACCEPT – AND +(STARTING POSITION ONLY))  VALIDATION--13
//FAX NUMBER (NUMERICSPACE CAN ACCEPT – AND +(STARTING POSITION ONLY))
 //only numbers with space in middel or in starting and accepts only one zero(numWithOutContiZeros)
 //eg(+0800000000000000) and +00876645000000  and +87675765-8976 8768  and +09789 876
 // it accepts starting maximum 2 zeros only maximum limit is:16
 //*************************************************************************************************//
function IsValidPhoneNumberPlus(str)
{	
	var reg  = /^([\+]?[1-9][0-9][0-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	var reg1 = /^([\+]?[0-9][1-9][0-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	var reg2 = /^([\+]?[0-9][0-9][1-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	var reg3 = /^([\+]?[1-9][1-9][0-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	var reg4 = /^([\+]?[1-9][0-9][1-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	var reg5 = /^([\+]?[0-9][1-9][1-9])+[0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/;
	
	if(str.length<=16)
	{
	if(reg.test(str)||reg1.test(str)||reg2.test(str)||reg3.test(str)||reg4.test(str)||reg5.test(str))
	
		{
		return true;
		}
		return false;
	}
	return false;
}

//**************************************************************************************************//
//CONTACT NUMBER (NUMERICSPACE CAN ACCEPT – AND +(STARTING POSITION ONLY))  VALIDATION--13
//FAX NUMBER (NUMERICSPACE CAN ACCEPT – AND +(STARTING POSITION ONLY))
 //only numbers with space in middel or in starting and accepts only one zero(numWithOutContiZeros)
 //eg(+0800000000000000) and +00876645000000  and +87675765-8976 8768  and +09789 876
 // it accepts starting maximum 2 zeros only maximum limit is:16
 //*************************************************************************************************//
function Quantity(str)
{	
	var reg  = /^[1-9]+$/;
	var reg1 = /^[0-9]+[1-9][0-9]+$/;
	var reg2 = /^[1-9]+[0-9]+$/;
	var reg3 = /^[0-9]+[1-9]+$/;
	var reg4 = /^[1-9]+[0-9][0-9]+$/;
		
	if(str.length<=5)
	{
	if(reg.test(str)||reg1.test(str)||reg2.test(str)||reg3.test(str)||reg4.test(str))
	
		{
		return true;
		}
		return false;
	}
	return false;
}

	
//*********************************************************************************************************//
//only numbers 0-9 only.this function not accepting starting atleast one zero also.
//ex:9876543234  or  9089700807    or 8564560080   limit is 10 numbers only.
//*********************************************************************************************************//
function IsValidLocalPhone(Val)
{
	var reg = /^[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$/
	
	if (reg.test(Val))
		return true;
	return false;
	}
//*********************************************************************************************************//
//It doesn't Accept All Zerossssss//ramesh
//ex:9876543234  or  9089700807    or 8564560080   limit is 10 numbers only.
//*********************************************************************************************************//
function IsAllZeros(Val)
{
	var reg = /^[0][0][0]+$/
	
	if (!reg.test(Val))
		return true;
	return false;
	}
	
//**************************************************************************************************//
    //Age Restriction
////************************************************************************************************//
function IsValidAge(age)
{
  if(!(age > 0 && age < 99))
	return false;
  return true;
}
//**************************************************************************************************//
    //Age Restriction
////************************************************************************************************//
function IsValidQuantity(age)
{
  if(!(age > 0 && age < 999))
	return false;
  return true;
}
//**************************************************************************************************//
    //HTMLTag
    //if u give html tags it gives error message
////************************************************************************************************//
function IsHTMLTags(str)
{
  var reg =/<|>/
  if(reg.test(str))
	return false;
  return true;
}
//************************************************************************************************//
    //Credit Card ex:8766-1010-1110-5567  or 8675 9866 0976 9708
    //only integers,limit is 16 integers.every four integers must give - or singlespace compulsary
    //not accepts starting zero and not accepts all 16  zero values
////**********************************************************************************************//
function IsCreditCard(id)
{
  var reg=/^([1-9][0-9][0-9][0-9]([ ]|[\-])[0-9][0-9][0-9][0-9]([ ]|[\-])[0-9][0-9][0-9][0-9]([ ]|[\-])[0-9][0-9][0-9][0-9][0-9]?)$/
  if(!reg.test(id))
	 return false;
  return true;
}
//************************************************************************************************//
//             IsValidWebsite                                                       
//************************************************************************************************//

function IsWebSiteAddress(str)
{
	
//var reg=/^[w|W]{3}\.[a-zA-Z0-9]+([\.\-]?[a-zA-Z0-9]+)*\.((in|IN|com|COM|net|NET|ORG|org|EDU|edu|mil|MIL|gov|GOV|info|co[\.]in|co[\.]uk|ac[\.]in|init|INIT))\s*$/;
var reg=/^[w|W]{3}\.[a-zA-Z0-9]+([\.\-\_]?[a-zA-Z0-9]+)([\.\-\_]?[a-zA-Z])*$/;
 
	if(!reg.test(str))
		return false;
	return true;
 }

//***********************************************************************************************//
// Restriction The Length of TextArea
// minimum length must have to give
// this function is checks minimum length
//***********************************************************************************************//
		function IsTextLimit(str,minlen)	
		{   
		var length=minlen;
		//str=txtAddress;
			if(str.length>=minlen)
				return true;
		return false;
		}	
		
//***********************************************************************************************//
// Restriction The Length of TextArea
// maximum length must have to give
// this function is checks maximum length
//***********************************************************************************************//
		function IsTextLimitMax(str,maxlen)	
		{   
		var length=maxlen;
		//str=txtAddress;
			if(str.length<=maxlen)
				return true;
		return false;
		}					
//***********************************************************************************************//
//             IsDecimal  
//ex:324.8877  or  766.0000  or 8776.0980 
//after . must give 4 digits compulsary
//it accepts integers only not any spaces in mid or in starting also                                                    */
//***********************************************************************************************//

function IsDecimal(id)
{
var reg=/^[\-]?[0-9]+[\.][0-9]{1,4}$/;
	if(!reg.test(id))
		return false;
	return true;
}
//********************************************************************************
//ex:23.23   20.00	45.99	60.50
//*******************************************************************************************

/*function IsDecimal(id)
{
	var reg=/^([1-9][\.])([0-9]{1,2})$/;
	var reg1=/^([1-9][0-9][\.])([0-9]{1,2})$/;
	//var reg2=/^([1-9][0-9][0-9][\.])([0-9]{3,2})$/;
	//var reg3=/^([1-9][0-9][0-9][0-9][\.])([0-9]{4,2})$/;
	//var reg4=/^([1-9][0-9][0-9][0-9][0-9][\.])([0-9]{5,2})$/;
	//var reg5=/^([1-9][0-9][0-9][0-9][0-9][0-9][\.])([0-9]{6,2})$/;
		if(reg.test(id)||reg1.test(id))//||reg2.test(id)||reg3.test(id)||reg4.test(id)||reg5.test(id))
			return true;
	return false;
}*/
//***************************************************************************************************
//for decimal  VALIDATION--1
//condition is it accepts from 0.01 to 99.99 
//ex:0.01  0.99  1.99  23.99  67.89  45 78 67 25 99.99  99
//***************************************************************************************************
function IsDec(val)
{
  if(!(val > 0.00 && val < 100.00))
  return false;
  return true;
}

//*********************************************************************************//
//zipcode  Ex - 203984 
// It takes 6 to 10 digits only ,It will not Accept Starting Zeros & 
// will not Accept Any Special Characters any where
//*********************************************************************************//
function IsValidZipCode(id)
   {
	 var reg  = /^([1-9][0-9][0-9][0-9][0-9])$/
	 var reg1 = /^([1-9][0-9][0-9][0-9][0-9][0-9])$/
	 var reg2 = /^([1-9][0-9][0-9][0-9][0-9][0-9][0-9])$/
	 var reg3 = /^([1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$/
	 var reg4 = /^([1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$/
	
		if(reg.test(id)||reg1.test(id)||reg2.test(id)||reg3.test(id)||reg4.test(id))
			return true;
	    return false;
	}		

//*********************************************************************************//
//  OnlyNumber
//ex: it never accepts starting zero...
//************************************************************************************/
	function OnlyNumbers(id) 
	{
		var reg=/^[1-9]?[0-9]?[0-9]$/;
		if(!reg.test(id))
			return false;
		return true;
	}
//******************************************************************************/
// IsNumAlpha
// ex 234asdfaaafsa  or asdfa2341 or 21431 or asdfas...........
//****************************************************************************/		
		
	function IsNumAlpha(id)
	{
		var reg1=/^[a-zA-Z0-9]+([a-zA-Z0-9])*$/; 
		if(!reg1.test(id))
			return false;
		return true;
	}
//*************************************************************************************************//
//		Alpha Numeric WithSingle Space in mid not in starting
//ex:kjhk987hgjkh987  or 987jyhgj8977kjhi or 987 kjgh ukg 987jyg or uj h876 yuhg 
//not accepting single space also in middle or in starting
//*************************************************************************************************//
function IsNumAlphaSpace(str)
{
	var reg=/^[a-zA-Z0-9]([ ]?[a-zA-Z0-9])+$/
	if (!reg.test(str)) 
		return false;
	return true;
}
//*************************************************************************************************//
//		Alpha Numeric WithSingle Space in mid not in starting
//ex:kjhk987hgjkh987  or 987jyhgj8977kjhi or 987 kjgh ukg 987jyg or uj h876 yuhg 
//not accepting single space also in middle or in starting
//*************************************************************************************************//
function ServiceName(str)
{
	var reg=/^[a-zA-Z0-9](([ ]|\(|\))?[a-zA-Z0-9])+$/
	if (!reg.test(str)) 
		return false;
	return true;
}
//**********************************************6***************************************************//
//		 Numeric alpha WithOutSpace and with hyphen(-)
//  ex:abc6757jhgu87 or 9876hjugjh987 or 987jhjk-89hk-987  or jkghljkhgu987-987  or jk-hg-iohg-987
//not accepting single space and special character except hyphen  in middle or in starting
//hyphen also not excepting in starting and ending of the text it accepts only in mid of text
//*************************************************************************************************//
function IsNumAlphaHyphen(str)
{
	
	var reg=/^[a-zA-Z0-9]([\-]?[a-zA-Z0-9])+$/
    
	if (!reg.test(str)) 
		return false;
	return true;
}
//*************************************************************************************************//
//Price ex:243.34
//*************************************************************************************************//
function IsValidPrice(str)
{
var reg1 = /^[0-9]{1,10}$/;
var reg = /^[0-9]{1,7}[\.]([0-9]{1,2})$/;
	if(reg1.test(str)|| reg.test(str))
		return true;
	return false; 
}

//******************************************************************************//
//this function not accepting only alphabets
//******************************************************************************//
function Weight(str)
{
  //var reg = /^[a-zA-Z]*$/;
  //var reg1 = /^(([0-9]{1,4})+([\.]?([0-9]|[a-zA-Z0-9]{0,2})))*$/;
  
			        var reg1 = /^[1-9]*$/;
                  var reg2 = /^(([0-9][1-9])+([\.]+([0-9]{0,2})))*$/;
                  var reg3 = /^(([1-9][0-9])+([\.]+([0-9]{0,2})))*$/;
                  var reg4 = /^(([1-9])+([\.]+([0-9]{0,2})))*$/;
                  var reg5 = /^(([0-9][1-9]+[0-9]{1,2})+([\.]+([0-9]{0,2})))*$/;
                  var reg6 = /^(([1-9][0-9]+[0-9]{1,2})+([\.]+([0-9]{0,2})))*$/;
                  var reg7 = /^([0-9]+[\.]+([0-9][1-9][0-9]{0,1}))*$/;
                  var reg8 = /^([0-9]+[\.]+([1-9]{0,2}))*$/;
                  var reg9 = /^([0-9]+[\.]+([1-9][0-9][0-9]{0,1}))*$/;
  
  //if((!reg.test(str))&&((reg1.test(str))||(reg2.test(str))))
  if(reg1.test(str)||reg2.test(str)||reg3.test(str)||reg4.test(str)||reg5.test(str)||reg6.test(str)||reg7.test(str)||reg8.test(str)||reg9.test(str))
  {
        return true;        
  }
  return false;
}
	
//*********************************************************************************************//
//ex:e34 4er or rw3 57t or  f5 6ty  or  ert5 43e  or   e456 6er
//for uk pincode validation.
//*********************************************************************************************//
function IsUKPostCode(str)
{	  
		
      //var reg = /^[a-zA-Z][ ]?([A-Za-z0-9]{1,4})+$/;
      //var reg1 = /^[a-zA-Z][A-Za-z0-9][ ]?([A-Za-z0-9]{1,4})+$/;
      //var reg2 = /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9]{1,4})+$/;
      //var reg3= /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9]{1,4})+$/;
      var reg = /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])+$/;
      var reg1 = /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])+$/;
      var reg2 =  /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])+$/;
     var reg3= /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][ ]?([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])+$/;
      
     if(str.length<=9)      
    if (reg.test(str)|| reg1.test(str)|| reg2.test(str)||reg3.test(str))
     //if (reg.test(str))
      
		return true;
	return false;
}
//*********************************************************************************************//
//ex:A39  or BN9 or nn12 or n123
//for uk pincode validation.  //ramesh
//*********************************************************************************************//
 function IsUKPostCode1(str)
{     
     var reg= /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9]+$/; 
     var reg1= /^[a-zA-Z][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]+$/;
      
     if(str.length<=4)      
    if (reg.test(str)|| reg1.test(str))
     //if (reg.test(str))
      
		return true;
	return false;
}
//*********************************************************************************************//
//ex:A39  or BN9 or nn12 or n123
//for uk pincode validation.  //ramesh
//*********************************************************************************************//
function IsUKPostCode2(str)
{     
     var reg= /^[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]+$/;
     var reg1= /^[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]+$/;
      
     if(str.length<=4)      
    if (reg.test(str)||reg1.test(str))
     //if (reg.test(str))
      
		return true;
	return false;
} 

/*UK postcode check
http://en.wikipedia.org/wiki/UK_postcodes
It is possible to validate the format of a postcode using the following rules:

The postcode must be of 6, 7, or 8 characters in length (including the space) 
The outward code (the set of characters to the left of the space) must be 2, 3 or 4 characters in length 
The first character of the outward code must be alphabetic. 
The inward code (the set of characters to the right of the space) must always be 3 characters in length. 
The first character of the inward code must be numeric. 
The second and third characters of the inward code must be alphabetic. 
*/

/*function validateZipFirst(zipfirst)
{
	var zipfirst =  zipfirst;
	//alert('Checker->' + zipfirst + '<-');
	if (zipfirst.length > 4 || zipfirst.length < 2)
	{
		alert('Error in postcode, the areacode must be 2-4 characters');
		return;		
	}
	if (isNaN(zipfirst.substring(0,1))== false)
	{
		alert('First character in areacode must be a letter.');
	}
}*/

function validateZipLast(ziplast)
{
	var ziplast =  ziplast.value;
	//alert('Checker->' + zipfirst + '<-');
	if (ziplast.length != 3)
	{
		alert('Error in postcode, the streetcode must be 3 characters.');
		return;
	}
	if (isNaN(ziplast.substring(0,1)))
	{
		alert('First character in street code must be a number.');
		return;
	}
	if (isNaN(ziplast.substring(1,2))==false)
	{
		alert('Second character in street code must be a letter.');
		return;		
	}
	if (isNaN(ziplast.substring(2,3))==false)
	{
		alert('Third character in street code must be a letter.');
	}
}

/***************************************************************************************************
//             VALIDATION--3
//for alphanumeric with space and & and -
//ALPHANUMERICSPACE it START WITH ALPHABATES AND NUMBERS AND IT CAN ACCEPT &, - IN BETWEEN 
//Ex:sdfsdfs hgf&hgf-dfsd or 34345dsf jyt&45-sdf 
***************************************************************************************************/
function IsAlphaNumSp(str)
{
	var reg1=/^[a-zA-Z0-9]((\&|\-|[ ])?[a-zA-Z0-9])*\s*$/;
	//var reg =/^\S([a-zA-Z0-9\s][a-zA-Z0-9\s#\_\-\/\.\\:,\;\(\)\[\]\"\']?)+$/;
	if (!reg1.test(str))
		return false;
	return true;
}
/**************************************************************************************************/
// FUNCTION TO FORMAT MONEY EXP:1 CHANGE TO 1.00, 1.1 CHANGE TO 1.10, 1.111 CHANGE TO 1.11
/**************************************************************************************************/
function FormatMoney(val)
{
	var strField = new String(val);
	var strNewField = new String();
	var chkdecemal = 0;

	var i = 0;

	for (i = 0; i < strField.length; i++)
	{
		strNewField[i] = strField.charAt(i);
		if(strField.charAt(i) == '.')
		{					
			chkdecemal++;
			if(strField.length > (i+2))
				strNewField = strField.substring(0,i+3);
			
			break;
		}
	}
	if(chkdecemal == 0)
	{
		chkdecemal = 1;
		val += ".00";
		return (val);
	}
	if(chkdecemal == 1 && (strField.length - i) < 3)
	{
		val += "0";
		return (val);
	}
	else
		return (strNewField);
}
//Compare To Values(a>b)
function compareValue(x,y)
{   
        
    if(parseFloat(x) >= parseFloat(y))
        return false;
    else
        return true;
}
// This is should not allow to write any tags into textbox, parameter is textbox id


function IsTag(str) {
    var strtxtbox = document.getElementById(str);
    var strvalue = strtxtbox.value;

    //      var r = new RegExp("[-&()./ *#a-zA-Z0-9 \r]", "g");


    var r = new RegExp("[<>!#$%^&*]", "g");
    if (r.test(strvalue)) {
        document.getElementById(str).value = document.getElementById(str).value.substring(0, document.getElementById(str).value.length - 1);
        return false;
    }

    return true;
}
//For mouse right click disable
function DisableRightClick(event) {
    //For mouse right click
    if (event.button == 2) {
        alert("Right Clicking not allowed!");
    }
}
 
 

