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 toggleDays(year, month, weekDay, prefix, state) {
	for (var dayOfMonth = 1; dayOfMonth < 32; dayOfMonth++) {
		var theDate = new Date(year, month-1, dayOfMonth);
		if (weekDay == theDate.getDay()) {
			var frm = prefix + '_' + year + '-' + (month < 10 ? '0' : '') + month + '-' + (dayOfMonth < 10 ? '0' : '') + dayOfMonth;
			var cb = document.getElementById(frm);
			if (cb != null) {
				if (! cb.disabled) {
					cb.checked = (state.checked ? true : false);
				}
			}
		}
	}
}
function showSpec(divname, imagename){
	document.getElementById("prod_description").style.display='none';
	document.getElementById("specifications").style.display='none';
	document.getElementById(divname).style.display='block';
	
	document.getElementById("spec_tab").className="spec_tab"; 
	document.getElementById("desc_tab").className="spec_tab"; 
	document.getElementById(imagename).className="spec_tab_on"; 
}

function setEmailText(){
	var id=document.getElementById('email_type').options[document.getElementById('email_type').selectedIndex].value;
	 
	var thetext=""; 
	var name=document.getElementById('email_customer').value;
	var discount=document.getElementById('customer_trade_discount').value;
	var customer_navision=document.getElementById('customer_navision_new').value;

	var item_desc=document.getElementById('item_desc').value;
	
	
	if(id == 1){
		thetext="Dear "+name+", \n\nWe can confirm that the following item(s) have now been refunded\n\n\n\nIf you have any further queries, please contact Consumer Relations and quote your returns reference number \n\nConsumer Relations";
	}
	if(id == 2){
		thetext="Dear "+name+", \n\nWe can confirm that we are awaiting the following item(s) ";
	}
	if(id == 3){
		thetext="Dear "+name+", ";
	}
	document.getElementById('email_content').value=thetext;
	if(id == 4){
		
		thetext="Dear "+name+", \n\nThank you for applying for a trade account and for the interest you have shown in www.doorchic.co.uk.\n\nWe are pleased to inform you that your application has been successful, and you are now able to experience the benefits of being a registered trade customer with www.doorchic.co.uk. \n\nBenefit from ‘special prices’, discounts and promotions not available to unregistered customers.\nSee all previous orders you have made.\nBuild and save orders for use at a later date.\nSee products priced including or excluding VAT.\nPriority dispatch for account customers.\nFree scheduling service available.\nPro forma invoices are available upon request.\nPayment can be made by cheque.**\n\nYour trade discount of "+discount+"% is available for all items* and will be activated when you log in as a trade customer where it will be visible and calculated in your final shopping basket. Please remember to log in to activate your discount.\n\n\nYour cash account customer number is "+customer_navision+". Please quote this number on all correspondence.\n\nShould you wish to contact us please e-mail sales@doorchic.co.uk. Full contact details can be found in the ‘Contact us’ section on the website.\n\nThank you once again for taking the time to register with us, and we look forward to meeting your requirements in the near future.\n\n\n\n\n*Excluding sale and promotional items or items marked as ‘Star Buy’ \n** Items will be dispatched once funds have cleared.";
	}
	if(id == 5){
		thetext="Dear "+name+", \n\nThank you for applying for a trade account and for the interest you have shown in www.doorchic.co.uk.\n\nUnfortunately on this occasion you have not met our minimum trade account requirements. We have, however, registered your details on our systems where you will enjoy the various benefits of www.doorchic.co.uk registered customers.\n\nPlease contact a member of our customer service team should should your circumstances change or you would like to discuss the matter further.";
	}
	if(id == 6){
		thetext="Dear "+name+", \n\n"+item_desc+"";
	}
	if(id == 7)
	{
		var order_id=document.getElementById('email_orderid').value;
	thetext="Dear "+name+", \n\n\Thank you for your recent correspondence regarding order "+order_id+".\n\nYou have expressed a wish to return the following items:\n\n"+item_desc+" \n\nA returns form will be sent to you shortly. Please fill in your details and enclose the form with the return items. Items should be returned in their original packaging and in a re-saleable condition. \n\nWe advise using a traceable method of return as we cannot be held responsible for missing items or parcels.\n\nA refund has been issued to your account for....., less the carriage costs incurred in the initial dispatch and the standard re-stocking fee as laid out in our terms and conditions.\n\nIf you have any further questions please see our returns policy as laid out in our terms and conditions, or if you would prefer to speak to a member of our customer service team please call 01924 230265.\n\nMany Thanks \n\nCustomer services";	
	}
	document.getElementById('email_content').value=thetext;
	
}

