

function Check_State(param){
	//alert(param);
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;
  	var field = param + "-" + selection;
	
	// Loop to 50 removing all instances on the page
	for (var x = 0; x <= 25; x++)
   	{
   		var hideme = param + "-" + x;
 		Hide_MQ(hideme);
    }
	Show_MQ(field);
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function Show_Delivery_Addresses(param){
	if (document.getElementById(param) != null){
	  var oId=document.getElementById(param)
	  if(oId.style.visibility == "hidden"){	  
	  	Show_MQ(param);
		Hide_MQ('selectaddresses');		  
	  }
	  else{
	  	Hide_MQ(param);
		Show_MQ('selectaddresses');
	  }

	}
	

}

function updateDelivery(type, id){

	
if(type.search("UK") != -1){
	//alert('about to show delivery-' + id + 'next');
	Show_MQ('delivery-' + id + 'next');
	Show_MQ('delivery-' + id + 'morning');
	Show_MQ('delivery-' + id + 'lunch');
	Show_MQ('deliverytextnext-' + id);
	Show_MQ('deliverytextmorning-' + id);
	Show_MQ('deliverytextlunch-' + id);	
}

else if (type.search("DUBLIN") != -1 || type.search("NORTHERN IRELAND")!= -1 || type.search("CHANNEL ISLANDS")!= -1){
	//alert('about to show delivery-' + id + 'next');
	Show_MQ('delivery-' + id + 'next');
	Hide_MQ('delivery-' + id + 'morning');
	Hide_MQ('delivery-' + id + 'lunch');
	Show_MQ('deliverytextnext-' + id);
	Hide_MQ('deliverytextmorning-' + id);
	Hide_MQ('deliverytextlunch-' + id);
}

else{
	//alert('about to hide delivery-' + id + 'next');
	Hide_MQ('delivery-' + id + 'next');
	Hide_MQ('delivery-' + id + 'morning');
	Hide_MQ('delivery-' + id + 'lunch');
	Hide_MQ('deliverytextnext-' + id);
	Hide_MQ('deliverytextmorning-' + id);
	Hide_MQ('deliverytextlunch-' + id);	
}
// must be dublin or ni


}

function Show_Other(param, id){
	//alert(param);
	
	var mySelect=document.getElementById(param);	
	
	var selection = mySelect.value;
	
	if(selection == id){
	 Show_MQ(param + "-" + id);
	}
	else{
		Hide_MQ(param + "-" + id);
	}
	
}

function Process_colour_front(noneid, param, id){
	Process_colour_rear(noneid, param, id);
}

function Process_colour_rear(noneid, param, id){
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById('colour_front');
	var selection1 = mySelect.value;

	var mySelect=document.getElementById('colour_rear');
	var selection2 = mySelect.value;

	// 1 indicateds that none has been selected
	if(selection1 == 1 && selection2 == 1)		
		Show_MQ('colours_throughout_row');
	else		
		Hide_MQ('colours_throughout_row');

}

function Process_colours_throughout(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;
	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	if(selection == noneid){		
		Show_MQ('cover_row');
		Show_MQ('text_row');
		Show_MQ('colour_front_row');
		Show_MQ('colour_rear_row');
		
	}
	else{		
		Hide_MQ('cover_row');
		Hide_MQ('text_row');
		Hide_MQ('colour_front_row');
		Hide_MQ('colour_rear_row');		

	}


}

function Process_colours(noneid, param, id){
/*	// show other field if necessary
	Show_Other(param, id);
	
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;
	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	if(selection == 12){		
		//Show_MQ('cover_row');
		//Show_MQ('text_row');
		Show_MQ('colour_front');
		Show_MQ('colour_rear');
		
	}
	else{		
		//Hide_MQ('cover_row');
		//Hide_MQ('text_row');
		Hide_MQ('colour_front');
		Hide_MQ('colour_rear');		
	}
	*/
}



function Process_spot_uv_cover(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	
	// selection is front
	if(selection == 1)
		Hide_MQ('spot_uv_cover_coverage_row');
	
	else
		Show_MQ('spot_uv_cover_coverage_row');	
	
	
	
}

function Process_spot_uv(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	
	// selection is front
	if(selection != 1){
		Show_MQ('spot_uv_coverage_row');
	}
	// selection is back
	else{
		Hide_MQ('spot_uv_coverage_row');
	}
	
	
	
}

/*
function Process_spot_uv(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	
	// selection is front
	if(selection == 2){
		//Show_MQ('spot_uv_coverage_front_row');
		//Hide_MQ('spot_uv_coverage_reverse_row');		
		Show_MQ('spot_uv_coverage_row');
	}
	// selection is back
	else if(selection == 3){
		Show_MQ('spot_uv_coverage_row');
		//Hide_MQ('spot_uv_coverage_front_row');
		//Show_MQ('spot_uv_coverage_reverse_row');		
	}
	else if(selection != noneid){		
		Show_MQ('spot_uv_coverage_row');
		//Show_MQ('spot_uv_coverage_front_row');
		//Show_MQ('spot_uv_coverage_reverse_row');
	}
	
	else{
		Hide_MQ('spot_uv_coverage_row');
		//Hide_MQ('spot_uv_coverage_front_row');
		//Hide_MQ('spot_uv_coverage_reverse_row');		
	}
	
	
	
}
*/


function Process_binding(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	
	// selection is front
	if(selection == 4){
		Hide_MQ('binding_position_row');
	}
	// selection is back
	else{
		Show_MQ('binding_position_row');
	}
	
	
	
}


function Process_folding(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	
	// selection is front
	if(selection == 1){
		Show_MQ('folding_type_row');
	}
	// selection is back
	else{
		Hide_MQ('folding_type_row');
	}
	
	
	
}



function Process_double_sided(noneid, param, id){
	// show other field if necessary
	Show_Other(param, id);
	
	// now check to see if none has been selected	
	var mySelect=document.getElementById(param);
	var selection = mySelect.value;

	// if the user has selected colours throughout hide
	// colour cover, text, colour_front, colour_rear
	if(selection == noneid){		
		Hide_MQ('colours_throughout_row');
		Hide_MQ('colour_rear_row');
		Show_MQ('colour_front_row');
	}
	// if yes, extra code required to check the state of colours throughout
	else{	
		var mySelect=document.getElementById('colours_throughout');
		var selection = mySelect.value;
		// if none is selected
		if(selection == 1){
			
			Show_MQ('colours_throughout_row');		
			Show_MQ('cover_row');
			Show_MQ('text_row');
			Show_MQ('colour_front_row');
			Show_MQ('colour_rear_row');
		}
		else{
			Show_MQ('colours_throughout_row');
			Hide_MQ('cover_row');
			Hide_MQ('text_row');
			Hide_MQ('colour_front_row');
			Hide_MQ('colour_rear_row');
		}
	}


}



function Show_MQ(Element){
	if(document.getElementById(Element) != null){
		  var oId=document.getElementById(Element)
		  oId.style.visibility = "visible";
		  oId.style.display = "";
	}
}
function Hide_MQ(Element){
	if (document.getElementById(Element) != null){
	  var oId=document.getElementById(Element)
	  oId.style.visibility = "hidden";
	  oId.style.display = "none";
	}
}

function confirmDelete()
{
 var where_to= confirm("Do you really want to go delete this record?");
 return (where_to)
}

function confirmDeliveryAddress()
{
 var where_to= confirm("Please confirm this delivery information is correct");
 return (where_to)
}


function confirmSpec()
{
 var where_to= confirm("Are you sure this information is complete? You will not be able to make edits once submitted");
 return (where_to)
}

function confirmDelivery()
{
 var where_to= confirm("Are your delivery addresses correct? \nPLEASE NOTE: They cannot be changed once your order is complete");
 return (where_to)
}


function checkSendToProofer()
{
 var where_to= confirm("Are you sure you want to send this to proofing?");
 return (where_to)
}

function AllArtworkUploaded(){
var where_to= confirm("Only press OK if you have uploaded all your artwork for this item");
 return (where_to)
}


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_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; }
}
function BuildUsername() {
  if (document.forms[0].username.value == "") {
    var Array = document.forms[0].domain.value.split(".");
	Array[0] = Array[0].toLowerCase();
	var RefString="abcdefghijklmnopqrstuvwxyz";
	var TempChar;
	var Username = "";
	for (i=0; i < Array[0].length; i++) {
	  TempChar = Array[0].substring (i, i+1);
	  if (RefString.indexOf (TempChar,0) > -1) {
	    Username = Username + TempChar;
	  }
	}
	document.forms[0].username.value = Username.substring(0,16);
  }
}

