function ChkImgFile(cntrl)
{
		if(cntrl.value != "")
		{
		    var str =cntrl.value;
		    var cnt = str.substring(str.lastIndexOf('.'),str.length) ;
		    if ( cnt !=".jpg" && cnt != ".jpeg" &&  cnt != ".png" && cnt != ".gif" )
		    {
		        alert("Invalid Image Format! only .jpg, .png, .gif files allowed.");
				cntrl.value = "";
		        cntrl.focus();
		        return false;
		    }		
		}
		return true;
}

function goImgWin(myImage,myWidth,myHeight,origLeft,origTop) {
myHeight += 24;
myWidth += 24;
TheImgWin = window.open(myImage,'image','height=' +
myHeight + ',width=' + myWidth +
',toolbar=no,directories=no,status=no,' +
'menubar=no,scrollbars=no,resizable=yes');
TheImgWin.resizeTo(myWidth+2,myHeight+30);
//TheImgWin.moveTo(origLeft,origTop);
TheImgWin.focus();
}

function isValidURL(cntrl){ 
	var url=cntrl.value;
	var RegExp = /http:\/\/www\.\w[\w\-]+(\.\w[\w\-]+)+$/; 
    if(RegExp.test(url)){ 
        return true; 
    }else{ 
        alert("Please enter valid URL!(example: http://www.yourdomain.com or http://www.yourdomain.co.uk)");
		cntrl.value = "";
		cntrl.focus();
		return false; 
    } 
} 


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

}

function CheckEmpty(cntrl, strMsg)
{
	if (cntrl.value == "")
	{
		alert(strMsg  + " is required.Please enter " + strMsg + ".");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function CheckEmptyEmail(cntrl)
{
	if (cntrl.value == "")
	{
		alert("Email address can not be blank. Please enter a valid Email address");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function CheckString(cntrl)
{
	var ch;
	ch = cntrl.value.search("[^A-Za-z' ]");
	if(cntrl.value.length > 0 &&  ch>= 0) 
	{
		alert("Please enter alphabets only!");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}
        
function CheckPhone(cntrl)
{
	if(!RegExp(/^[0-9][\d\- ]*[0-9]$/).test(cntrl.value))
	{
		alert("Phone number does not appear to be valid. Please check!");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function CheckNumber(cntrl)
{
	if(!RegExp(/^[0-9][\d\- ]*[0-9]$/).test(cntrl.value))
	{
		alert("Please enter numbers only!");
		cntrl.value="";
		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.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckPassLength(cntrl)
{
	if (cntrl.value.length < 4)
	{
		alert("Please enter a Password that is atleast 4 characters using only letters and numbers.");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckEmail(cntrl)
{
	if(!RegExp(/^[A-Za-z][\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(cntrl.value))
	{
		alert("Incorrect email address format. Please type a valid email address. Example: john_23@yahoo.com");
		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!");
		cntrl.value = "";
		cntrl2.focus();
		return false;
	}
	else 
	{
		return true;
	}
}

function CheckLength(cntrl,strCntrlName,len)
{
	if (cntrl.value.length < 0)
	{
		alert(strCntrlName+" should have at least one characters. Please check!");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	else if (cntrl.value.length > len)
	{
		alert(strCntrlName+" should have less than "+len+" characters. Please check!");
		cntrl.value = "";
		cntrl.focus();
		return false;
	}
	
	else
	{
		return true;
	}
}

function CheckDate(d,m,y)
{
	var toDay = new Date();

	var monthfield=m
	var dayfield=d
	var yearfield=y
	var dayobj = new Date(yearfield, monthfield-1, dayfield)

	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
	{
		alert("Invalid Day, Month, or Year range detected. Please correct and submit again.");
		return false;
	}	
	
	/*
	if(dayobj > toDay)
	{
		alert("You cannot enter future date");
		return false;
	}
	else {
		return true;
	}
	*/
	return true;	
}

function SelectEmpty(cntrl, strMsg)
{
	if (cntrl.value == "")
	{
		alert("Please select " + strMsg + "!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function CheckSpecialString(cntrl,strMsg)
{
	var myRegExp = /!|@|#/;
	string1=cntrl.value
	var matchPos1 = string1.search(myRegExp);
		if(matchPos1 != -1)
		{ 
			alert("Please enter a valid "+ strMsg + "!"); 
			cntrl.value="";
			cntrl.focus();
			return false; 
		}
		else {
		return true;
	}
		var charpos = cntrl.value.search("[']"); 
		
        if(cntrl.value.length > 0 &&  charpos >= 0) 
        { 
             alert( "Please enter a valid "+ strMsg + "!");  
			 cntrl.value="";
			 cntrl.focus();
             return false; 
        }
		else {
		return true;
	   }
		var charpos = cntrl.search("[$]"); 
		
        if(cntrl.value.length > 0 &&  charpos >= 0) 
        { 
             alert( "Please enter a valid "+ strMsg + "!"); 
			 cntrl.value="";
			 cntrl.focus();
             return false; 
        }  
		else {
		return true;
	   }
		var charpos = cntrl.value.search("[%]"); 
		
        if(cntrl.value.length > 0 &&  charpos >= 0) 
        { 
             alert( "Please enter a valid Page URL!"); 
			 cntrl.value="";
			 cntrl.focus();
             return false; 
        }   
		else {
		return true;
	    }
		var charpos = cntrl.value.search("[&]"); 
		
        if(cntrl.value.length > 0 &&  charpos >= 0) 
        { 
             alert( "Please enter a valid First Name!");
			 cntrl.value="";
			 cntrl.focus();
             return false; 
        }  
		else {
		return true;
	    }
		var charpos = cntrl.value.search("[*]"); 
		
        if(cntrl.value.length > 0 &&  charpos >= 0) 
        { 
             alert( "Please enter a valid Page URL! "); 
			 cntrl.value="";
			 cntrl.focus();
             return false; 
        }  
	else {
		return true;
	}
}