var xmlHttp;

var err=false;

var cmm_ok;

var posted;

var val;

var checkPC

var http_request;
var pagereload=false;

function selectrating(id,update) {



  var img1;
  var img2;
  var img3;
  var img4;
  var img5;
  


  var img1="st1nd.jpg";
  var img2="st2nd.jpg";
  var img3="st3nd.jpg";
  var img4="st4nd.jpg";
  var img5="st5nd.jpg";


 if (update)
  {

    document.getElementById("cmmv").value = id
    
  }


  val = document.getElementById("cmmv").value;


  img1= (((id < 1) && (val < 1)) ? "n" : "c") + ((id < 1) ? "d" : "l");
  img2= (((id < 2) && (val < 2)) ? "n" : "c") + ((id < 2) ? "d" : "l");
  img3= (((id < 3) && (val < 3)) ? "n" : "c") + ((id < 3) ? "d" : "l");
  img4= (((id < 4) && (val < 4)) ? "n" : "c") + ((id < 4) ? "d" : "l");
  img5= (((id < 5) && (val < 5)) ? "n" : "c") + ((id < 5) ? "d" : "l");
  document.getElementById("st1").src = "/images/st1" + img1 + ".jpg";
  document.getElementById("st2").src = "/images/st2" + img2 + ".jpg";
  document.getElementById("st3").src = "/images/st3" + img3 + ".jpg";
  document.getElementById("st4").src = "/images/st4" + img4 + ".jpg";
  document.getElementById("st5").src = "/images/st5" + img5 + ".jpg";

checkcmm();
  
  
}


function checkcmv() {

 document.getElementById("cmmv").value=document.getElementById("cmmv").value.substr(document.getElementById("cmmv").value.length-1,1);
 if ((document.getElementById("cmmv").value!=1) &&
     (document.getElementById("cmmv").value!=2) &&
     (document.getElementById("cmmv").value!=3) &&
     (document.getElementById("cmmv").value!=4) &&
     (document.getElementById("cmmv").value!=5) &&
     (document.getElementById("cmmv").value!=0)) {

    document.getElementById("cmmv").value=0;



    }

  selectrating(document.getElementById("cmmv").value,true);

checkcmm();

}


function checkcmm() {


 if (document.getElementById("cmmn").value.length>30) {document.getElementById("cmmn").value=document.getElementById("cmmn").value.substr(0,30);}
 if (document.getElementById("cmmt").value.length>400) {document.getElementById("cmmt").value=document.getElementById("cmmt").value.substr(0,400);}




 if ((document.getElementById("cmmv").value > 0) && (document.getElementById("cmmt").value!="") && (document.getElementById("cmmn").value!=""))
  {

    cmm_ok=true;

  }
  else
  {

    cmm_ok=false;

  }



  if (cmm_ok==true) {document.getElementById("sbx").src = "/images/sb-out.jpg"} else {document.getElementById("sbx").src = "/images/sb-off.jpg"}


}

function sbimg(onn) {


  if (posted)
  {
    document.getElementById("sbx").src = "/images/sb-send.jpg"
  }
  else
  {

  if (cmm_ok==true) {

    

      if (onn==true) {
        document.getElementById("sbx").src = "/images/sb-over.jpg"
       }
      else
       {
        document.getElementById("sbx").src = "/images/sb-out.jpg"
       }
   }
   else
   {
    document.getElementById("sbx").src = "/images/sb-off.jpg"
   }
  }


}


function mbo(onn) {

    document.getElementById(onn).className = document.getElementById(onn).className.replace("menu","manu");



}

function mbu(onn) {


    document.getElementById(onn).className = document.getElementById(onn).className.replace("manu","menu");


}

