function isSpace(stringToBeChecked, errorMessage){
	if(stringToBeChecked==""){
		window.alert(errorMessage);
		//document.form1.txtSearch.focus();
		return false;
		}
	return true;
}


function validateEmail(str){
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if(str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	   }
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//alert("Invalid E-mail ID")
		return false
		}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
  		}
	if(str.indexOf(at,(lat+1))!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	    }
	 if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    //alert("Invalid E-mail ID")
	    return false
		}
	 if(str.indexOf(dot,(lat+2))==-1){
	    //alert("Invalid E-mail ID")
	    return false
	    }
	 if(str.indexOf(" ")!=-1){
	    //alert("Invalid E-mail ID")
	    return false
		}
	 return true

}
/************************** end of function validateEmail ****************************/



/************************** All Trim starts ***********************************/
function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
/************************** All Trim ends ***********************************/



/************************** date validation starts ***********************************/
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 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)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>The date format should be : dd/mm/yyyy.</b></font>";
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter a valid month.</b></font>";
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter a valid day.</b></font>";
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter a valid 4 digit year.</b></font>";
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter a valid date.</b></font>";
		return false
	}
return true
}

function ValidateDate(dt)
{

	if (isDate(dt)==false)
	{
		return false
	}
    return true
 }
/************************** date validation ends ***********************************/

function login(str){
	var result_type=0;
     if (str.txtUN.value == "") {
	    document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Username.</b></font>";
     	document.getElementById("status").focus();
     	result_type=1;
        return false;
     }

     if (str.txtPW.value == "") {
	    document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Password.</b></font>";
     	document.getElementById("status").focus();
     	result_type=1;
        return false;
     }

	if(result_type==0) {
		str.submit();
	}
	else {
	 	alert(result_type);
	}
}

/************************** User details validation starts***********************************/

function form_validation(strForm) {


	if (strForm.txtname.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}


	if (strForm.txtusername.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Username.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtuserpassword.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtuserconfirmpassword.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Confirmation Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtuserconfirmpassword.value!=strForm.txtuserpassword.value)	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Confirmation Password must be same as Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtemail.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Email Address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	else {
		var str=strForm.txtemail.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

		if (!str.match(re)) {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the valid Email Address.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}
	if (strForm.txtwebsite.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Website address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtdesignation.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Position.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if(strForm.txtproprietor.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the Proprietor.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	for (counter = 0; counter < strForm.raddiscount.length; counter++)
	{
	if (strForm.raddiscount[counter].checked && strForm.raddiscount[counter].value=="Y")
	{
		if(strForm.txtdiscount.value=="")
		{
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the Discount Details.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}
	}








}

function form_validation_questionnaire(strForm){
if (strForm.txtname.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

if (strForm.selcountry.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please select your Country.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

if (strForm.txtcity.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your City.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

if (strForm.txtemail.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Email Address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	else {
		var str=strForm.txtemail.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

		if (!str.match(re)) {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the valid Email Address.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}

var radio_choice = false;
for (counter = 0; counter < strForm.your_age.length; counter++)
{
	if (strForm.your_age[counter].checked)
	{
		radio_choice = true;
	}
}
if (!radio_choice) {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Age.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
var radio_choice = false;
for (counter = 0; counter < strForm.sex.length; counter++)
{
	if (strForm.sex[counter].checked)
	{
		radio_choice = true;
	}
}
if (!radio_choice) {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Sex.</b></font>";
		document.getElementById("status").focus();
		return false;
	}


}

function form_validation_member(strForm) {


	if (strForm.txtname.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}


	if (strForm.txtusername.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Username.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if (strForm.txtuserpassword.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtuserconfirmpassword.value=='')	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Confirmation Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (strForm.txtuserconfirmpassword.value!=strForm.txtuserpassword.value)	{
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Confirmation Password must be same as the Password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if (strForm.txtemail.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Email Address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	else {
		var str=strForm.txtemail.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

		if (!str.match(re)) {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the valid Email Address.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}

}
function validForm(strForm1)
{
	var result=false;
	result = form_validation(strForm1);
	if(result == false){
		return false;
	}

	if (strForm1.cmdcounty.options[strForm1.cmdcounty.selectedIndex].value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your county.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if (strForm1.cmbcategory.options[strForm1.cmbcategory.selectedIndex].value=='' || (strForm1.cmbcategory.options[strForm1.cmbcategory.selectedIndex].value=='Other' && strForm1.txtothercategory.value=='') ) {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your facility.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if(strForm1.txtdesignation.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your designation.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if(strForm1.txtproprietor.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your proprietor.</b></font>";
		document.getElementById("status").focus();
		return false;
	}







}

function validForm_subcatg(strForm2)
{

	var result=false;
	result = form_validation(strForm2);
	if(result == false){
		return false;
	}

	if (strForm2.cmdcounty.options[strForm2.cmdcounty.selectedIndex].value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your county.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if (strForm2.cmbsubcategory.options[strForm2.cmbsubcategory.selectedIndex].value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your sub facility.</b></font>";
		document.getElementById("status").focus();
		return false;
	}


}

/************************** User details validation ends***********************************/

/*********Search String Validation Starts****************/
function search_str(str) {
	if(str.search_phrase.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Keyword(s).</b></font>";
		document.getElementById("status").focus();
		return false;
	}
}
/***************Search string Validation Ends*********************************/

//On change of select box from category page
function go(val,val1,form_name) {
	box = document.forms[form_name].cmdcounty;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = val+".php?id="+val1+"&id1="+destination;
}

//on member login
function valid_login(str) {
	if(str.member_login1.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Login Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if(str.member_password.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your password.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
}

//On change of select box from Search By County Page
function go_facility(val,val1,form_name) {
	box = document.forms[form_name].cmdfacility;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = val+".php?county_id="+val1+"&facility_id="+destination;
}

//validation for advanced search
function adv_search_str(str) {
	if(str.adv_search_phrase.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Keyword(s).</b></font>";
		document.getElementById("status").focus();
		return false;
	}
}

function contact_validation(str) {
	if(str.txtname.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (str.txtemail.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Email Address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	else {
		var str1=str.txtemail.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

		if (!str1.match(re)) {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the valid Email Address.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}
	if(str.txtcomments.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter your Comments.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
}



//validation for Advertisement (create and update)
function advertisement_validation(str) {


	if(str.advertisement_heading.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the Company's Name.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if(str.advertisement_name.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the advertisement's Summary.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	if (str.advertisement_email.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the advertisement's Email Address.</b></font>";
		document.getElementById("status").focus();
		return false;
	}
	else {
		var str1=str.advertisement_email.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

		if (!str1.match(re)) {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the advertisement's valid Email Address.</b></font>";
			document.getElementById("status").focus();
			return false;
		}
	}
	if(str.advertisement_phone.value=='') {
		document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the advertisement's Telephone.</b></font>";
		document.getElementById("status").focus();
		return false;
	}

	if(document.getElementById("upd_contents")!=null)
	{
	var texteditor=document.frames['upd_contents___Frame'].document.frames[0].document.getElementsByTagName('body')[0];
	}
	else
	{
	var texteditor=document.frames['contents___Frame'].document.frames[0].document.getElementsByTagName('body')[0];
	}
		texteditor.focus();
		if(texteditor.innerHTML.length==0 || texteditor.innerHTML=="<P>&nbsp;</P>") {
			document.getElementById("status").innerHTML="<font color='#FF0000'><b>Please enter the advertisement's Text.</b></font>";
			document.getElementById("status").focus();
			return false;
		}

}