function ShowHideVatInput() {
  if (document.forms[0].payment_method[0].checked && document.forms[0].show_cardholder.checked == false) {
    var Array = document.forms[0].bcountry.value.split("|");
  } else {
    var Array = document.forms[0].country.value.split("|");
  }
  
  if (Array.length == 2) {
    document.getElementById("row_vatno").style.display = "";
  } else {
    document.getElementById("row_vatno").style.display = "none";
  }
}

function ShowHideCardHolder() {
  for (i=0; i<8; i++) {
    if (document.forms[0].payment_method[0].checked && document.forms[0].show_cardholder.checked == false) {
      if (document.forms[0].bforename.value == "" && document.forms[0].bsurname.value == "" && document.forms[0].bcompany.value == "" && document.forms[0].baddress.value == "" && document.forms[0].bcity.value == "" && document.forms[0].bcounty.value == "" && document.forms[0].bzip.value == ""  && document.forms[0].bphone.value == "" && document.forms[0].bemail.value == "") {
	    document.forms[0].bforename.value = document.forms[0].forename.value;
	    document.forms[0].bsurname.value = document.forms[0].surname.value;
		document.forms[0].bcompany.value = document.forms[0].company.value;
		document.forms[0].baddress.value = document.forms[0].address.value;
		document.forms[0].bcity.value = document.forms[0].city.value;
		document.forms[0].bcounty.value = document.forms[0].county.value;
		document.forms[0].bzip.value = document.forms[0].zip.value;
		document.forms[0].bphone.value = document.forms[0].phone.value;
		document.forms[0].bemail.value = document.forms[0].email.value;
	  }
	  document.getElementById("row_card_holder_" + i).style.display = "";
    } else {
      document.getElementById("row_card_holder_" + i).style.display = "none";
    }
  }
}

