//Create print and bookmark buttons
function toolsBtn(){
	var targ = document.getElementById("tools");
	/*var li1 = createBtn("print","/images/pagetools_print.gif",76,19,"Print page");*/
	var li2 = createBtn("bookmark","/images/pagetools_bookmark.gif",72,19,"Bookmark this page");
	/*targ.appendChild(li1);*/
	targ.appendChild(li2);
}

//Li element class for print and bookmark buttons
function createBtn(f,s,w,h,aT){
	li = document.createElement("li");
	a = document.createElement("a");
	img = document.createElement("img");
	img.src=s;
	img.width=w;
	img.height=h;
	img.alt=aT;
	a.href="#";
	if(f=="print"){
		a.onclick= function(){self.print();return false;}
		a.onkeydown= function(){self.print();return false;}
	}
	if(f=="bookmark"){
		var url = document.location.href;
		var title = document.title;
		a.onclick= function(){bookmark(url,title);return false;}
		a.onkeydown= function(){bookmark(url,title);return false;}
	}
	a.appendChild(img);
	li.appendChild(a);
	return li;
}

//Bookmark function
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

//Popup function
function popup(url){
	window.open(url,"Email","width=580,height=580,scrollbars=yes");	
}




// MAP > hover
function panelOn(layer){
document.getElementById("worldmap").className=layer;
//document.getElementById("panel"+layer).className="americas";
}

function panelOff(layer){
document.getElementById("worldmap").className="mapping";
//document.getElementById("panelDefault").className="";
}






//FLYOUT MENUS
var menus = new Array();
var subMenus = new Array();
var currentVis = new Array();
var currentSubVis = new Array();

function showMenu(lyr){


	for(i=0;i<currentVis.length;i++){
	if(currentVis[i]){
		currentVis[i].className = "hide";
		var pLI = currentVis[i].parentNode;
		pLI.firstChild.className="";
	}
	}
	currentVis.length=0;
	window.clearTimeout(t);
	if(document.getElementById(lyr)){
		document.getElementById(lyr).className = "show";
		currentVis.push(document.getElementById(lyr));
		var pLI = document.getElementById(lyr).parentNode;
		pLI.firstChild.className="selected";
	}

}

function hideMenu(){	
	for(i=0;i<menus.length;i++){
	if(document.getElementById(menus[i])){
		document.getElementById(menus[i]).className = "hide";
		var pLI = document.getElementById(menus[i]).parentNode;
		pLI.firstChild.className="";
	}
	}
	hideSubMenu();
}


function showSubMenu(lyr){
	
	for(i=0;i<currentSubVis.length;i++){
	if(currentSubVis[i]){
		currentSubVis[i].className = "hide";
		var pLI = currentSubVis[i].parentNode;
		pLI.firstChild.className="";
	}
	}
	currentSubVis.length=0;
	window.clearTimeout(t);
	if(document.getElementById(lyr)){
		document.getElementById(lyr).className = "show";
		currentSubVis.push(document.getElementById(lyr));
		var pLI = document.getElementById(lyr).parentNode;
		pLI.firstChild.className="selected";
	}

}

function hideSubMenu(){	
	for(i=0;i<subMenus.length;i++){
	if(document.getElementById(subMenus[i])){
		document.getElementById(subMenus[i]).className = "hide";
		var pLI = document.getElementById(subMenus[i]).parentNode;
		pLI.firstChild.className="";
	}
	}

}


window.onload = init;

function init(){
	
	document.onclick=function(){hideMenu();}

}

