function phoneValidations(txt_phone)
{
	
 var regExpPhone=/^[0-9]{0,20}$/i;  
if(txt_phone!="")
   {
		if(!regExpPhone.test(txt_phone))
		{
		var mess="Phone Number is invalid";
		alert(mess);
		return false ; 
		}
		if(txt_phone.length>12)
	   {
			 mess="Phone Number Length Maximum 12 digits";
			alert(mess);
			return false ; 
	   }
	    return true;
    }
  return true;
}




function mobileValidations(txt_phone)
{
	
 var regExpPhone=/^[0-9]{0,20}$/i;  
if(txt_phone!="")
   {
		if(!regExpPhone.test(txt_phone))
		{
		var mess="Mobile Number is invalid";
		alert(mess);
		return false ; 
		}
		if(txt_phone.length>13)
	   {
			 mess="Mobile Number Maximum 13 digits";
			alert(mess);
			return false ; 
	   }
	  
    }
	
     return true;
}
function description(str,msg){
   
		if(str=="")
			{	
		     alert(msg+" cannot be blank !");				
			 return false;
			}
		return true;
}
// shud contain only alphanumeric values and shud  . 
function isPageName(str,msg){
   if (str == ""){	// is not null
			alert(msg+" cannot be blank !");
			return false;
	}
	if(str.lenth>128){
           alert("\input type is too long!");
           return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values and shud _ and .
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '.'))
		{
			alert(msg+"field  accepts letters & numbers.");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert(msg+" should begin with an alphabetic character");
		
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;

}
//  shud contain only alphanumeric values with" _ (without space)
function validNameFields_without_space(str,msg)
{
   
	if (str == ""){	// is not null
			alert(msg+" cannot be blank !");
			return false;
	}
	if(str.lenth>128){;
           alert("\input type is too long!")
           return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch))
		{
			alert(msg+"field  accepts letters & numbers.");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert(msg+" should begin with an alphabetic character");
		
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;
}

//  shud contain only alphanumeric values and shud _ and . & spacec
function validNameFields(str,msg)
{
   
	if (str == ""){	// is not null
			alert(msg+" cannot be blank !");
			return false;
	}
	if(str.lenth>128){;
           alert("\input type is too long!")
           return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values and shud _ and .
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch)&& (ch != '_'))
		{
			alert(msg+"field can not accepts spaces & special character! ");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert(msg+" should begin with an alphabetic character");
		
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;
}
function validNameFieldsWithSpace(str,msg)
{
   
	if (str == ""){	// is not null
			alert(msg+" cannot be blank !");
			return false;
	}
	if(str.lenth>128){;
           alert("\input type is too long!")
           return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values and shud _ and .
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch)&& (ch != '_'))
		{
		if(ch!=" ")	{
			alert(msg+"field can not accepts spaces & special character! ");
			return false;
		}
		
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert(msg+" should begin with an alphabetic character");
		
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;
}
function validName(name,msg)
{
      if(name.lenth>128){
       alert("input type is too long!");
       return false;
      }

//var regExp="^[A-Za-z\s]+$";
//alert(name);
//alert(name.match(regExp));
//if(!name.match(regExp)){
//alert(msg+" must not contain special character");
//return false;

//}

	 var charpos = name.search("[^A-Za-z]"); 
	  if(name.length > 0 &&  charpos >= 0  ) 
	 { 
		alert("Special char position "+charpos);
		return false;
	  }//if 
	 
    return true;
 
}
// shud contain only alphanumeric values and shud _ and .& spaces witout mandatory fields
function chekedNumeric(str,msg)
{
    if (str == "")	{	// is not null
		return true;
	}
	if(str.lenth >128){
	  alert("\input type is too long!");
           return false;
	}
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values and shud _ and .
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch)&& (ch != " "))
		{
			alert(msg+"field  accepts letters & numbers.");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert(msg+" should begin with an alphabetic character");
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;
}

function emptyField(name,msg)
{
      if(name.lenth >128 )
	  {
         alert("\input type is to long!");
         return false;
      }
      if(name=="")
		{					
		  alert("Please Enter the "+msg);
		  return false ;
		}
		return true;

}
function emptyFCKField(name,msg)
{
     
      if(name=="")
		{					
		  alert("Please Enter the "+msg);
		  return false ;
		}
		return true;

}
function emailValidation(txt_Emailid)
{
	var regExpAltEmailid=/^[-a-z0-9\._]+@(?:[-a-z0-9]+\.){1,32}[a-z]+$/i;
				
				if(txt_Emailid=="")
					{					
					   var mess="Email Address is blank";
						alert(mess);
						return false ;
					}
				if(txt_Emailid >128){
				  alert("\input type is too long!");
				  return false;
				 }
				if(!regExpAltEmailid.test(txt_Emailid))
					{					
					var mess="Plese Enter a valid Email Adrress";
						alert(mess);		
						return false ;
					}		
					return true;	
}

function emailValidWithNullString(txt_Emailid)
{		
		
		var regExpAltEmailid=/^[-a-z0-9\._]+@(?:[-a-z0-9]+\.){1,32}[a-z]+$/i;
				
				if(txt_Emailid=="")
					{					
			         return true ;
					}
				if(txt_Emailid >128){
				    alert("\input type is too long!");
				    return false;
				  }
				if(!regExpAltEmailid.test(txt_Emailid))
					{					
					var mess="Plese Enter a valid Alt Emailid";
						alert(mess);		
						return false ;
					}		
					return true;
}