function ShowHideCardInput() {
  if (document.forms[0].payment_method[1].checked) {
    var Array = document.forms[0].plan.value.split("|")
    if (document.forms[0].billing[2].checked == false && Array.length == 4) { 
      if (confirm("You may settle your account by cheque or bank transfer on an annual billing cycle only. Change to an annual billing cycle?")) {
	    document.forms[0].billing[2].checked = true;
	  } else {
	    document.forms[0].payment_method[0].checked = true;
	    document.forms[0].payment_method[1].checked = false;
	  }
	}
  }

  for (i=0; i<9; i++) {
    if (document.forms[0].payment_method[0].checked) {
      document.getElementById("row_card_details_" + i).style.display = "";
    } else {
      document.getElementById("row_card_details_" + i).style.display = "none";
    }
  }
  
  ShowHideCardHolder();
}

function ChangeBillingCycle() {
  if (document.forms[0].payment_method[1].checked) {
    if (confirm("Monthly and quarterly billing is available only when paying by credit/debit card. Change to credit/debit card payment?")) {
	  document.forms[0].payment_method[0].checked = true;
	  ShowHideCardInput();
	} else {
	  document.forms[0].billing[0].checked = true;
	  document.forms[0].billing[1].checked = true;
	  document.forms[0].billing[2].checked = true;
	}
  }
}

function ShowHideTermInput() {
  if (document.forms[0].regtype[0].checked) {
    if (document.forms[0].domain.value.substring(document.forms[0].domain.value.lastIndexOf(".")+1,document.forms[0].domain.value.length) == "uk") {
      document.getElementById("row_term").style.display = "none";
	} else {
	  document.getElementById("row_term").style.display = "";
	}
  } else {
    document.getElementById("row_term").style.display = "none";
  }
}