function menuSetup(){
var nav = document.getElementById("navigation");
var parentUL = nav.getElementsByTagName("ul");
var parentULNodes = parentUL[0].childNodes;

var parentLI = new Array();
var subLI = new Array();
var j=0;
var k=0;
var l=0;
var n=0;

//Get all the child nodes of the master UL and make a new array.
for(i=0;i<parentULNodes.length;i++){
	if(parentULNodes[i].nodeName=="LI"){
		parentLI[j]=parentULNodes[i];
		j++;
	}	
}

//For all the child LI's of the master UL
for(i=0;i<parentLI.length;i++){

	//If the LI has got a submenu then...
	var subMenu = parentLI[i].getElementsByTagName("ul");
	if(subMenu[0]){
		
		//Hide it, assign an id then put the mouse over onto the LI
		subMenu[0].className="hide";
		subMenu[0].id="menu"+k;
		subMenu[0].onmouseover=function(){pause();}
		subMenu[0].onmouseout=function(){window.clearTimeout(t);}
		menus.push(subMenu[0].id);
		parentLI[i].store = subMenu[0].id;
		parentLI[i].onmouseover = function(){showMenu(this.store);}
		parentLI[i].onmouseout = function(){pause();}
		k++;
		
		//For all the child LI's of the submenu UL
		var m=0;
		var subMenuNodes = subMenu[0].childNodes;
		//Get all the child nodes of the submenu and create a new array
		for(h=0;h<subMenuNodes.length;h++){
			if(subMenuNodes[h].nodeName=="LI"){
				subLI[m]=subMenuNodes[h];
				m++;
			}	
		}
	
		//For all the submenu LI nodes....
		for(g=0;g<subLI.length;g++){
			//If there is a subsubmenu then...
			var subSubMenu = subLI[g].getElementsByTagName("ul");
			if(subSubMenu[0]){
				//Hide it, assign it an id then put the mouseover onto the LI
				subSubMenu[0].className="hide";
				subSubMenu[0].id="submenu"+n;
				subMenus.push(subSubMenu[0].id);
				subLI[g].store = subSubMenu[0].id;
				subLI[g].onmouseover = function(){showSubMenu(this.store);}
				subLI[g].id="sub-items"
				n++;
			}
			else{
				subLI[g].onmouseover = function(){hideSubMenu();}
			}
		}

	}
	else{
		parentLI[i].onmouseover = function(){hideMenu();}
	}

}





//document.getElementById("item1menu").onmouseout = function(){dave("item1menu");}
//document.getElementById("item1amenu").onmouseout = function(){dave("item1amenu","sub");}


}


var t;
function pause(){
	t = window.setTimeout("hideMenu();",100);
}














