// JavaScript Document

//	Bookmark Page
function bookmarksite(){
var myloc = location.href;
var title = "ORA Dentistry Spa";
// check if active
// alert (title+"\r\n"+myloc);
if (document.all)
window.external.AddFavorite(myloc,title);
else if (window.sidebar)
window.sidebar.addPanel(title, myloc,"")
}

//	Send to Friend

function sendtofriend() {
	// alert (URL);
	var URL 
	URL = location.href;
	window.open('sendtofriend.htm?page='+URL, 'EmailWindow', 'scrollbars=yes,width=780,height=355');
}


//	Key Restrict

function getKeyCode(e){
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function keyRestrict(e, validchars){ 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}


//	Contact Form

function SendApp() {
	var cForm = document.frmAppointment;
	var ctr = 0;
	
	if (cForm.txtFName.value=="First Name:") {
		alert("Please type in your First Name.");
		cForm.txtFName.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtLName.value=="Last Name:") {
		alert("Please type in your Last Name.");
		cForm.txtLName.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtAddress.value=="Address:") {
		alert("Please type in your Address.");
		cForm.txtAddress.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtCity.value=="City:") {
		alert("Please type in your City.");
		cForm.txtCity.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtState.value=="State or Country:") {
		alert("Please type in your State or Country.");
		cForm.txtState.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtZip.value=="Zip or Postal Code:") {
		alert("Please type in your Zip or Postal Code.");
		cForm.txtZip.focus();
		var ctr = 1;
	}
	
	else if(cForm.txtPhone.value=="Phone (home):") {
		alert("Please type in your Phone Number");
		cForm.txtPhone.focus();
		var ctr = 1;
	}
	
	else if(cForm.txtEmail.value=="E-mail:") {
		alert("Please type in your Email Address.");
		cForm.txtEmail.focus();
		var ctr = 1;
	}
		
	else if (CheckEmail(cForm.txtEmail.value)==false) {
		alert("Please check your Email Address.");
		cForm.txtEmail.focus();
		var ctr = 1;
	}
	
	else if (cForm.txtAppDate.value=="Appointment Date:") {
		alert("Please type in your desired Appoinment Date.");
		cForm.txtAppDate.focus();
		var ctr = 1;
	}
	
	if(ctr == 0){
	cForm.SendMsg.value="okay";
	cForm.submit();
	
	}
}

//################################################
//				To Check the Email
//################################################

function CheckEmail(Email){
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Email)) {
  return true
 }
 
 return (false)
}

//////////////////////////////////////////////////
function clrField(txtfield) {
if (txtfield.defaultValue==txtfield.value) { 
	txtfield.value = "" 
	}
} 

function rplceField(txtfield) {
	if (txtfield.value=="") { 
	txtfield.value = txtfield.defaultValue 
	}
}
/////////////////////////////////////////////////


/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		
		xOffset = 100;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var docwidth=$(document).width();
		var docheight=$(document).height();
		//alert(docwidth);
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' width='300' height='250'/>"+ c +"</p>");								 		var mleft =0;
		//alert(docwidth);
		//alert(e.pageX);
		var hati = (docwidth/2)
		if(hati >  e.pageX){
			mleft = e.pageX + yOffset
		}
		else{
			mleft = e.pageX - 300 - yOffset
		}
		//alert(mleft);
		
		
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(mleft) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		var docwidth=$(document).width();
		var docheight=$(document).height();	
		var hati = (docwidth/2)
		if(hati >  e.pageX){
			mleft = e.pageX + yOffset
		}
		else{
			mleft = e.pageX - 300 - yOffset
		}
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(mleft) + "px");
	});	
	
	$("a.preview").click(function(){
	location.href="product.html?product_id="+this.href;
	});
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});



/////////////////////////////////////////////////////////////////////////////////////////////////////////////
