function UpdatePricing() {
  var Array = document.forms[0].plan.value.split("|")
  if (Array.length == 4) { 
    document.getElementById("row_billing").style.display = "";
    document.getElementById("monthly_price").innerHTML = "&pound;" + Array[1] + " per month"
    document.getElementById("quarterly_price").innerHTML = "&pound;" + Array[2] + " per quarter"
    document.getElementById("annually_price").innerHTML = "&pound;" + Array[3] + " per year"
	if (document.forms[0].payment_method[1].checked) {
      document.forms[0].billing[0].checked = false;
	  document.forms[0].billing[1].checked = false;
	  document.forms[0].billing[2].checked = true;
	}
  } else {
    document.getElementById("row_billing").style.display = "none";
  }
}

HelpText = new Array;
HelpText['delete'] = "Deleting an item will remove it from your shopping basket and move it to your quotes area. You can view your quotes by selecting the My Quotes link at the top left of the page.";
HelpText['basket'] = "You can add quotes to your shopping basket when you wish to make an order. To view your quotes select the My Quotes link above";
HelpText['deletequote'] = "If you remove a quote it will no longer be available for ordering";
HelpText['next'] = "Delivery before 6PM the next working day";
HelpText['morning'] = "Delivery before 9AM the next working day";
HelpText['lunch'] = "Delivery before lunchtime the next working day";
HelpText['account_owner'] = "Enter your contact details in the fields below. If you are registering a new domain name, its legal registrant will be the party you specify here. If you do not have an existing email address you cannot order online, please call our sales office on +44 (0)845 226 5566.";
HelpText['payment_method'] = "Specify whether you wish to pay for your account online by credit or debit card, or whether you will settle your account offline by cheque or bank transfer. If you choose to pay by cheque or bank transfer we will email you a pro forma invoice and remittance advice with further instructions, your account will not be activated until we receive your payment.";
HelpText['vatno'] = "You are inside the European Union but abroad from the United Kingdom. If you have a VAT number you may enter it here, otherwise you will be charged VAT on your order.";
HelpText['promo'] = "If you have a special offer or promotion code from an advertisement, please enter it here.";
HelpText['cardnumber'] = "Enter your credit or debit card number. This is normally the longer number or number in larger type on cards which show more than one number.";
HelpText['expiry'] = "Select the month and year that your card expires from the drop-down list.";
HelpText['cvv'] = "The card security code is a three digit number printed on your debit/credit card. Some card issuers refer to this number as the 'Card Security Code' others as the 'Personal Security Code' and others as 'Card Verification Value'.<br><br><div align='center'><img src='../images/security_code.gif'></div><br>Some cards, have a three digit number printed at the top of the signature strip on the reverse of the card. Whilst others have the number printed on the front of the card, above the main number. See the illustrations above for assistance identifying your card security code.";
HelpText['begin'] = "If your card has a begin, start or valid from date, select the month and year from the drop-down list. This field is not applicable to all cards, if your card does not have a begin date, leave this field blank.";
HelpText['issue'] = "If your card has an issue number, enter it here. This field is not applicable to all cards, if your card does not have an issue number, leave this field blank.";
HelpText['card_owner'] = "If the registered name and address of the card you are using to pay (normally the name and address shown on the card statement) is not the same as those you have entered for the Account Owner above, uncheck this box and enter the card holder's contact details.";

function PopUpHelp(field,yArg,xArg) {
  if (yArg == undefined) { yArg = -10; }
  if (xArg == undefined) { xArg = 20; }
  var info = field;
  
   for (i = 0; i < 10; i++){
	  info = info.replace(i, ''); 
	}
	

  
  document.getElementById("helptext").innerHTML = HelpText[info];
  document.getElementById("helplayer").style.left = GetElementLeft(document.images[field]) + xArg;
  document.getElementById("helplayer").style.top = GetElementTop(document.images[field]) + yArg;
  document.getElementById("helplayer").style.visibility = "visible";
}

function GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy

      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent is not a table or the body, then...
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nLeftPos += 1;             // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nLeftPos += nParBorder;       // append the border width to counter
            }
         }
      }
      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}

function GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nTopPos = eElement.offsetTop;         // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent a table cell, then...
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nTopPos += 1;              // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nTopPos += nParBorder;        // append the border width to counter
            }
         }
      }

      nTopPos += eParElement.offsetTop;      // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                           // return the number calculated
}


