// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

// Extract Cart id from header and goto requested page
function updateParent(newURL){
	oldURL = String(opener.document.location);
	tempStart = oldURL.indexOf("cart_id");
	if (tempStart > 0){
		tempString = oldURL.substring(tempStart, oldURL.length);
		tempEnd = tempString.indexOf("&");
		if (tempEnd < 0){
			tempEnd = tempString.length;
		}
		tempCartid = tempString.substring(0, tempEnd);
		opener.document.location = newURL+"&"+tempCartid;
	} else {
		opener.document.location = newURL;
	}
	opener.window.focus();
}

function addToFavourites() {
	var urlAddress = "http://www.thejewellerycompany.com";
	var pageName = "TheJewelleryCompany.com";
	if (window.external){
		window.external.AddFavorite(urlAddress,pageName);
     }else{
	 	alert("Sorry! Your browser doesn't support this function.");
     }
}

<!-- This script will validate that the required fields are set  -->
function fixElement(element, message) {
	alert(message);
	element.focus();
}

function isFormReady(form) {
	var passed = false;
	if (form.keywords.value == "" || form.keywords.value == "Search") {
		fixElement(form.keywords, "Please enter something to search for!");
	} else {
		passed = true;
	}
	return passed;
}

function ViewCrossReference (selSelectObject){
	if(selSelectObject.options[selSelectObject.selectedIndex].value != ""){
		location.href=selSelectObject.options[selSelectObject.selectedIndex].value
	}
}
<!-- End script to validate required fields -->

function AdvancedSearch (form, numItems){
	var passed = false;
	var keywords = "";
	//var numItems = 6;
	for (var loop = 1; loop <= numItems; loop++){
		if (eval("form.search"+loop+".value").length > 0){
			if (keywords.length > 0){
				keywords += " ";
			}	
		keywords += eval("form.search"+loop+".value");
		}
	}	
	//alert (keywords);
	if (keywords.length < 1) {
		alert ("Please enter something to search for!");
	} else {
		form.keywords.value = keywords;
		passed = true;
	}
	return passed;
}

// detect browser & OS
var detect = navigator.userAgent.toLowerCase();

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function checkBrowser(){

	var OS,browser,version,total,thestring;
	//alert(detect);
	
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		//version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	
	//if (!version) version = detect.charAt(place + thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}

	if (OS == "Windows")
	{
		return true;
	}else{
		return false;
		}
}

function openBrWindow(url,scrollbars,resizable,w,h){
	if (checkBrowser() != true){
		//alert(h);
		//h = parseInt(h) + 20;
		//alert(h);
	}
	//alert(h);
	window.open(url,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + w + ',height=' + h,'');
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); 
  if (obj) obj.value = newText;
}

// End -->

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Style(form){
	alert(form);
	//location.replace(form);
	place = form.indexOf("|");
	alert(place);
	style = form.substring(0,place);
	alert(style);
	open = MM_openBrWindow('static/size-guide.htm','','scrollbars=yes,resizable=yes,width=450,height=450');
	return open;
}




// flash cookie
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
//           - Wdy, DD-Mon-YYYY HH:MM:SS GMT
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	//alert (curCookie);
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}













//// INSERT FLASH ELEMENT OR ALTERATIVE IF USER HASN'T THE CORRECT PLAYER////

function insertFlash(swf,width,height,bgcolor,params,altimage,urllink,target) {
//alert (swf+"\n"+width+"\n"+height+"\n"+bgcolor+"\n"+params+"\n"+altimage+"\n"+urllink+"\n"+target);
	params.version = parseInt(params.version.substring(params.version.indexOf(".")-1));
	// does user have minimum player to view swf 
	if(myFlashPlayer<params.version){
		if (altimage.indexOf(".jpg")!= -1 || altimage.indexOf(".gif")!= -1){
			// no flash but alternative image specified
			if (urllink){
			document.write("<a href=\""+urllink+"\" target=\""+target+"\"><img src=\""+altimage+"\" target=\""+target+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" BORDER=\"0\"></a>");
			}else{
			document.write("<img src=\""+altimage+"\" target=\""+target+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" BORDER=\"0\">");
			}
		}else{
			if (altimage.indexOf(".js")!= -1){
				// no flash but javascript alternative specified
				insertJS(altimage);
			}else{
				if (altimage=="") {
					// no flash & no alternative
					document.write("<p align=\"center\"><a href=\"javascript:GoGetFlash()\"><font color=\"#CCCCCC\" size=\"1\" face=\"Arial, Helvetica, sans-serif\">YOU REQUIRE FLASH PLAYER "+params.version+" TO VIEW THIS.<br>CLICK HERE TO DOWNLOAD THE LATEST FLASH PLAYER.</font></a></p>");
				}	
			}
		}
	}else{
		// set default bgcolor if not provided
		if(!bgcolor || bgcolor=="") bgcolor = "#FFFFFF";
		if(!params) params = new Object();
		if(!params.version) params.version = maxFlashPlayer;
		// parse parameters
		var objectParams = "";
		var embedParams = "";
		for (var i in params) {
			objectParams += "<PARAM NAME="+i+" VALUE=\""+params[i]+"\">\n";
			embedParams += i+"="+params[i];
		}
		// write the object
		document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
		document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+params.version+"\"");
		document.write("WIDTH=\""+width+"\" HEIGHT=\""+height+"\" id=\"flash\" ALIGN=\""+params.align+"\">");
		document.write("<PARAM NAME=movie VALUE=\""+swf+document.location.search+"\">"); 
		document.write("<PARAM NAME=quality VALUE=high>");
		document.write("<PARAM NAME=bgcolor VALUE="+bgcolor+">");
		document.write(objectParams);
		document.write("<EMBED src=\""+swf+document.location.search+"\" quality=high scale=exactfit bgcolor=\""+bgcolor+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" ALIGN=\""+params.align+"\"" );
		document.write(embedParams);
		document.write("TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>");
		document.write("</OBJECT>");
	}
}