function overmenu(img, desc) {

  var descr;

    descr = ""


    if ((desc != "") || (img != ""))

    {

      if (img != "")

        {

          descr = descr + "<div style='background: #fff; width: 100%;'><center><img style='margin: 5px;' src='/images/products/small/" + img + "' /></center></div>";

        }


      if (desc != "")
        {

          descr = descr + "<div style='background: #dedeff; width: 100%; margin-top: 2px'>" + desc + "</div>";

        }

      else

	{

        descr = desc;

	}

    }

    return overlib(descr, DELAY, 200, WIDTH, 200, TIMEOUT, 2000, VAUTO, HAUTO, OFFSETX, 20, OFFSETY, 20, MOUSEOFF, CELLPAD, 5);



}




// ************************   AJAX   **********************************


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
  // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

return xmlHttp;
}


function showCD(str)

{

  xmlHttp=GetXmlHttpObject();

  if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  var url="/view/sendcomment.asp";

  url=url+"?q="+str;

  url=url+"&sid="+Math.random();

  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}


function stateChanged()
{
  if (xmlHttp.readyState==4)
  {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
  }
}








function makePOSTRequest(url, parameters, reloadit) {

      http_request = GetXmlHttpObject();
      pagereload=reloadit;
      http_request.onreadystatechange = alertContents;
      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 alertContents(reloadit) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            if(pagereload)
            {
	      window.location.reload();
	    }
	    else
	    {
              document.getElementById('cmm_send').innerHTML = result;
	    }
	    pagereload=false;
         } else {
            alert('There was a problem with the request.');
         }
      }
   }




function trypostcmm() {

	 checkcmm();

	 if (cmm_ok && !posted) {
	 document.getElementById("sbx").src = "/images/sb-send.jpg"
	 posted=true;
	 postcmm();

	 }

   }

function postcmm() {
      var poststr = "cmmip=" + encodeURI( document.getElementById("cmmip").value ) +
                    "&cmmv=" + escape(encodeURI( document.getElementById("cmmv").value)) +
                    "&cmmn=" + escape(encodeURI( document.getElementById("cmmn").value)) +
                    "&cmmid=" + escape(encodeURI( document.getElementById("cmmid").value)) +
                    "&cmmt=" + escape(encodeURI( document.getElementById("cmmt").value));
                    
      makePOSTRequest('/includes/sendcomment.asp', poststr,false);
   }

function postst() {
      var poststr = "dtitle=" + encodeURI(document.paymentpage.dtitle.value) +
      	  	    "&dfname=" + escape(encodeURI(document.paymentpage.dfname.value)) +
		    "&dsname=" + escape(encodeURI(document.paymentpage.dsname.value)) +
		    "&daddress=" + escape(encodeURI(document.paymentpage.daddress.value)) +
		    "&dtown=" + escape(encodeURI(document.paymentpage.dtown.value)) +
		    "&dcountry=" + escape(encodeURI(document.paymentpage.dcountry.value)) +
		    "&dpostcode=" + escape(encodeURI(document.paymentpage.dpostcode.value)) +
		    "&email=" + escape(encodeURI(document.paymentpage.email.value)) +
		    "&telephone=" + escape(encodeURI(document.paymentpage.telephone.value)) +
		    "&bprevorder=" + escape(encodeURI(document.getElementById("po").checked?"Yes":"No")) +
		    "&bprevopostcode=" + escape(encodeURI(document.paymentpage.bprevopostcode.value)) +
		    "&bmailing=" + escape(encodeURI(document.getElementById("bm").checked?"Yes":"No")) +
		    "&source=" + escape(encodeURI(document.paymentpage.source.value)) +
		    "&sourceother=" + escape(encodeURI(document.paymentpage.sourceother.value));

      makePOSTRequest('/ECommerce/send1.asp', poststr,false);
      
      

   }