function validQuestion(Question)
{
	
	var regExpQuestion=/^[^0-9][a-zA-Z0-9\-?\.?\@?]+/i;
			
				if(Question=="")
					{					
					var mess="Title field is empty!"
						alert(mess);
						return false ;
					}
				if(Question.lenth >128){
				   alert("\input type too long!");
				}	
				if(!regExpQuestion.test(Question))
					{					
					var mess="Plese Enter a valid Title"
						alert(mess);		
						return false ;
					}		
					return true;
}

function CompareDates(date1,date2) 
{ 
   var str1  = date1.value;
   var str2  = date2.value;

   var dt1   = parseInt(str1.substring(0,2),10); 
   var mon1  = parseInt(str1.substring(3,5),10);
   var yr1   = parseInt(str1.substring(6,10),10); 

   var dt2   = parseInt(str2.substring(0,2),10); 
   var mon2  = parseInt(str2.substring(3,5),10);
   var yr2  = parseInt (str2.substring(6,10),10); 

   var date1 = new Date(yr1, mon1-1, dt1); 
   var date2 = new Date(yr2, mon2-1, dt2); 

   if(date2 < date1)
   {
      alert("Start date cannot be greater than End date");
      return false; 
   } 
   return true;
} 


// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=1900;
var maxYear=2100;

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 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 isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	//var strYear=dtStr.substring(pos2+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
    
	var d=new Date();
	var curday=d.getDate(); 
	var curmon=d.getMonth()+1;
    var cyear=d.getFullYear();

	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){
		alert("The date format should be : dd-mm-yyyy");
		return false;
	}

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false;
	}
	 if(strYear < cyear){
	  alert("Please enter Current or Future Year.");
	  return false;
	}
	if(strYear <= cyear)
	{
		if(strMonth < curmon){
		  alert("Please enter Current or Future Month.");
		  
		  return false;
		}
		
	}
	if(strYear <= cyear)
	{
		if(strMonth <= curmon)
		{
	    	if(strDay < curday)
			{
		      alert("Please enter Current or Future Day.");
		      return false;
		    }
		}
		
	}
return true;
}


/**
* This function allow only number for the text field
*/
function isNumberKey(evt)
{
	//event.which work with Mizilla and event.keyCode is worked with IE
	 var charCode = (evt.which) ? evt.which : evt.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	 return true;

}

function isURL(str)
{
   	 if(str=="")
   	 {
	  return true;
	 }
	 if(str.lenth>128){
	     alert("\input type too long!");
	     return false;
     }
	 if(str.indexOf("http://")== -1){
	 alert("Error: Your url should begin with http://");
	 return false;
	 }
	return true; 
}

function get_url(str)
{
//var your_url=prompt('Enter your web page URL!','');
   if(str==""){
      alert("Enter your page URL!");
	  return false;
	 }
   if(str.lenth>128){
      alert("\input type too long!");
      return false;
   }	 
   var is_protocol_ok=str.indexOf('http://');
   if (is_protocol_ok==-1)
   { 
    alert("Error: Your url should begin with http://");
    return false;
   }
 return true;
}

//user login name validation function 

function isUserLoginName(str)	{
	
	if (str == "")	{	// is not null
			alert("\User Login Name cannot be blank, please enter your desired User Login Name")
			
			return false;
	}
	if(str.lenth>128){
      alert("\input type too long!");
      return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values and shud _ and .
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && (ch != '.')&&(ch !='@'))
		{
			alert("\nThe User Login Name field  accepts letters,numbers,@ & underscore.\n\nPlease re-enter your User Login Name.");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_start) == -1 ) {
		alert("User Login Name should begin with an alphabetic character");
		return false;
	}

	if(str.search(regex_login_end) == -1 ) {
		alert("User Login Name should not end with special characters");
		
		return false;

	}

//
	return true;
}

// Name Validator
function isName(name,msg)	{
	name1=name;
	if(name1==""){
	  alert(msg+" cannot be blank");
	  return false;
	}
	if(name1.lenth>128){
      alert("\input type too long!");
      return false;
    }
	var regex_for_name	= /^[A-Za-z]+ [A-Za-z]+$/;
	var alt_regex_for_name	= /^[A-Za-z]+$/;
	if(   (name1.search(regex_for_name) != -1)  || (name1.search(alt_regex_for_name) != -1 ) ) {
			return true;
	} else {
		alert(msg+ " is invalid");
		
		return	false;	
	}
  return true;
}

function priceEcom(str,msg)
{
   	if(str.lenth>128){
           alert("\input type is too long!")
           return false;
    }
	for (var i = 1; i < str.length; i++)	{ // shud contain only alphanumeric values & '$'
		var ch = str.substring(i, i + 1);
		if ((ch < "0" || "9" < ch)&&(ch !='$')&&(ch !='.'))
		{
			alert(msg + " field  accepts numbers.");
			return false;
		}
	}
	
	var regex_login_end		= /[A-Za-z0-9]$/ ;
	//var	regex_login_start	= /^[A-za-z]/;

	if(str.search(regex_login_end) == -1 ) {
		alert(msg+"should not end with special characters");
		return false;

	}
 return true;
}
function isCharPresent(name,str,c){

if(str.indexOf(c)==-1)
	return false;
else{
	alert("Please Dont use special Characters");
	return true;
}
}