function showPic (whichpic) {
				if (document.getElementById) {
				document.getElementById('placeholder').src = whichpic.href;
				 
				return false;
				} else {
				return true;
				}
				}

				function popup(url, width, height)
				{
					window.open(url, 'popup','resizable=no, scrollbars=yes, width=' + width + ', height=' + height )
				}
				function popupfull(url)
				{
					window.open(url,'popup','width=800,height=600,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
				}

//Function alerts the index of the selected option within form
function alertselected(){

	if (document.forms[0].seen.options[document.forms[0].seen.selectedIndex].value=="Newspaper Advert") document.forms[0].newspaper.style.visibility = "visible"
;
}
function checkSeen (strng) {
 var error = "";
 	if (strng == "") {
 	   error = "Please select an option from the dropdown menu to say where you have seen the offer.\n";

 	}
return error;
}
function checkCode (strng) {
 	var error = "";
 	if (strng == "") {
	    error = "Please enter a promotional code\n";
		
	 }
return error;
}
function checkWholeForm(theForm) {
    var why = "";
   
    why += checkCode(theForm.code.value);
    why += checkSeen(theForm.seen.value);
    
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function dowindow(ident,wwidth,wheight,wpage){
	var openStr=''
	var left=(screen.availWidth/2)-(wwidth/2)
	var top=(screen.availHeight/2)-(wheight/2)
	var strscrolls='yes'
	if (ident!='none' || ident!='noscroll'){
		wpage=wpage + '?id=' + ident
	}
	if (ident=='noscroll'){
		strscrolls='no'
	}
	openStr='height='+wheight+',width='+wwidth+',toolbar=false,location=false,scrollbars='+strscrolls+',status=false,resizable=false,top='+top+',screeny='+left+',left='+left+',screenx='+top
	bob=window.open(wpage,'newwin',openStr)
	
}

function doMovie(winname,w,h,f,b){
  var leftval=0
  var topval=0
  //w+=40;
 // h+=56;
  leftval=(screen.width-w)/2
  topval=(screen.height-h)/2
  eval("win"+winname+"=window.open('/movie.php?name='+winname+'&width=' + w +'&height='+ h +'&file=' + f + '&bgcol=' + b,'testwin','status=false,scrollbars=no,toolbar=no,menubar=no,location=no,width='+ (w+40) +',height=' + (h+40) +',resizable=no,screenX='+ leftval +',screenY='+ topval +',left='+ leftval +',top=' + topval)");
}

function dowmpMovie(winname,w,h,f,b){
  var leftval=0
  var topval=0
  //w+=40;
 // h+=56;
  leftval=(screen.width-w)/2
  topval=(screen.height-h)/2
  eval("win"+winname+"=window.open('/movie-wmp.php?name='+winname+'&width=' + w +'&height='+ h +'&file=' + f + '&bgcol=' + b,'testwin','status=false,scrollbars=no,toolbar=no,menubar=no,location=no,width='+ (w+40) +',height=' + (h+80) +',resizable=no,screenX='+ leftval +',screenY='+ topval +',left='+ leftval +',top=' + topval)");
}

function addEvent(obj, evType, fn) { 
	if (obj.addEventListener) { 
		obj.addEventListener(evType, fn, true); 
		return true; 
	} else if (obj.attachEvent) { 
		var r = obj.attachEvent('on' + evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function setAlternateRowColors() {
	var rows, arow;
	var tables = document.getElementsByTagName('table');
	var rowCount = 0;
	for (var i = 0; i < tables.length; i++) {
		if (tables.item(i).className == 'presentational') {
			rows = tables.item(i).getElementsByTagName('tr');
			for (var j = 1; j < rows.length; j++) {
				arow = rows.item(j);
				if (arow.nodeName == 'TR') {
					if (rowCount % 2) {
						arow.className = 'evenRow';
					}
					rowCount++;
				}
			}
			rowCount = 0;
		}
	}
}


function setInputWidths() {
	var inputs = document.getElementsByTagName('input');
	var rowCount = 0;
	for (var i = 0; i < inputs.length; i++) {
		var input = inputs.item(i);
		if (input.type == 'radio' || input.type == 'checkbox') {
			input.style.width = 'auto';
		}
	}
}

addEvent(window, 'load', setAlternateRowColors);
addEvent(window, 'load', setInputWidths);

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_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 initBoxes(publishedState) {
	if (publishedState == true) {
		window.document.form1.publishedYes.checked = true;
		window.document.form1.publishedNo.checked = false;
	}else{
		window.document.form1.publishedNo.checked = true;
		window.document.form1.publishedYes.checked = false;
	}

}
function replyBoxes(replyState) {
	if (replyState == true) {
		window.document.form1.reply[0].checked = true;
		window.document.form1.reply[1].checked = false;
	}
}

function replyenable() {
	document.form1.replyaddress.disabled=!document.form1.reply[0].checked;
	}
function memberenable() {
	document.form1.password1.disabled=!document.form1.accessLevel[1].checked;
	document.form1.password2.disabled=!document.form1.accessLevel[1].checked;
	}

function checkStates(action) {
	if (action == "publish") {
		window.document.form1.publishedNo.checked = false;

	}
	if (action == "unpublish") {
		window.document.form1.publishedYes.checked = false;
	}
	if (action == "reply") {
		window.document.form1.replyNo.checked = false;

	}
	if (action == "unreply") {
		window.document.form1.replyYes.checked = false;
	}

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_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 showOptions(list) {
		var myIndex  = list.selectedIndex;
		var selValue = list.options[myIndex].value;
		var selectedArray = eval("objectArray"+selValue);
		var selectedValues = eval("objectArrayIDs"+selValue);
		
		var maxVal = 50;
		for (i=0;i<maxVal;i++) {
			document.form1.selObjects.options.remove(i);
			document.form1.selObjects.options[i] = null;
		}
		if (selectedArray.length>0) {
			document.form1.selObjects.disabled = false;
			for (i=0;i<selectedArray.length;i++){
				if (selectedArray[i] != null) {
					document.form1.selObjects.options[i] = new Option(selectedArray[i],selectedValues[i]);
				}else{
					document.form1.selObjects.options[i] = null;
				}
			}
		}else{
			document.form1.selObjects.options[0] = new Option("no items available",null);
			document.form1.selObjects.disabled = true;
		}
}

function funcAddObject() {
	
	var objselObjects;
	var objFinalObjects;
	var objNewOption;
	var i;
	var iSelCount;
		
	objselObjects = window.document.forms["form1"]["selObjects"];
	objFinalObjects = window.document.forms["form1"]["selFinalObjects"];
			
	iSelCount = objFinalObjects.options.length;

	for (i=0;i<objselObjects.options.length;i++) {
		if (objselObjects.options[i].selected) {
			
			iSelCount++;
				
			objNewOption = new Option(objselObjects.options[i].text, objselObjects.options[i].value, false, false);			
			objFinalObjects.options[objFinalObjects.length] = objNewOption;
				
			objselObjects.options[i] = null;
			i = -1;
		}		
	}
						
}

function funcRemoveObject() {
	
	var objselObjects;
	var objFinalObjects;
	var objNewOption;
	var i;
		
	objselObjects = window.document.forms["form1"]["selObjects"];
	objFinalObjects = window.document.forms["form1"]["selFinalObjects"];
				
	for (i=0;i<objFinalObjects.options.length;i++) {
		if (objFinalObjects.options[i].selected) {
			
			if (objselObjects.options.length>0) {
				objNewOption = new Option(objFinalObjects.options[i].text, objFinalObjects.options[i].value, false, false);
				
				objselObjects.options[objselObjects.length] = objNewOption;
			}else{
				window.document.forms["form1"].toRemoveString.value+=objFinalObjects.options[i].value+",";
			}			
				
			objFinalObjects.options[i] = null;				
				
			i=-1;
		}
	}
}

function funcClearAllObject() {
	var objselObjects;
	var objFinalObjects;
	var objNewOption;
	var iCount;
	var iCount2;
	var i;
		
	objselObjects = window.document.forms["form1"]["selObjects"];
	objFinalObjects = window.document.forms["form1"]["selFinalObjects"];
		
	iCount = objselObjects.options.length;
	
	for (i=iCount;i>-1;i--) {
		objselObjects.options[i] = null;
	}

	iCount2 = objFinalObjects.options.length;
	
	for (i=iCount2;i>-1;i--) {
		if (iCount == 0) {
			//window.document.form1.toRemoveString.value+=objFinalObjects.options[i].value+",";
		}
		objFinalObjects.options[i] = null;
	}
}

function funcSavePage() {
	var objForm  = window.document.form1;
	var objselObjects = objForm["selFinalObjects"];
	for (i=0;i<objselObjects.length;i++) {
		objForm["selObjectsString"].value += objselObjects.options[i].value+",";
	}
}


function enableboxes(){
	document.forms[0].currentrole.disabled=false;
	document.forms[0].timeinrole.disabled=false;
	return;
}
function disableboxes(){
	document.forms[0].currentrole.disabled=true;
	document.forms[0].timeinrole.disabled=true;
	return;
}

function makePOSTRequest(url, parameters, cb)
{
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}

	http_request.onreadystatechange = function()
    {
      if(http_request.readyState==4)
	  	{
			cb(http_request.responseText);
        }
      };
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function listCompare()
{
	poststr = "action=list";
	makePOSTRequest("/setcomparison.php", poststr, compareCallback);
}

function addCompare(id)
{
	poststr = "action=add&id=" + id;
	makePOSTRequest("/setcomparison.php", poststr, compareCallback);
}

function removeCompare(id)
{
	poststr = "action=remove&id=" + id;
	makePOSTRequest("/setcomparison.php", poststr, compareCallback);
}

function compareCallback(str)
{
	document.getElementById('divProdCompare').innerHTML = str;
}


			function swapimg(img)
			{
			img = document.productdetails.order_colourid.selectedIndex
				
				
				document.images["prodimg"].src = images[img]; 
				
				
				
			}
			
			function swapfromdd()
			{
				for (i=0; i<ids.length; i++)
				{
					if (ids[i] == document.form1.order_colourid.options[document.form1.order_colourid.selectedIndex].value)
					{
						document.images["prodimg"].src = images[i]; 
						document.images["prodimg"].width = widths[i];
						
					}
				}
			}
			
			
function swapOut(imSrc){
	alert ('hello');
		document.getElementById('prodImage').src = "uploads/" + imSrc;
}

var pointer = 'pointer';


					function pricecallback(str)
					{
						
						if(str.match("NOT AVAILABLE")){
								document.getElementById("price").innerHTML = str;	
							document.getElementById("add_to_basket").style.display = 'none';
							document.getElementById("dollarprice").innerHTML = "";
						document.getElementById("europrice").innerHTML = "";
						}else{
							document.getElementById("add_to_basket").style.display = '';
							document.getElementById("price").innerHTML = "&pound;"+str;
						var dollar = document.getElementById("dollarconv").value*str;
						dollar = dollar.toFixed(2);
						
						var euro = document.getElementById("euroconv").value*str;
						euro = euro.toFixed(2);
						document.getElementById("dollarprice").innerHTML = "(&#36;"+dollar+")";
						document.getElementById("europrice").innerHTML = "(&euro;"+euro+")";
						}
					}
					
					function ajaxFunction()
					{  
						var finishname;
						var sizename;
						var functionname;
						var product_id;
						var vat;
						var bom;
						
						finishname = document.productdetails.order_colourid.value;
						sizename = document.productdetails.order_sizeid.value;
						functionname = document.productdetails.order_functionid.value;
						product_id = document.productdetails.order_productid.value;
						vat = document.productdetails.vat.value;
						bom = document.productdetails.order_bom.value;
										
						var poststr = 'finishname=' + escape(finishname) + 
									'&sizename=' + escape(sizename) + 
									'&functionname=' + escape(functionname) +
									'&vat=' + escape(vat) +
									'&product_id=' + product_id +
									'&bom=' + escape(bom);
						
						
						makePOSTRequest("/time.php", poststr, pricecallback);
						
					 }
					 
					 
					 
					 var titleIndex = 0;
var firstname = "";
var surname = "";
var business = "";
var address1 = "";
var address2 = "";
var town = "";
var countyIndex = 0;
var postcode = "";
var countryIndex = 0;

function InitSaveVariables(form) {
titleIndex = form.del_address_title.selectedIndex;
firstname = form.del_address_firstname.value;
surname = form.del_address_surname.value;

address1 = form.del_address_line1.value;
address2 = form.del_address_line2.value;
town = form.del_address_town.value;
countyIndex = form.del_address_county.selectedIndex;
postcode = form.del_address_postcode.value;
countryIndex = form.del_address_country.selectedIndex;
}

function validate_other(form) {

if(form.customer_howheardid.value==7 && form.customer_howhearddetails.value=='')
{
alert("Please enter where you heard about Doorchic.");
return false;
}
}

function MakeDeliveryAddressVisible()
{
	
	if (document.getElementById("set_delivery").checked==true) {
		document.getElementById("delivery_options").style.display = '';
	}else{
		document.getElementById("delivery_options").style.display = 'none';
	}
}

function ShipToBillPerson(form) {
if (form.set_delivery.checked) {
InitSaveVariables(form);
form.del_address_title.selectedIndex = form.address_title.selectedIndex;
form.del_address_firstname.value = form.address_firstname.value;
form.del_address_surname.value = form.address_surname.value;

form.del_address_line1.value = form.address_line1.value;
form.del_address_line2.value = form.address_line2.value;
form.del_address_town.value = form.address_town.value;
form.del_address_county.selectedIndex = form.address_county.selectedIndex;
form.del_address_postcode.value = form.address_postcode.value;
form.del_address_country.selectedIndex = form.address_country.selectedIndex;
}
else {
form.del_address_title.selectedIndex = titleIndex;
form.del_address_firstname = firstname;
form.del_address_surname.value = surname;

form.del_address_line1.value = address1;
form.del_address_line2.value = address2;
form.del_address_town.value = town;
form.del_address_county.selectedIndex = countyIndex;       
form.del_address_postcode.value = postcode;
form.del_address_country.selectedIndex = countryIndex;
   } 
}

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