function isEmail(emailAddress){
emailAddressValue=emailAddress.value.toLowerCase();
var countryTLDs=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$/;
var gTLDs=/^(aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org)$/;
var basicAddress=/^(.+)@(.+)$/;
var specialChars='\\(\\)><@,;:\\\\\\\"\\.\\[\\]';
var validChars='\[^\\s'+specialChars+'\]';
var validCharset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\'-_.';
var quotedUser='(\"[^\"]*\")';
var atom=validChars+'+';
var word='('+atom+'|'+quotedUser+')';
var validUser=new RegExp('^'+word+'(\.'+word+')*$');
var symDomain=new RegExp('^'+atom+'(\.'+atom+')*$');
var matchArray=emailAddressValue.match(basicAddress);
if(emailAddress.value==''||emailAddress==null){
return true;
}
if(matchArray==null){
alert('The Email address doesn\'t seem to be correct,\nplease check syntax.');
emailAddress.focus();
return false;
}else{
var user=matchArray[1];
var domain=matchArray[2];
for(i=0;i<user.length;i++){
if(validCharset.indexOf(user.charAt(i))==-1){
alert('The Email address contains invalid characters,\nplease check the username.');
emailAddress.focus();
return false;
}
}
for(i=0;i<domain.length;i++){
if(validCharset.indexOf(domain.charAt(i))==-1){
alert('The Email address contains invalid characters,\nplease check the domain.');
emailAddress.focus();
return false;
}
}
if(user.match(validUser)==null){
alert('The Email address doesn\'t seem to be correct,\nplease check the username.');
emailAddress.focus();
return false;
}
var atomPat=new RegExp('^'+atom+'$');
var domArr=domain.split('.');
var len=domArr.length;
for(i=0;i<len;i++){
if(domArr[i].search(atomPat)==-1){
alert('The Email address doesn\'t seem to be correct,\nplease check the domain name.');
emailAddress.focus();
return false;
}
}
if((domArr[domArr.length-1].length==2)&&(domArr[domArr.length-1].search(countryTLDs)==-1)){
alert('The Email address doesn\'t seem to be correct,\nplease check domain suffix.');
emailAddress.focus();
return false;
}
if((domArr[domArr.length-1].length>2)&&(domArr[domArr.length-1].search(gTLDs)==-1)){
alert('The Email address doesn\'t seem to be correct,\nplease check domain suffix.');
emailAddress.focus();
return false;
}
if((domArr[domArr.length-1].length<2)||(domArr[domArr.length-1].length>6)){
alert('The Email address doesn\'t seem to be correct,\nplease check domain suffix.');
emailAddress.focus();
return false;
}
if(len<2){
alert('The Email address doesn\'t seem to be correct,\nplease check missing hostname.');
emailAddress.focus();
return false;
}
}
return true;
}
String.prototype.trim = function() { return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");	}
function mandatoryText(input,fieldName){
if(input.value.trim()==''||input==null){
alert('Please enter your '+fieldName+'.');
input.focus();
return false;
} else {
return true;
}
}
function validForm(){
if(!mandatoryText(document.getElementById('EMAIL_FIELD'), 'Email Address')) return;
if(!isEmail(document.getElementById('EMAIL_FIELD'))) return;
document.getElementById('emvForm').submit();
}

function fnGiftPopUp()
        {
            var e=window.open('http://www.intotheblue.co.uk/giftpop.html','Gift','scrollbars=1,menubar=0,resizable=1,width=720,height=500');
            return false;
        }
        
function fnCheckFreeGiftOption(obj,var1)
{
 if ( obj.value=="Select Below" )
     {
        alert("Choose your free gift")
        return false;
     }
     else
     {
        document.getElementById("hidVar").value=var1;
        return true;
        
    }
     
}



function fnChangeDeliveryOption(obj,strCheckChange,strOriginalValue)
{
    //alert(svalue);
   if(strCheckChange=='yes')
   {
  
        var result=confirm('Promotional code is already added for selected delivery option , are you sure to change?');
        if(result)
        {
           // if(obj.selectedIndex == 1 || obj.selectedIndex == 2) 
          if (obj.selectedIndex == 1 ||obj.selectedIndex == 2 ) 
            {
             alert('Please note that Weekday Special Delivery can only be guaranteed for the next day if your order is placed between Monday and Thursday.\nFor Saturday deliveries please use our Saturday Special Delivery option - if you select Saturday Special Delivery we will arrange for your order to be delivered on the Saturday following your order.\nAll Post Office Special Delivery options need to be placed before 4.00pm to guarantee next day.\nCourier Service is available for delivery Monday to Friday and orders need to be placed before 2.00pm.');
            
            }
            document.forms[0].submit();  
        }
        else
        {
            for ( var i = 0; i < obj.options.length; i++ ) 
            {        
                if ( obj.options[i].value == strOriginalValue ) 
                {            
                    obj.options[i].selected = true;            
                    
               }  
            }
        }
   }
   
   if(strCheckChange=='no') 
   {
        //if (obj.selectedIndex == 1 || obj.selectedIndex == 2) 
        if (obj.selectedIndex == 1 ||obj.selectedIndex == 2 ) 
        {
            alert('Please note that Weekday Special Delivery can only be guaranteed for the next day if your order is placed between Monday and Thursday.\nFor Saturday deliveries please use our Saturday Special Delivery option - if you select Saturday Special Delivery we will arrange for your order to be delivered on the Saturday following your order.\nAll Post Office Special Delivery options need to be placed before 4.00pm to guarantee next day.\nCourier Service is available for delivery Monday to Friday and orders need to be placed before 2.00pm.');
           
        }
        document.forms[0].submit();  
    }
    
    
}

function fnCheckAbout(objcmb,strValue)
{
  
    objcmb.disabled=true;
    document.getElementById("lblWhere").style.color='gray';
    if(strValue!='Yes')
	    {
	        objcmb.disabled=false;
	        document.getElementById("lblWhere").style.color='black';
	    }
	    else
	    {
	        objcmb.value='Please select';
	    }
}

function loadjsfile(filename, filetype){
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
}





