// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//--------------DROPDOWN MENU FUNCTIONS-------------------//
//make sure to include all 'submenu id' and 'submenu_sub id' you needed to the arrays bellow
//do not forget all submenus divs id MUST begin with the string 'submenu' + whatever
//all submenus_Sub divs id MUST begin with the string 'submenu_Sub' + whatever

var submenu_array = ["submenu1","submenu2","submenu3","submenu4","submenu5"];
var submenu_Sub_array = [];

function setLyr(obj,lyr)  //controls the positioning of the submenu layer lets you adjust x,y positioning for ie-mac and safari separately
{

	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
//window.alert(newX);
	var fixX //adjasting the diference between ie-mac and other browsers
	var fixY  //adjasting the diference between ie-mac and other browsers
	if ((is_ie5up) && (is_mac)){  // fix for ie-mac
		fixX = 7;
		fixY = 0;
	
	}	
	else if (is_safari){ // fix for safari
		fixX = 0;
		fixY = 0;
	} 
	else if ((is_ie5up) && (!is_mac)){ //fix for 
		fixX = 7;
		fixY = 0;
	}
	else if(is_opera){
		fixX = 20;
		fixY = 4;
		}
	else {
		fixX = 0;
		fixY = 0;
	}
	x.style.top = newY + fixX + 11 + 'px';
	x.style.left = newX + fixY -1 + 'px';
}

function setLyr2(obj,lyr)   //controls the positioning of the submenu_Sub layer let you adjust ie-mac x,y positioning separately
{
		var newX = findPosX(obj)-1;
		var newY = findPosY(obj);
		var x = new getObj(lyr);
		var addX = obj.offsetWidth;
		var fixX
		var fixY
			//window.alert(addX);
	if ((is_ie5up) && (is_mac)){ //fix for ie-mac
		fixX = -1;
		fixY = -12;
	}	
	else {
		fixX = -1;
		fixY = -1;
	}
	x.style.top = newY + fixX + 'px';
	x.style.left = newX+ fixY + addX + 'px';
	
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getObj(name){
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
 }
}

function FW_clearTimeout(){
	if (fwHideMenuTimer) clearTimeout(fwHideMenuTimer);
	fwHideMenuTimer = null;
	fwDHFlag = false;
}

function FW_startTimeout(){
	fwStart = new Date();
	fwDHFlag = true;
	fwHideMenuTimer = setTimeout("fwDoHide()", 1000);
}

function fwDoHide(){
	var printstring = '';
	printstring +=fwStart+' fwHideMenuTimer:'+fwHideMenuTimer+' layers: ';
	/*window.status = printstring;*/
	if (!fwDHFlag) return;
	var elapsed = new Date() - fwStart;
	if (elapsed < 40) {
		fwHideMenuTimer = setTimeout("fwDoHide()", 40-elapsed);
		return;
	}
	fwDHFlag = false;
	hideActiveMenus();
	window.ActiveMenuItem = 0;
}



function hideActiveMenus() {  //goes over each of the submenus in the arrays and hide them
	for (i=0; i<(submenu_array.length); i++){
		  var name=submenu_array[i]; 
			var removeLayer = document.getElementById(name);
			removeLayer.style.visibility="hidden";
		}
		for (i=0; i<(submenu_Sub_array.length); i++){
		  var name=submenu_Sub_array[i]; 
			var removeLayer = document.getElementById(name);
			removeLayer.style.visibility="hidden";
		}
}

function ShowNav(layerName){  // show named layer and hide All other layers from the submenu_array
	
	for (i=0; i<(submenu_array.length); i++){
		var name=submenu_array[i]; 
		var subname=name.substr(0,7); 
		 if(subname=="submenu"){ 
			   if (layerName==name){
				   MM_showHideLayers(layerName,'','show');
			   } else {
				   var removeLayer = document.getElementById(name);
				   removeLayer.style.visibility="hidden";
				}
			}
	}
}

function hideSubNav(){  // hides all sub sub nav
	
	for (i=0; i<(submenu_Sub_array.length); i++){
		  var name=submenu_Sub_array[i]; 
			var removeLayer = document.getElementById(name);
			removeLayer.style.visibility="hidden";
		}
}

function showSubNav(layerName){ // show named layer and hide All other layers from the submenu_Sub_array
	for (i=0; i<(submenu_Sub_array.length); i++){
		var name=submenu_Sub_array[i]; 
		var subname=name.substr(8,4);
		if(subname=="_Sub"){ 
			if (layerName==name){
				MM_showHideLayers(layerName,'','show');
			} else {
				var removeLayer = document.getElementById(name);
				removeLayer.style.visibility="hidden";
			}
		}
	}
}