//// CHECK COOKIE FOR LGT FLASH PLAYER ////

function Check4FlashCookie(){
	myFlashPlayer = getCookie('myFlashPlayer');
	//alert("myFlashPlayer="+myFlashPlayer);
	if (myFlashPlayer == null){
	Sniff4FlashPlayer();
	setCookie('myFlashPlayer', myFlashPlayer)
}

function Sniff4FlashPlayer(){
	// INTIALISE VARIABLES //
	maxFlashPlayer="20";//10,0,0,0
	myFlashPlayer=0;
	//// Find Flash Player Version! ////
	if(!supportedBrowser){myFlashPlayer=0;}
	if(NNpass || macIEpass){Flash_checkForPlugIn();}
	if(winIEpass){myFlashPlayer = (Flash_checkForActiveX());}
	}
}







////  BROWSER DETECTION  ////

// Is this a Mac running Microsoft Internet Explorer V5+ or Opera
macIEpass = ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.indexOf("Mac") != -1)) && (parseFloat(navigator.appVersion) >= 4) ? true : false; 
 
// Is this a PC running Microsoft Internet Explorer V4+
winIEpass = ((navigator.appName.indexOf("Microsoft") != -1) && (navigator.appVersion.indexOf("Windows") != -1)) && (parseFloat(navigator.appVersion) >= 4) ? true : false;
  
// Is this a Mac or PC running Netscape V4+ or a Mac running Safari
NNpass = ((navigator.appName == "Netscape") && (navigator.userAgent.indexOf("Mozilla") != -1) && (parseFloat(navigator.appVersion) >= 4)) ? true : false;
//  (navigator.javaEnabled())) ? true : false; Doesn't work with Mac Nav7+

supportedBrowser = (winIEpass || NNpass || macIEpass) ? true : false;
//alert ("Browser: Windows="+winIEpass+"  Nestcape="+NNpass+"  Mac IE="+macIEpass); -- for testing purposes
	
////  END BROWSER DETECTION  ////


//// FLASH DETECTION ////

function Flash_checkForPlugIn() {
  var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ?
  navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if (plugin) {
    myFlashPlayer = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) 
  }
}

// vbscript check for Flash ActiveX control in windows IE
if(supportedBrowser && winIEpass) {
  document.write('<scr' + 'ipt language="VBScript"\> \n');
  document.write('Function Flash_checkForActiveX()' + '\n');
  document.write('Dim hasPlayer, playerversion' + '\n' );
  document.write('hasPlayer = false' + '\n' );
  document.write('playerversion = 10' + '\n' );
  document.write('Do While playerversion >= 1' + '\n' );
  document.write('On Error Resume Next' + '\n');
  document.write('hasPlayer = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & playerversion & \"\")))' + '\n' );
  document.write('If hasPlayer = true Then Exit Do' + '\n' );
  document.write('playerversion = playerversion - 1' + '\n');
  document.write('Loop' + '\n');
  document.write('Flash_checkForActiveX = playerversion' + '\n');
  document.write('End Function' + '\n');
  document.write('</scr' + 'ipt\> \n');
}

//// END FLASH DETECTION ////


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 

		
		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center">Loading...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
				
    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '<p style="padding-left:10px;" class="product_intro_text">' + ' '+title + '</p>'
		newHTML = newHTML + '</div>'; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}		

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}


var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}
