function CheckEmpty(cntrl, strMsg)
{
	if (cntrl.value == "")
	{
		alert("Please enter " + strMsg + "!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckRadio(cntrl, strMsg)
{
	var i = 0;
	var g = 0;
	while(i < cntrl.length)
	{		
		if(cntrl[i].checked == true) 
			g = 1;
		i++;
	}	
	if(g != 1){
		alert("Please select " + strMsg + "!");
		//cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckCombo(cntrl, strMsg)
{	
	if(cntrl.value < 1){
		alert("Please select " + strMsg + "!");
		//cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckString(cntrl)
{
	if(!RegExp("^[A-Za-z][\w]*[A-Za-z]+$").test(cntrl.value))
	{
		alert("Please enter alphabets only!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckPhone(cntrl)
{
	if(!RegExp(/^[0-9][\d\- ]*[0-9]$/).test(cntrl.value))
	{
		alert("Contact number does not appear to be valid. Please check!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckAlphaNumerals(cntrl)
{
	if(!RegExp(/^[a-zA-Z][\w\d\ \.,-]*[a-zA-Z0-9]$/).test(cntrl.value))
	{
		alert("Please enter alphanumerals only!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckNumerals(cntrl,str)
{
	if(!(cntrl.value).match(/^\d+$/ ))
	{
		alert(str+" should be numeric only!");
		cntrl.value = 0;
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckPrice(cntrl,str)
{
	if(!(cntrl.value).match(/(^\d+$)|(^\d+\.\d+$)/))
	{
		alert(str+" should be possitive numerals only!");
		cntrl.value = 0;
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckPassLength(cntrl)
{
	if (cntrl.value.length < 4)
	{
		alert("Password should have at least four charachers. Please check!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckEmail(cntrl)
{
	if(!RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(cntrl.value))
	{
		alert("This Email ID does not appear to be valid. Please check!");
//		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function ConfirmPassword(cntrl1, cntrl2)
{
	if(cntrl1.value != cntrl2.value)
	{
		alert("Password doesn't match with confirmation password. Please check!");
		cntrl2.focus();
		return false;
	}
	else 
	{
		return true;
	}
}

function CheckURL(cntrl)
{
	if(!RegExp( /^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&/=]+$/).test(cntrl.value))
	{
		alert("This URL does not appear to be valid. Please check!");
//		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateCaptcha(cntrl1,cntrl2)
{
	if(cntrl1.value != cntrl2.value)
	{
		alert("Please enter the correct CAPTCHA!");
		cntrl2.value = "";
		cntrl2.focus();
		return false;
	}
	
	else
		return true;
}

function CompareDates(f_date,t_date){
	//alert(document.getElementById("from_date"));	
		if (f_date.value != "" && t_date.value != "")
		{
			dt1=new Date(f_date.value);
			dt2=new Date(t_date.value);
		
			if(dt1>dt2){
				alert("'From date' is greater than 'To date'. ");
				return false;
			}
			else
				return true;		
			
		}
		if (f_date.value != "")
		{
			dt1=new Date(f_date.value);			
			if(dt1){
				alert("'From date' is not valid. ");
				return false;
			}
			else
				return true;
		}
	}	


function checkDateRange(startDate,endDate) {
   // Parse the entries
   		var sd = startDate.value;
		var ed = endDate.value;
		sd = sd.replace(/-/g,"/");
		ed = ed.replace(/-/g,"/");
	   var startDate = Date.parse(sd);
	   var endDate = Date.parse(ed);
	   // Make sure they are valid	   
		if (isNaN(startDate)) {
		  alert("The From date provided is not valid, please enter a valid date.");
		  return false;
	   }
	   if (isNaN(endDate)) {
		   alert("The To date provided is not valid, please enter a valid date.");
		   return false;
	   }
	   // Check the date range, 86400000 is the number of milliseconds in one day
	   var difference = (endDate - startDate) / (86400000 * 7);
	   if (difference < 0) {
		   alert("The from date must come before the to date.");
		   return false;
	   }
	   return true;
	}
	

//	Contact Number validation start from here

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;


function CheckContactNumber(cntrl)
{

	if (checkInternationalPhone(cntrl.value) == false)
	{
		alert("Contact number does not appear to be valid. Please check!")
		cntrl.value=""
		cntrl.focus()
		return false
	}
	return true
}
			  
function checkInternationalPhone(strPhone)
{
	var bracket = 3;
	strPhone = trim(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket = bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket) return false
	var brchr = strPhone.indexOf("(");
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function trim(s)
{   
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function CheckShortDescCharLengthSpecial(cntrl)
{ 
//	alert(cntrl.value.length);
	if(cntrl.value.length > 600)
	{
		alert("You have exceeded the maximum number of characters for comments. ");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

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 ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
			  			  			  
//	Contact Number validation end here
//	Define a function to check the length of a title. It must be <= 65

function CheckTitleLength(cntrl)
{
//	alert(cntrl.value.length);
	if(cntrl.value.length > 120)
	{
		alert("The number of characters should not exceed 120!");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
		return true;
}