function poststnew() {
      var poststr = "dtitle=" + encodeURI(document.paymentpage.dtitle.value) +
      	  	    "&dfname=" + escape(encodeURI(document.paymentpage.dfname.value)) +
		    "&dsname=" + escape(encodeURI(document.paymentpage.dsname.value)) +
		    "&daddress=" + escape(encodeURI(document.paymentpage.daddress.value)) +
		    "&dtown=" + escape(encodeURI(document.paymentpage.dtown.value)) +
		    "&dcountry=" + escape(encodeURI(document.paymentpage.dcountry.value)) +
		    "&dpostcode=" + escape(encodeURI(document.paymentpage.dpostcode.value)) +
		    "&email=" + escape(encodeURI(document.paymentpage.email.value)) +
		    "&telephone=" + escape(encodeURI(document.paymentpage.telephone.value)) +
		    "&bprevorder=" + escape(encodeURI(document.getElementById("po").checked?"Yes":"No")) +
		    "&bprevopostcode=" + escape(encodeURI(document.paymentpage.bprevopostcode.value)) +
		    "&bmailing=" + escape(encodeURI(document.getElementById("bm").checked?"Yes":"No")) +
		    "&source=" + escape(encodeURI(document.paymentpage.source.value)) +
		    "&sourceother=" + escape(encodeURI(document.paymentpage.sourceother.value));

      makePOSTRequest('/ECommerce/sendnew.asp', poststr,false);



   }

function countryset() {

      var poststr = "ID=" + encodeURI(document.country.ID.value);
      makePOSTRequest('/ECommerce/countryset.asp', poststr, true);


   }

function currencyset() {
      var poststr = "cID=" + encodeURI(document.currency.cID.value);

      makePOSTRequest('/ECommerce/currencyset.asp', poststr, true);


   }


function open_win(url)
{
window.open(url,"orderprint","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=550, height=500")
}



function confirmpay()

