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; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/**
 * NEW BUYLINE
 */
function $(elm) {
	return document.getElementById(elm);
}

function deliop_show(obj) {
	if (obj == 1) {
		$('deliv_details').style.display = 'block';
	} else {
		$('deliv_details').style.display = 'none';
	}
}

function shipp_add(elm) {
	$('shipaddr_form').style.display = 'block';
	if (elm == 1) {
		$('shiptitle').value = $('title').value;
		$('shipfname').value = $('fname').value;
		$('shiplname').value = $('lname').value;
		$('shipcountry').value = $('country').value;
		$('shippcode').value = $('pcode').value;
		$('shipadd1').value = $('add1').value;
		$('shipadd2').value = $('add2').value;
		$('shipadd3').value = $('add3').value;
		$('shiptown').value = $('town').value;

		if ($('delivery').value == '1' && $('shipcountry').value == 'UNITED KINGDOM') {
			deliv_charge('s');
		} else if($('delivery').value == '2' && $('shipcountry').value == 'UNITED KINGDOM') {
			deliv_charge('e');
		} else {
			deliv_charge();
		}
	} else {
		$('shiptitle').value = 'Select';
		$('shipfname').value = '';
		$('shiplname').value = '';
		$('shipcountry').value = 'Select';
		$('shippcode').value = '';
		$('shipadd1').value = '';
		$('shipadd2').value = '';
		$('shipadd3').value = '';
		$('shiptown').value = '';
		
		deliv_charge();
	}
}

function deliv_charge(elm) {
	if (elm == 's') {
		$('deliv_standard').style.display = 'block';
		$('deliv_express').style.display = 'none';
		$('deliv_europe').style.display = 'none';
		$('deliv_world').style.display = 'none';
		$('delivery').value = '1';
		return false;
	} else if(elm == 'e') {
		$('deliv_standard').style.display = 'none';
		$('deliv_express').style.display = 'block';
		$('deliv_europe').style.display = 'none';
		$('deliv_world').style.display = 'none';
		$('delivery').value = '2';
		return false;
	} else {
		EU_countries = new Array(
			"ALBANIA",
			"ANDORRA",
			"ARMENIA",
			"AUSTRIA",
			"AZERBAIJAN",
			"AZORES",
			"BALEARIC ISLANDS",
			"BELGIUM",
			"BOSNIA HERZEGOVINA",
			"BULGARIA",
			"CANARY ISLANDS",
			"CROATIA",
			"CYPRUS",
			"CZECH REPUBLIC",
			"DENMARK",
			"ESTONIA",
			"FAROE ISLANDS",
			"FINLAND",
			"FRANCE",
			"GERMANY",
			"GEORGIA",
			"GIBRALTAR",
			"GREECE",
			"GREENLAND",
			"HUNGARY",
			"ICELAND",
			"IRELAND",
			"ITALY",
			"KAZAKHSTAN",
			"KOSOVO",
			"KYRGYZSTAN",
			"LATVIA",
			"LIECHTENSTEIN",
			"LITHUANIA",
			"LUXEMBOURG",
			"MACEDONIA",
			"MADEIRA",
			"MALTA",
			"MOLDOVA",
			"MONACO",
			"MONTENEGRO",
			"NETHERLANDS",
			"NORWAY",
			"POLAND",
			"PORTUGAL",
			"ROMANIA",
			"RUSSIAN FEDERATION",
			"SAN MARINO",
			"SERBIA",
			"SLOVAKIA",
			"SLOVENIA",
			"SPAIN",
			"SWEDEN",
			"SWITZERLAND",
			"TAJIKISTAN",
			"TURKEY",
			"TURKMENISTAN",
			"UKRAINE",
			"UZBEKISTAN",
			"VATICAN CITY STATE"
		);
//			"UNITED KINGDOM"
		if ($('shipcountry').value == 'UNITED KINGDOM' || $('shipcountry').value == 'Select') {
			$('deliv_standard').style.display = 'block';
			$('deliv_express').style.display = 'none';
			$('deliv_europe').style.display = 'none';
			$('deliv_world').style.display = 'none';
			$('delivery').value = '1';
		} else {
			for (value in EU_countries) {
				if ($('shipcountry').value == EU_countries[value]) {
					$('deliv_standard').style.display = 'none';
					$('deliv_express').style.display = 'none';
					$('deliv_europe').style.display = 'block';
					$('deliv_world').style.display = 'none';
					$('delivery').value = '3';
					break;
				} else {
					$('deliv_standard').style.display = 'none';
					$('deliv_express').style.display = 'none';
					$('deliv_europe').style.display = 'none';
					$('deliv_world').style.display = 'block';
					$('delivery').value = '4';
				}
			}
		}
	}
}

function parseFloatNum(num) {
	num = num+'';
	if (num.lastIndexOf(".") == num.length-2) {
		num = num+'0';
	}
	
	return num;
}

function chkout1() {
	var comm = "";
	if ($('title').value == "" || $('title').value == "Select") {
		comm += 'Your title\n';
	}
	if ($('fname').value == "" || $('lname').value == "") {
		comm += 'Your first nad last name\n';
	}
	if ($('country').value == "" || $('country').value == "Select") {
		comm += 'Your country of origin\n';
	}
	if ($('pcode').value == "") {
		comm += 'Your postcode\n';
	}
	if ($('add1').value == "") {
		comm += 'Your address\n';
	}
	if ($('town').value == "") {
		comm += 'Your town\n';
	}
	if ($('phone').value == "") {
		comm += 'Your telephone\n';
	}
	if ($('email').value == "") {
		comm += 'Email address\n';
	} else {
		var str = $('email').value;
		if ((str.lastIndexOf(".") > str.indexOf("@") && str.indexOf("@") > 0) == false) {
			comm += 'Email address\n';
		}
	}
	
	if ($('shipaddr_form').style.display == "block") {
		if ($('shiptitle').value == "" || $('shiptitle').value == "Select") {
			comm += 'Receiver title\n';
		}
		if ($('shipfname').value == "" || $('shiplname').value == "") {
			comm += 'Receiver first nad last name\n';
		}
		if ($('shipcountry').value == "" || $('shipcountry').value == "Select") {
			comm += 'Shipping country\n';
		}
		if ($('shippcode').value == "") {
			comm += 'Shipping postcode\n';
		}
		if ($('shipadd1').value == "") {
			comm += 'Shipping address\n';
		}
		if ($('shiptown').value == "") {
			comm += 'Shipping town\n';
		}
	} else {
		comm += 'Ship to\n';
	}
	
	if (comm.length == 0) {
		return true;
	} else {
		alert('Please complete following fields!\n\n'+comm);
		return false;
	}
}

function changeimage(sliderImages) {
	if (typeof(currentImage) == "undefined") {
		currentImage = 1;
	} else {
		currentImage = currentImage+1;
	}
	if (typeof(sliderImages[currentImage]) == "undefined") {
		currentImage = 0;
	}
	$('myimage').src = sliderImages[currentImage];
}