function mouseoutMenu(){
	fwDHFlag = false;
	return true;
}
function addTel(){
var add='<span class=\"pink\">0845 652 6525</span>';
document.write(add);
}
function addBidEmail(){
var add='<a href=\"mailto:print@printinco.co.uk&subject=Printinco - Bid Request&body=The job I want%0D%0A%0D%0AJob:%0D%0AArtwork format:%0D%0AQuantity:%0D%0ABid:%0D%0ADate Required: " >email now</a>';
document.write(add);
}
function WhatYouWant(){
var add='<img class=\"bluearrow\" height=\"11\" src=\"i/blue-arrow.gif\" width=\"9\" /><a href=\"mailto:print@printinco.co.uk\">Tell us what you want!</a>';
document.write(add);
}
function addEmailText(){
var add='<a href="mailto:print@printinco.co.uk">print@printinco.co.uk</a>';
document.write(add);
}
function addEmailWallingford(){
var add='<a href="mailto:sales@printinco.co.uk">sales@printinco.co.uk</a>';
document.write(add);
}
function addEmailTextme(){
var add='<a href="mailto:printme@printinco.co.uk">printme@printinco.co.uk</a>';
document.write(add);
}
function addEmail(){
var add='<a href=\"mailto:print@printinco.co.uk\" >email</a>';
document.write(add);
}
function addCapEmail(){
var add='<a href=\"mailto:print@printinco.co.uk\" >Email</a>';
document.write(add);
}
function addBannersEmail(){
var add='<a href=\"mailto:banners@printinco.co.uk\" >contact us</a>';
document.write(add);
}
function addMarketingcoEmail(){
var add='<a href=\"mailto:jackie@marketingco.biz\" >email</a>';
document.write(add);
}
function EprintLink(){
var add='<a href=\"mailto:print@printinco.co.uk\"><img height=\"38\" alt=\"EPrint print@printinco.co.uk\" src=\"i/eprint.gif\" width=\"176\" border=\"0\"></a>';
document.write(add);
}

function addResellersMenu(){
var add='<div id="resellersMenu"><a href=\"birthday_banners_resellers.html\">Birthday Banners</a> | <a href=\"wedding_banners_resellers.html\">Wedding Banners</a> | <a href=\"special_occasions_resellers.html\">Special Occasions</a> | <a href=\"promotional_banners_resellers.html\">Promotional Banners</a> | <a href=\"sporting_banners_resellers.html\">Sporting Banners</a> | <a href=\"banner_stands_resellers.html\">Banner Stands</a> | <a href=\"#\" onClick="orderFormPopup()">Order Form</a> | <a href=\"logout.aspx\">logout</a></div>';
document.write(add);
}
function addOrderFormLink(){
var add='<a href=\"#\" onClick="orderFormPopup()" >email order form</a>';

document.write(add);
}

function orderFormPopup(){
		popWin=window.open('orderform.aspx?type=Normal', 'orderform', 'personalbar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no,width=500,height=545,top=0,left=0');
		if(window.focus) {
			popWin.focus();
		}
}
function addOrderFormResellers(){
var add='<a href=\"#\" onClick="orderFormPopupResellers()" >email order form</a>';

document.write(add);
}
function orderFormPopupResellers(){
		popWin=window.open('orderform.aspx?type=Resellers', 'orderform', 'personalbar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no,width=500,height=545,top=0,left=0');
		if(window.focus) {
			popWin.focus();
		}
}
function addressesPopup(){
		popWin=window.open('address.htm', 'addresses', 'personalbar=no,toolbar=no,status=no,scrollbars=no,resizable=no,menubar=no,width=489,height=230,top=50,left=50');
		if(window.focus) {
			popWin.focus();
		}
}
function addExtranetMenagerEmail(){
var add='<a  class=\"link\" href=\"mailto:accounts@printinco.co.uk\">Extranet Accounts Department</a>';
document.write(add);

			}

//ShowHide Divs Was Ere






function bigpic(name,width,height){
		picturepath = 'garments.aspx?pic=' + name;
		tearWin=window.open(picturepath, 'samples', 'personalbar=no,toolbar=no,status=no,scrollbars=no,resizable=no,menubar=no,width='+width+',height='+height+',top=40,left=40');
		if(window.focus) {
			tearWin.focus();
		}
}
/* This script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

//////////////////////////
function calculate(){
var newPrice=00;
var selectedType;
var formType=document.Form1.formType.value;

if (formType=="reseller"){
	var bannerCode=document.Form1.bannerCode.value;
	if (bannerCode!=""){
	//alert(formType);
	var bannerCodeLetter=bannerCode.substring(0,1);
	//alert(bannerCodeLetter.toLowerCase());
		if((bannerCodeLetter.toLowerCase()=="a")||(bannerCodeLetter.toLowerCase()=="d"))
		{
			selectedType="Text Only";
			//alert(selectedType);
		}
	}
}else{
	selectedType=selectedRadioValue('bannerType');
}

var selectedFixing=document.Form1.fixing.value;	
var selectedQuantity=document.Form1.quantity.value;	
var selectedSize=document.Form1.size.value;
if (selectedType=="Text Only"){
   if (selectedSize==1){
   newPrice +=29.95;
   }
    else if (selectedSize==2){
   newPrice +=39.95;
   }
    else if (selectedSize==3){
   newPrice +=42.95;
   }
    else if (selectedSize==4){
   newPrice +=45.95;
   }
   if (selectedRadioValue('bgColour')!=10){
		newPrice += 10.58;
	}
}else{
 if (selectedSize==1){
   newPrice +=39.95;
   }
    else if (selectedSize==2){
   newPrice +=55.95;
   }
    else if (selectedSize==3){
   newPrice +=59.95;
   }
    else if (selectedSize==4){
   newPrice +=65.95;
   }
   if (selectedRadioValue('bgColour')!=10){
		newPrice += 14.10;
	}

}
if (selectedFixing=="Bungy cords"){
   newPrice +=8.00;
   }else if (selectedFixing=="Velcro mounting"){
   newPrice +=3.00;
   }else if (selectedFixing=="Banner stand"){
   newPrice +=47.00;
   }
newPrice=selectedQuantity*newPrice;
RoundnewPrice=round_decimals(newPrice,2)
document.Form1.price.value= RoundnewPrice;
}

function selectedRadioValue(selectedField)
{
	var radioButtons = document.Form1.elements[selectedField];
	for (var i = 0; i < radioButtons.length; i++)
	{
		if (radioButtons[i].checked == true)
		{
			return radioButtons[i].value;
		}
	}
	return "";
}



