function getObById(id)
{
	if (document.layers) //Netscape 4
		return eval('document.' + id);
	else if (navigator.userAgent.indexOf("Opera") != -1) //Opera
		return eval("document.all."+id);
	else // all others . . .
		return document.getElementById(id);
}

function switchy(imgobj,imgsrc) {
	var imgobject = getObById(imgobj);
	imgobject.src = imgsrc;
}

var scale = 4;														// ... scale of magnification
var smallDir = 'uploads';									// ... directory where small image is kept
var largeDir = 'uploads/zoom';						// ... directory where large image is kept
var loadingSrc = '';
var largeSrc = '';
var justLoaded = 'Yes';										// ... script checks whether page has just loaded
var ie = document.all;										// ... ie
var ob = getObById && !ie;								// ... other browsers
var smallX = 0;														// ... position of small image from left
var smallY = 0;														// ... position of small image from top
var largeW = 1200;													// ... width of large image
var largeH = 1200;													// ... height of large image

function preLoad() {
	// ... preload loading graphic
	loadingSrc = new Image(47,47);
	loadingSrc.src = 'http://www.oyster-pearl-jewellery.co.uk/skins/oysterpearls/styleImages/progress.gif';
	// ... preload large image into cache
	largeSrc = new Image(getObById('ProductImage').width * scale,document.getElementById('ProductImage').height * scale);
	if(getObById('ProductImage').src.indexOf('nophoto') != -1) {
		largeSrc.src = getObById('ProductImage').src.replace('nophoto','zoom_nophoto');
	} else {
		largeSrc.src = getObById('ProductImage').src.replace(smallDir,largeDir);
	}
}
function pageLoaded() {
	justLoaded = 'No';
}
function showZoom(e) {
	var obj = ob ? e.target : event.srcElement;
	var ev = e || event;
	var zoom = getObById('ZoomPicture');
	if (largeSrc.complete == true) {
		if ((obj.className == 'Hover') && (justLoaded != 'Yes')) {
			
			
			var coors = findPos();
			
			// ... create zoom
			var zoomsrc = largeSrc.src;
			
			zoom.style.display = 'block';
			zoom.style.height = '332px';
			zoom.style.width = '320px';
			zoom.style.backgroundColor = '#eae6e0';
			zoom.style.backgroundImage = "url(" + zoomsrc + ")";
			zoom.style.backgroundRepeat = "no-repeat";
			zoom.style.position = 'absolute';
			zoom.style.left = (smallX + 310) + 'px';
			zoom.style.top = smallY + 'px';
			zoom.style.zIndex = '10';
			
			zoom.innerHTML = '';
			
			scrll = document.documentElement.scrollTop;
			
			zoom.style.backgroundPosition = (-1 * ((ev.clientX - smallX) * scale) + 150) + 'px ' + (-1 * ((ev.clientY - smallY + scrll) * scale) + 150) + 'px';
			
		} else {
			zoom.style.display = 'none';
		}
	} else {
		
		if ((obj.className == 'Hover')) {
			
			var coors = findPos();
			
			// ... create zoom
			var zoomsrc = loadingSrc.src;
			
			zoom.style.display = 'block';
			zoom.style.height = '332px';
			zoom.style.width = '320px';
			zoom.style.backgroundColor = '#f7f5f4';
			zoom.style.backgroundImage = "url(" + zoomsrc + ")";
			zoom.style.backgroundRepeat = "no-repeat";
			zoom.style.backgroundPosition = "133px 110px";
			zoom.style.border = '0';
			zoom.style.position = 'absolute';
			zoom.style.left = (smallX + 310) + 'px';
			zoom.style.top = smallY + 'px';
			zoom.style.zIndex = '10';
			
			zoom.innerHTML = '';
			
			scrll = document.documentElement.scrollTop;
			
			zoom.innerHTML = '<p style="padding: 155px 0 0 0; text-align: center;">Loading...</p>';
			
		}
	}	
}
function hideZoom(e) {
	zoom.style.display = 'none';
}
function findPos() {
	if (getObById('ProductImage').offsetParent) {
		smallX = getObById('ProductImage').offsetLeft;
		smallY = getObById('ProductImage').offsetTop;
		var op = getObById('ProductImage');
		while (op = op.offsetParent) {
			smallX += op.offsetLeft;
			smallY += op.offsetTop;
		}
		return [smallX,smallY];
	}
}


function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	
	if (matchArray==null)
	{
		alert("Please check your email address.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null)
	{
	    alert("The username doesn't seem to be valid.")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
	    for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("The domain's IP address doesn't seem to be valid.")
						return false
		    }
		}
	    return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	{
		alert("The domain name doesn't seem to be valid.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
	   alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	if (len<2)
	{
	   var errStr="This address is missing a hostname!"
	   alert(errStr)
	   return false
	}
	return true;
}



function validate(){
	if ((getObById('cmntname').value == "") || (getObById('cmntname').value == " "))
	{
		alert("Please enter your name.");
		getObById('cmntname').focus();
		return (false);
	}
	if (getObById('cmntemail').value == "")
	{
		alert("Please enter your email address.");
		getObById('cmntemail').focus();
		return (false);
	}
	if (emailCheck(getObById('cmntemail').value) != true)
	{
		//alert("Please enter a valid email address.");
		getObById('cmntemail').focus();
		return (false);
	}
	if (getObById('comment').value == "")
	{
		alert("Please enter your comment");
		getObById('comment').focus();
		return (false);
	}
	return (true);
}



function clearInput(inputid,stdtxt)
{
	var inp = getObById(inputid);
	if (inp.value == stdtxt) {
		inp.value = '';
	}
}

function resetInput(inputid,stdtxt)
{
	var inp = getObById(inputid);
	if (inp.value == '') {
		inp.value = stdtxt;
	}
}


function cartLight(onoff)
{
	if (onoff == 'on')
	{
		
	}
}
