var xmlHttp = createXmlHttpRequestObject(); 

function calcPrice(formname){

	try{var printed = document.forms[formname].printed.checked;}catch(err){}
	try{var embroidered = document.forms[formname].embroidered.checked;}catch(err){}
	try{var col = document.forms[formname].Colour.value;}catch(err){}
	try{var size = document.forms[formname].Size.value;}catch(err){}
	try{var q = document.forms[formname].quantity.value;}catch(err){}
	try{var product_id = document.forms[formname].product_id.value;}catch(err){}
	
	ajaxPriceProcess(product_id, col, size, printed, embroidered, q, formname);
}

function createXmlHttpRequestObject(){	
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try{
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


function get_check_value(){
	var c_value = "";
	for (var i=0; i < document.orderform.music.length; i++){
	if (document.orderform.music[i].checked){
      c_value = c_value + document.orderform.music[i].value + "\n";
      }
   }
}


function ajaxPriceProcess(product_id, col, size, printed, embroidered, q, formname){
	
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	  //try{document.getElementById("price_"+formname).innerHTML = 'Calculating';}catch(err){}
    formname = encodeURIComponent(formname);
	col = encodeURIComponent(col);
	size = encodeURIComponent(size);
	var url = "http://www.dexterandgordon.co.uk/ajaxprocess.php?product_id=" + product_id + "&col=" + col + "&size=" + size + "&q=" + q +'&printed=' + printed + '&embroidered=' + embroidered;
	//document.write(url);
	xmlHttp.open("GET", url, true);  
	xmlHttp.onreadystatechange = handleServerResponsePrice;
    xmlHttp.send(null);
	
  }
  
}



// executed automatically when a message is received from the server
function handleServerResponsePrice() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      
	  xmlResponse = xmlHttp.responseXML;
      
	  xmlDocumentElement = xmlResponse.documentElement;

	  var myhtmlcode = xmlDocumentElement.getElementsByTagName("htmlcode").item(0).firstChild.data;
	  var product_id = xmlDocumentElement.getElementsByTagName("product_id").item(0).firstChild.data;
	  var formname = "price_buy_"+product_id;
	  var str = "document.getElementById('" + formname + "').innerHTML = 'PRICE: " + myhtmlcode + "'";
      eval(str);
	
	} else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}



function over(obj, index) {
	var col='#000000';
	if(index==1){col='#b3ecff'}
	if(index==2){col='#ffc0d8'}
	if(index==3){col='#ffc0d8'}
	if(index==4){col='#d4ec8c'}
	if(index==5){col='#d4ec8c'}
	if(index==6){col='#ffe87b'}
   obj.style.backgroundColor = col;
}

function out(obj){
	obj.style.backgroundColor = '#FFFFFF';
}

function email(){
	var a='sales';
	var b='dexterandgordon.co.uk';
	var c='@';
	document.write(' <a href="mailto:'+a+c+b+'">'+a+c+b+'</a>');
}

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_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 photo(photo){
	var features='toolbar=no,resizable=no,width=600,height=450';
	gallery = window.open('photo.php?photo='+photo, 'photo', features);
}

function linkto(url){
	document.location.href=url;
}

function deleteconfirm(del){ 
	if (
		confirm("Are you sure you wish to permanently delete this item?\n\nOK = Yes - Cancel = No")){ 
		window.location=del;
	}
} 