{
	var error = false;
	var almess = "Ops! You forgot to fill the following fields:\n\n";
	var i;

	if ((document.getElementById('name').value=="") || (document.getElementById('name').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Full name\n";
		};



	if ((document.getElementById('address').value=="") || (document.getElementById('address').value=="Please Complete!"))

		{
			error = true;
			almess = almess + "  - Delivery address\n";
		};

	if ((document.getElementById('town').value=="") || (document.getElementById('town').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Delivery Town\n";
		};


        var myPostCode = document.getElementById('postcode').value;



  	if (checkPC){


  	if (checkPostCode (myPostCode))
	  {
    	  document.getElementById('postcode').value = checkPostCode (myPostCode);
  	  }
	  else
	  {
			error = true;
			almess = almess + "  - Delivery Postcode has wrong format\n";

	  }}
	  
	  else
	  {

  	if (myPostCode=="Please Complete!")
	  {
			error = true;
			almess = almess + "  - Delivery Postcode\n";

	  }}
	  



	if ((document.getElementById('email').value=="") || (document.getElementById('email').value=="Please Complete!") || (document.getElementById('email').value.indexOf("@")==-1))
		{
			error = true;
			almess = almess + "  - Email Address\n";
		};


	if ((err == false) && (error == false))

		{
			if (document.getElementById('source').value=="")
			{
				almess="Please let Us know how did You Find Us.";
				err = true;
				error = true;

			};

			if ((document.getElementById('source').value.indexOf("enter below")>=0) && (document.getElementById('SourceOther').value==""))


			{
				almess="Please let Us know how did You Find Us by Filling 'Other' field.";
				err = true;
				error = true;
			};

		}






submitpayment();

	if (error == true)
	{
		//Error
		alert(almess);
		return false;
	} else {
	       poststnew();
		//No error, ok.
		return true;
	};



};

function confirmpays()

{
	var error = false;
	var almess = "Ops! You forgot to fill the following fields:\n\n";
	var i;

	if ((document.getElementById('sname').value=="") || (document.getElementById('sname').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Surname\n";
		};

	if ((document.getElementById('fname').value=="") || (document.getElementById('fname').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Forname\n";
		};


	if ((document.getElementById('address').value=="") || (document.getElementById('address').value=="Please Complete!"))

		{
			error = true;
			almess = almess + "  - Delivery address\n";
		};

	if ((document.getElementById('town').value=="") || (document.getElementById('town').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Delivery Town\n";
		};


        var myPostCode = document.getElementById('postcode').value;



  	if (checkPC){


  	if (checkPostCode (myPostCode))
	  {
    	  document.getElementById('postcode').value = checkPostCode (myPostCode);
  	  }
	  else
	  {
			error = true;
			almess = almess + "  - Delivery Postcode has wrong format\n";

	  }}

	  else
	  {

  	if (myPostCode=="Please Complete!" || myPostCode=="")
	  {
			error = true;
			almess = almess + "  - Delivery Postcode\n";

	  }}




	if ((document.getElementById('email').value=="") || (document.getElementById('email').value=="Please Complete!") || (document.getElementById('email').value.indexOf("@")==-1))
		{
			error = true;
			almess = almess + "  - Email Address\n";
		};


	if ((err == false) && (error == false))

		{
			if (document.getElementById('source').value=="")
			{
				almess="Please let Us know how did You Find Us.";
				err = true;
				error = true;

			};

			if ((document.getElementById('source').value.indexOf("enter below")>=0) && (document.getElementById('SourceOther').value==""))


			{
				almess="Please let Us know how did You Find Us by Filling 'Other' field.";
				err = true;
				error = true;
			};

		}






//submitpayment();

	if (error == true)
	{
		//Error
		alert(almess);
		return false;
	} else {
//	       poststnew();
		//No error, ok.
		return true;
	};



};



function confirmcard()

{
        document.getElementById('sent').style.display="none";
        document.getElementById('wait').style.display="block";
	var error = false;
	var almess = "Ops! You forgot to fill the following fields:\n\n";
	var i;

	if (document.getElementById('cardname').value=="")
		{
			error = true;
			almess = almess + "  - Name on card\n";
		}

	if ((document.getElementById('cardnumber').value==""))
		{
			error = true;
			almess = almess + "  - Card number\n";
		}

	if ((document.getElementById('expm').value=="") || (document.getElementById('expy').value==""))

		{

			error = true;
			almess = almess + "  - Card expiration date is incorrect\n";

		}


	if ((document.getElementById('address1').value=="") && (document.getElementById('address2').value=="") && (document.getElementById('address3').value=="") && (document.getElementById('address4').value==""))

		{
			error = true;
			almess = almess + "  - Card owner Address\n";
		}

	if (document.getElementById('city').value=="")
		{
			error = true;
			almess = almess + "  - Card owner City\n";
		}


        var myPostCode = document.getElementById('postcode').value;


  	if (myPostCode=="")
	  {
			error = true;
			almess = almess + "  - Card owner Postcode\n";

	  }

	if (document.getElementById('country').value=="-1")
		{
			error = true;
			almess = almess + "  - Card owner Country\n";
		}



	if (error == true)
	{
		//Error
        	document.getElementById('wait').style.display="none";
        	document.getElementById('sent').style.display="block";
		alert(almess);
		return false;
	} else {
		//No error, ok.
		return true;
	};



};



function confirmpay2()

{
	var error = false;
	var almess = "Ops! You forgot to fill the following fields:\n\n";
	var i;

	if ((document.getElementById('name').value=="") || (document.getElementById('name').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Full name\n";
		};



	if ((document.getElementById('address').value=="") || (document.getElementById('address').value=="Please Complete!"))

		{
			error = true;
			almess = almess + "  - Delivery address\n";
		};

	if ((document.getElementById('town').value=="") || (document.getElementById('town').value=="Please Complete!"))
		{
			error = true;
			almess = almess + "  - Delivery Town\n";
		};


        var myPostCode = document.getElementById('postcode').value;



  	if (checkPC){


  	if (checkPostCode (myPostCode))
	  {
    	  document.getElementById('postcode').value = checkPostCode (myPostCode);
  	  }
	  else
	  {
			error = true;
			almess = almess + "  - Delivery Postcode has wrong format\n";

	  }}

	  else
	  {

  	if (myPostCode=="Please Complete!")
	  {
			error = true;
			almess = almess + "  - Delivery Postcode\n";

	  }}




	if ((document.getElementById('email').value=="") || (document.getElementById('email').value=="Please Complete!") || (document.getElementById('email').value.indexOf("@")==-1))
		{
			error = true;
			almess = almess + "  - Email Address\n";
		};


	if ((err == false) && (error == false))

		{
			if (document.getElementById('source').value=="")
			{
				almess="Please let Us know how did You Find Us.";
				err = true;
				error = true;

			};

			if ((document.getElementById('source').value.indexOf("enter below")>=0) && (document.getElementById('SourceOther').value==""))


			{
				almess="Please let Us know how did You Find Us by Filling 'Other' field.";
				err = true;
				error = true;
			};

		}






submitpayment();

	if (error == true)
	{
		//Error
		alert(almess);
		return false;
	} else {
	       //poststnew();
		//No error, ok.
		return true;
	};



};

function startpay()
{
var msg;

msg="Please Note:\nDELIVERY ADDRESS is required on this page.\n\nIf this is NOT the HOME/BILLING ADDRESS of the person paying for the order, please ensure that the correct BILLING ADDRESS is entered on the next Order Page"

alert(msg);

}




var requiredFields = new Array("name","address","postcode");
var field;
var complete = "Please Complete!";

function submitpayment()
{
  if (checkRequiredFields()==1)
  {
    return (false);
  }
  return (true);
}

function checkRequiredFields()
{
var returnValue = 0;
for (loop=0;loop < requiredFields.length; loop++)
  {
  field = eval("document.paymentpage." + requiredFields[loop]);
  if (field.value=="" || field.value==complete)
    {
      field.value=complete;
      field.style.backgroundColor = "#66FFFF";
      returnValue=1;
    }
  }
return (returnValue);
}

function resetFieldValue(resetField)
{
if (resetField.value==complete)
  {
  resetField.value="";
  resetField.style.backgroundColor = "";
  }

}


function O(id,value) {
	document.getElementById('b').style.opacity = value/10;
	document.getElementById('b').style.filter = 'alpha(opacity=' + value*10 + ')';
}


	// Path to arrow images
	var arrowImage = '/images/select_arrow.gif';	// Regular arrow
	var arrowImageOver = '/images/select_arrow_over.gif';	// Mouse over
	var arrowImageDown = '/images/select_arrow_down.gif';	// Mouse down


	var selectBoxIds = 0;
	var currentlyOpenedOptionBox = false;
	var editableSelect_activeArrow = false;



	function selectBox_switchImageUrl()
	{
		if(this.src.indexOf(arrowImage)>=0){
			this.src = this.src.replace(arrowImage,arrowImageOver);
		}else{
			this.src = this.src.replace(arrowImageOver,arrowImage);
		}


	}

	function selectBox_showOptions()
	{
		if(editableSelect_activeArrow && editableSelect_activeArrow!=this){
			editableSelect_activeArrow.src = arrowImage;

		}
		editableSelect_activeArrow = this;

		var numId = this.id.replace(/[^\d]/g,'');
		var optionDiv = document.getElementById('selectBoxOptions' + numId);
		if(optionDiv.style.display=='block'){
			optionDiv.style.display='none';
			if(navigator.userAgent.indexOf('MSIE')>=0)document.getElementById('selectBoxIframe' + numId).style.display='none';
			this.src = arrowImageOver;
		}else{
			optionDiv.style.display='block';
			if(navigator.userAgent.indexOf('MSIE')>=0)document.getElementById('selectBoxIframe' + numId).style.display='block';
			this.src = arrowImageDown;
			if(currentlyOpenedOptionBox && currentlyOpenedOptionBox!=optionDiv)currentlyOpenedOptionBox.style.display='none';
			currentlyOpenedOptionBox= optionDiv;
		}
	}

	function selectOptionValue()
	{
		var parentNode = this.parentNode.parentNode;
		var textInput = parentNode.getElementsByTagName('INPUT')[0];
		textInput.value = this.innerHTML;
		this.parentNode.style.display='none';
		document.getElementById('arrowSelectBox' + parentNode.id.replace(/[^\d]/g,'')).src = arrowImageOver;

		if(navigator.userAgent.indexOf('MSIE')>=0)document.getElementById('selectBoxIframe' + parentNode.id.replace(/[^\d]/g,'')).style.display='none';

	}
	var activeOption;
	function highlightSelectBoxOption()
	{
		if(this.style.backgroundColor=='#316AC5'){
			this.style.backgroundColor='';
			this.style.color='';
		}else{
			this.style.backgroundColor='#316AC5';
			this.style.color='#FFF';
		}

		if(activeOption){
			activeOption.style.backgroundColor='';
			activeOption.style.color='';
		}
		activeOption = this;

	}

	function createEditableSelect(dest)
	{

		dest.className='selectBoxInput';
		var div = document.createElement('DIV');
		div.style.styleFloat = 'left';
		div.style.width = dest.offsetWidth + 16 + 'px';
		div.style.position = 'relative';
		div.id = 'selectBox' + selectBoxIds;
		var parent = dest.parentNode;
		parent.insertBefore(div,dest);
		div.appendChild(dest);
		div.className='selectBox';
		div.style.zIndex = 10000 - selectBoxIds;

		var img = document.createElement('IMG');
		img.src = arrowImage;
		img.className = 'selectBoxArrow';

		img.onmouseover = selectBox_switchImageUrl;
		img.onmouseout = selectBox_switchImageUrl;
		img.onclick = selectBox_showOptions;
		img.id = 'arrowSelectBox' + selectBoxIds;

		div.appendChild(img);

		var optionDiv = document.createElement('DIV');
		optionDiv.id = 'selectBoxOptions' + selectBoxIds;
		optionDiv.className='selectBoxOptionContainer';
		optionDiv.style.width = div.offsetWidth-2 + 'px';
		div.appendChild(optionDiv);

		if(navigator.userAgent.indexOf('MSIE')>=0){
			var iframe = document.createElement('<IFRAME src="about:blank" frameborder=0>');
			iframe.style.width = optionDiv.style.width;
			iframe.style.height = optionDiv.offsetHeight + 'px';
			iframe.style.display='none';
			iframe.id = 'selectBoxIframe' + selectBoxIds;
			div.appendChild(iframe);
		}

		if(dest.getAttribute('selectBoxOptions')){
			var options = dest.getAttribute('selectBoxOptions').split(';');
			var optionsTotalHeight = 0;
			var optionArray = new Array();
			for(var no=0;no<options.length;no++){
				var anOption = document.createElement('DIV');
				anOption.innerHTML = options[no];
				anOption.className='selectBoxAnOption';
				anOption.onclick = selectOptionValue;
				anOption.style.width = optionDiv.style.width.replace('px','') - 2 + 'px';
				anOption.onmouseover = highlightSelectBoxOption;
				optionDiv.appendChild(anOption);
				optionsTotalHeight = optionsTotalHeight + anOption.offsetHeight;
				optionArray.push(anOption);
			}
			if(optionsTotalHeight > optionDiv.offsetHeight){
				for(var no=0;no<optionArray.length;no++){
					optionArray[no].style.width = optionDiv.style.width.replace('px','') - 22 + 'px';
				}
			}
			optionDiv.style.display='none';
			optionDiv.style.visibility='visible';
		}

		selectBoxIds = selectBoxIds + 1;
	}

