jQuery.fn.amail = function(sAt,sDot,sRepl){
	if (!sAt)
		sAt = '||';
	if (!sDot)
		sDot = '|';
	if (!sRepl)
		sRepl = 'NOSPAM';
	this.each(function() {
		el = jQuery(this);
		var mail = el.text().replace(sAt,'@').replace(sDot,'.').replace(sRepl,'');
		el.each(function(){
		el.attr('href','mailto:' + mail);
		if(el.attr('title')){
			el.html(el.attr('title'));
		}else{
			el.html(mail);
			}
		});
	});
};
/* OPTOMETRIST BG */
function optocta() {
	document.getElementById('optoctabg').style.display='block';
	document.getElementById('optoctaclose').style.display='block';
	document.getElementById('ausmap').style.opacity='0.2';
	document.getElementById('ausmap').style.filter='alpha(opacity=20)';
	document.appointment_form.name.focus();
	window.scroll(0,160)
}
function optoctaclose() {
	document.getElementById('optoctabg').style.display='none';
	document.getElementById('optoctaclose').style.display='none';
	document.getElementById('ausmap').style.opacity='1';
	document.getElementById('ausmap').style.filter='alpha(opacity=100)';
}

/* OPTOMETRIST BG */
 /* For the form in book-an-appointment  */
function nextStep(step) {
	if(step==2) {
		jQuery('#booking1').removeClass('onfocus').addClass('done');
		jQuery('#booking2').addClass('onfocus');
	}
	if(step==3) {
		jQuery('#booking2').removeClass('onfocus').addClass('done');
		jQuery('#booking3').addClass('onfocus');
	}
	if(step==4) {
		jQuery('#booking3').removeClass('onfocus').addClass('done');
		jQuery('#booking4').addClass('onfocus');
	}
}

function show(whatever) {
		jQuery('#'+whatever).fadeIn('slow');
}
function hide(whatever) {
		jQuery('#'+whatever).fadeOut('slow');
}

function showcomginsoontop(whatever) {
		jQuery('#'+whatever).fadeIn('slow');
}
function hidecomginsoontop(whatever) {
		jQuery('#'+whatever).fadeOut('slow');
}

function showcomginsoonbottom(whatever,myleft,mytop) {
	jQuery('#'+whatever).css({"left": myleft});
	jQuery('#'+whatever).css({"top": mytop});
	jQuery('#'+whatever).css({"width": "180px"});
	jQuery('#'+whatever).fadeIn('slow');
}
function hidecomginsoonbottom(whatever) {
		jQuery('#'+whatever).fadeOut('slow');
}

function postme(){
	location.href=postme.arguments[0];
}

function load_store(){
	jQuery('#div-filter-stores').load('filter-store-locator.php?state='+load_store.arguments[0]);
	}
	
function emailvalidation(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					
	}

