//**********************
//Must include this on each storefront page using
//<script language="JavaScript" src="header.js"></script>
//To Do:	
//	1) Modify my_track and create an entry on the Franchise Control Panel for each franchise site;
//	2) Modify my_initial if the storefront pages reside on a different domain or folder.
//**********************

var my_track = "self";
var my_initial = "include/initial.asp";
var my_detail = "detail.htm";

var myStyle = 
	'&linecolor=' + escape('#000066') + 
	'&menu=category' + 
	'&body=bodyblue' + 
	'&bold=bodyheading' + 
	'&hlcolor=' + escape('#EFEDFC') + 
	'&bgcolor=' + escape('#EFEDFC') + 
	'&hdcolor=' + escape('#000066') + 
	'&idcolor=' + escape('#FFFFFF') + 
	'&header=bodywhite' + 
	'&rowcolor=' + escape('#EFEDFC') + 
	'&row=bodyblack' + 
	'&label=bodyblue' + 
	'&heading=heading' + 
	'&detail=' + escape(my_detail) + 
	'&popup=yes' + 
	'&zoom=yes' + 
	'';

InitialHeader(false);
function InitialHeader(bRefresh)
{
var i, sStr, page, curPage = "" + window.location, myid = "";
	curPage = curPage.toLowerCase();
//	REM shifted into initial.js
//	if (curPage.indexOf('&rnd=') > 0 || curPage.indexOf('?rnd=') > 0 ) bRefresh = true;
	if (curPage.indexOf('.asp') > 0 && window.goback && window.goback.length) 
	{
		sStr = curPage;
		i = sStr.lastIndexOf("/");
		if (i > 0) sStr = sStr.substring(0, i+1);
		curPage = goback.toLowerCase();
		if (curPage.indexOf(sStr) == 0)	curPage = "";
		//update my_detail
		i = curPage.lastIndexOf('.asp?pid=');
		if (i <= 0) i = curPage.lastIndexOf('.asp?file=');
		if (i > 0 && my_detail.indexOf('.asp') < 0) 
		{
			i = curPage.lastIndexOf('/', i);
			sStr = curPage.substring(i + 1, curPage.length);
			i = sStr.indexOf('?');
			sStr = sStr.substring(0, i);
			my_detail = sStr + '?file=' + my_detail;		
		}
	}
	i = curPage.lastIndexOf("?");
	if (i > 0) 
	{
		myid = '&' + curPage.substring(i+1, curPage.length);
		curPage = curPage.substring(0, i);
		i = myid.lastIndexOf('&id=');
		if ( i < 0) 
			myid = '';
		else 
		{
			if (i > 0) myid = myid.substring(i, myid.length);
			i = myid.indexOf('#', 1)
			if (i > 0) myid = myid.substring(0, i);	
			i = myid.indexOf('&', 1)
			if (i > 0) myid = myid.substring(0, i);	
		}
	}
	// SEO Implementation:
	if (window.seohandler) 
	{
		i = curPage.indexOf(seohandler);
		if ( i > 0) curPage = curPage.substring(0, i+1);
	}
	i = curPage.lastIndexOf("/");
	if (i > 7) 
		curPage = curPage.substring(0, i+1);
	else if (curPage.length && i < 0) 
		curPage += '/';
		
	page = my_initial + "?track=" + my_track + "+" + escape(curPage);
	if (window.sessionid)
		page += "&id=" + sessionid;
	else if (myid.length)
		page += myid;

	if (bRefresh)
		page += '&rnd=' + Math.round(Math.random()*100000); 

	if (curPage.indexOf('http') < 0 && my_initial.indexOf('://') < 0 && curPage.length)
	{
		alert('To properly preview the page: \n\nEdit "header.js" file to Prefix "my_initial" variable with a full domain URL.');
	}
	else if (!window.parent || (!window.parent.sitename && !window.parent.fixHTMLArea)) 
	//Do not load initial.asp if parent has it already.
	{
		document.write('<' + 'script language="JavaScript" src="' +
			page + '"></' + 'script>\r\n');
	}
}

if (window.parent && window.parent.sitename && !window.parent.fixHTMLArea) 
{
//Simply redefine some functions to call those on the parent window.
	eval("var sessionid = window.parent.sessionid;");
	eval("var cart = window.parent.cart;");
	eval("function quickcart(sParams) {window.parent.quickcart(sParams, window)}");
	eval("function insertstatic(sURL) {window.parent.insertstatic(sURL, window)}");
	eval("function insertpage(sURL) {window.parent.insertpage(sURL, window)}");
	eval("function submitform(sForm, sURL) {window.parent.submitform(sForm, sURL, window)}");
}

var myStyle0 = '?' + myStyle.substring(1, myStyle.length);
function setStyle(sField, sValue)
{
var thisStyle = myStyle;
var i, j, sStr;
	i = thisStyle.indexOf('&' + sField + '=');
	if (i >= 0)
	{
		j = thisStyle.indexOf('&', i + 1);
		if (j < 0) j = thisStyle.length;
		sStr = thisStyle.substring(i, j);
		thisStyle = thisStyle.replace(sStr, '&' + sField + '=' + escape(sValue));		
	}
	else
		thisStyle += '&' + sField + '=' + escape(sValue);
	return thisStyle;
}

/***********************************************
* AnyLink Drop Down Menu- ?Dynamic Drive (www.dynamicdrive.com) This notice MUST stay intact for legal use Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="about-history.htm">History & Internet Trading</a>'
menu1[1]='<a href="contact.htm">Contact Us</a>'
menu1[2]='<a href="shopping-guide.htm">Shopping Guide</a>'

var menu2=new Array()
menu2[0]='<a href="certificate.htm">Authenticity Certificate </a>'
menu2[1]='<a href="privacy.htm">Privacy & Security</a>'
menu2[2]='<a href="testimonials.htm">Testimonials</a>'
menu2[3]='<a href="returns.htm">Returns & Refunds</a>'
menu2[4]='<a href="payment.htm">Payment Details</a>'
menu2[5]='<a href="guarantee.htm">Our Guarantee</a>'
menu2[6]='<a href="pictures.htm">Our Picture</a>'

//Contents for menu 3
var menu3=new Array()
menu3[0]='<a href="membersbenefit.htm">Membership Benefits</a>'
menu3[1]='<a href="http://www.justopal.com/members/front.htm">Member Login</a>'
menu3[2]='<a href="becomemember.htm">Become a Member</a>'

//Contents for menu 4
var menu4=new Array()
menu4[0]='<a href="solid-opals.htm">Solid Opals</a>'
menu4[1]='<a href="doublets.htm">Doublets</a>'
menu4[2]='<a href="opal-triplets.htm">Triplets</a>'
menu4[3]='<a href="treated-opal.htm">Treated Opal</a>'		
menu4[4]='<a href="caring-opal.htm">Care for Your Opal</a>'
menu4[5]='<a href="opal-nomenclature.htm">Opal Nomenclature</a>'

//Contents for menu 5
var menu5=new Array()
menu5[0]='<a href="shipping.htm">Free Shipping</a>'
menu5[1]='<a href="giftpackaging.htm">Gift Packaging</a>'
menu5[2]='<a href="delivery.htm">Delivery Times</a>'

var menuwidth='165px' //default menu width
var menubgcolor='#EFEDFC'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed
var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


