// email id 

function echeck(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					
	}
	
	
	// Number check
	
	function isNumber(obj)
{
setTimeout(function(){
if(isNaN(obj.value))
{
alert("Input must be numeric");
obj.value=""
obj.focus()

}
},1);
}

// function to validate main page search

function Validatesearch(){
   
   var searchfor=document.homesearch.txtsearchfor
	
	if ((searchfor.value==null)||(searchfor.value=="")){
		alert("Please Select search for")
		searchfor.focus()
		return false
	}

    var search=document.homesearch.txtsearch
	
	if ((search.value==null)||(search.value=="")){
		alert("Please enter search key")
		search.focus()
		return false
	}

	return true
 }


// function to validate main page subscrobe from
function ValidateForm(){
   
   var name=document.frmsubscribe.txtname
	
	if ((name.value==null)||(name.value=="")){
		alert("Please Enter your name")
		name.focus()
		return false
	}

	var emailID=document.frmsubscribe.txtemailid
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	var mobile=document.frmsubscribe.txtmobile
	
	if ((mobile.value==null)||(mobile.value=="")){
		alert("Please Enter mobile number")
		mobile.focus()
		return false
	}
	if ((mobile.value.length<10)){
		alert("Please Enter 10 digit mobile number")
		mobile.focus()
		return false
	}
	var spam=document.frmsubscribe.txtspam
	var checkspam=document.frmsubscribe.txtcheckspam
	
	if ((spam.value==null)||(spam.value=="")){
		alert("Please Enter spam code")
		spam.focus()
		return false
	}
    if ((spam.value!=checkspam.value)){
		alert("Please Enter valid spam code")
		spam.focus()
		return false
	}

	return true
 }

// validation for book search 

function ValidatesearchForm(){
   
   var search=document.booksearch.txtsearch
	
	if ((search.value==null)||(search.value=="")){
		alert("Please Enter string to search")
		search.focus()
		return false
	}

	return true
 }


// validation for book Order or Valume 

function ValidateinquiryForm(){
   
   var name=document.bookinquiry.txtname
	
	if ((name.value==null)||(name.value=="")){
		alert("Please Enter Name")
		name.focus()
		return false
	}
	
	var email=document.bookinquiry.txtemail
	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter Email Id")
		email.focus()
		return false
	}
	
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	
	var mobile=document.bookinquiry.txtmobile
	
	if ((mobile.value==null)||(mobile.value=="")){
		alert("Please Enter Mobile Number")
		mobile.focus()
		return false
	}
	if ((mobile.value.length<10)){
		alert("Please Enter valid mobile number")
		mobile.focus()
		return false
	}

	
	var inquiry=document.bookinquiry.txtinquiry
	
	if ((inquiry.value==null)||(inquiry.value=="")){
		alert("Please Enter Inquiry Details")
		inquiry.focus()
		return false
	}


	return true
 }

/// Q/A Forum post Question

function validatequestion(){
   
   var question=document.postquestion.txtquestion
	
	if ((question.value==null)||(question.value=="")){
		alert("Please Enter question")
		question.focus()
		return false
	}
	
	return true
 }


maxL=150;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
	
}



///  User Login

function validatelogin(){
   
   var username=document.userlogin.txtusername
	
	if ((username.value==null)||(username.value=="")){
		alert("Please Enter Username")
		username.focus()
		return false
	}
	
	var password=document.userlogin.txtpassword
	
	if ((password.value==null)||(password.value=="")){
		alert("Please Enter password")
		password.focus()
		return false
	}

	
	return true
 }
 
 //////// Contact Us
 
 
 function Validatecontactus(){
	var emailID=document.frmcontactus.txtemailid
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	var comment=document.frmcontactus.txtcomment
	
	if ((comment.value==null)||(comment.value=="")){
		alert("Please Enter your comment")
		comment.focus()
		return false
	}
	
var vcode=document.frmcontactus.txtverificationcode
 var code=document.frmcontactus.code
 
if ((code.value==null)||(code.value=="")){
		alert("Please Enter Verification code")
		code.focus()
		return false
	}
	
if((vcode.value!=code.value)){
	alert("Please Enter valid Verification code")
	code.value=""
	code.focus()
	return false
    }

//http://overtures.in/newislamimarkaz/
	return true
 }