function validate_form(){
	var count=0;
	if(document.getElementById("state").value=="")
	{
		document.getElementById("lbl-location").innerHTML="<font color=red><strong>Select your location:</strong></font>";
		count++;
	}else{
		document.getElementById("lbl-location").innerHTML="Select your location:";
		}
	if(document.getElementById("app-store").value=="")
	{
		document.getElementById("lbl-store").innerHTML="<font color=red><strong>Select nearest Store:</strong></font>";
		count++;
	}else{
		document.getElementById("lbl-store").innerHTML="Select nearest Store:";
		}	
	if(document.getElementById("title").value=="")
	{
		document.getElementById("lbltitle").innerHTML="<font color=red><strong>Title:</strong></font>";
		count++;
	}else{
		document.getElementById("lbltitle").innerHTML="Title:";
		}
		
	if(document.getElementById("fullname").value=="")
	{
		document.getElementById("lblfullname").innerHTML="<font color=red><strong>Full Name:</strong></font>";
		count++;
	}else{
		document.getElementById("lblfullname").innerHTML="Full Name:";
		}	

	if(document.getElementById("address").value=="")
	{
		document.getElementById("lbladdress").innerHTML="<font color=red><strong>Address:</strong></font>";
		count++;
	}else{
		document.getElementById("lbladdress").innerHTML="Address:";
		}

	if(document.getElementById("city").value=="")
	{
		document.getElementById("lblcity").innerHTML="<font color=red><strong>City:</strong></font>";
		count++;
	}else{
		document.getElementById("lblcity").innerHTML="City:";
		}

	if(document.getElementById("form-state").value=="")
	{
		document.getElementById("lblstate").innerHTML="<font color=red><strong>State:</strong></font>";
		count++;
	}else{
		document.getElementById("lblstate").innerHTML="State:";
		}

	if(document.getElementById("postcode").value=="")
	{
		document.getElementById("lblpostcode").innerHTML="<font color=red><strong>Postcode:</strong></font>";
		count++;
	}else{
		document.getElementById("lblpostcode").innerHTML="State:";
		}
		
	if(document.getElementById("phone").value=="")
	{
		document.getElementById("lblphone").innerHTML="<font color=red><strong>Phone:</strong></font>";
		count++;
	}else{
		document.getElementById("lblphone").innerHTML="Phone:";
		}		

	if(emailvalidation(document.getElementById("email").value)==false)
	{
		document.getElementById("lblemail").innerHTML="<font color=red><strong>Email:</strong></font>";
		count++;
	}else{
		document.getElementById("lblemail").innerHTML="Email:";
		}
	if(document.getElementById("chkprivacy").checked==false)
	{
		document.getElementById("lblprivacy").innerHTML="<font color=red><strong>I agree with the terms of your privacy policy</strong></font>";
		count++;
	}else{
		document.getElementById("lblprivacy").innerHTML="I agree with the terms of your privacy policy";
		}
		
		
	if(count>0){
		return false;
	}
	
}


function validate_app_form(){
	var count=0;
	if(document.getElementById("name").value=="")
	{
		document.getElementById("lblname").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblname").style.color="#000000";
		}	

	if(document.getElementById("address").value=="")
	{
		document.getElementById("lbladdress").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lbladdress").style.color="#000000";
		}

	if(emailvalidation(document.getElementById("email").value)==false)
	{
		document.getElementById("lblemail").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblemail").style.color="#000000";
		}


	if(document.appointment_form.txtAppointmentType[0].checked==false && document.appointment_form.txtAppointmentType[1].checked==false && document.appointment_form.txtAppointmentType[2].checked==false)
	{
		document.getElementById("spantype1").style.color="#ff0000";
		document.getElementById("spantype2").style.color="#ff0000";
		document.getElementById("spantype3").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("spantype1").style.color="#000000";
		document.getElementById("spantype2").style.color="#000000";
		document.getElementById("spantype3").style.color="#000000";
		
		}		

	if(document.getElementById("datechoice1").value=="")
	{
		document.getElementById("lbldatechoice1").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lbldatechoice1").style.color="#000000";
		}

	if(document.getElementById("time1").value=="")
	{
		document.getElementById("lbldatechoice1").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lbldatechoice1").style.color="#000000";
		}
		
	if(document.getElementById("chkprivacy").checked==false)
	{
		document.getElementById("lblchkprivacy").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblchkprivacy").style.color="#000000";
		}	
	if(document.getElementById("city").value=="")
	{
		document.getElementById("lblcity").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblcity").style.color="#000000";
		}
	if(document.getElementById("form-state").value=="")
	{
		document.getElementById("lblstate").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblstate").style.color="#000000";
		}
	if(document.getElementById("postcode").value=="")
	{
		document.getElementById("lblpostcode").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblpostcode").style.color="#000000";
		}
	if(document.getElementById("phone").value=="")
	{
		document.getElementById("lblphone").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblphone").style.color="#000000";
		}
	if(count>0){
		return false;
	}
	
}
function validate_comment_form(){
	var count=0;

	if(document.getElementById("author").value=="")
	{
		document.getElementById("lblauthor").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblauthor").style.color="#000000";
		}	

	if(emailvalidation(document.getElementById("email").value)==false)
	{
		document.getElementById("lblemail").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblemail").style.color="#000000";
		}

	if(document.getElementById("comment").value=="")
	{
		document.getElementById("lblcomment").style.color="#ff0000";
		count++;
	}else{
		document.getElementById("lblcomment").style.color="#000000";
		}			
	if(count>0){
		return false;
	}
		
}
