function init(){
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	document.images['sizer'].height = y-194;
}

function checkCartForm(frm){
	//if(!validCartTelephone(frm)){
//		alert('Please supply a valid telephone number');
//		return false;	
//	}
	if(!validEmail(frm)){
		return false;
	}
	return true;
}

function checkForm(frm){ /* test if element will work here */
	if(!validEmail(frm)){
		return false;
	}
	switch(frm.selPreference.value){
		case "telephone" :
			if(!validTelephone(frm)){
				alert("Please supply a valid telephone number if you would like to be contacted by this method");
				return false;
			}
			break;
		case "email" :
			return true;
			break;
		default:
			return false;
			break;
	}
	return true;
}

function validCartTelephone(frm){
	var str = frm.night_phone_a.value;
	str = str.replace(/\s/g, '');
	var regpat = /^(\+)?[\d\(\)]{6,}$/;
	var b = regpat.test(str);
	return b;
}

function validTelephone(frm){
	var str = frm.txtTelephone.value;
	str = str.replace(/\s/g, '');
	var regpat = /^(\+)?[\d\(\)]{6,}$/;
	var b = regpat.test(str);
	return b;
}

function confirmDelete(){
	var agree=confirm("Are you sure you want to delete this item?");
	if (agree)
		return true ;
	else
		return false ;
}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
}

function copySelectedOption(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { removeAllOptions(to); var index = 0;}
				to.options[index] = new Option( o.text, o.value, true, true);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	//to.options[1].selected = true; //selectedIndex = 0;
}

function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
}

function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
}

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_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 enlargeImage(path, title){
	var iw = window.open('', 'iw', 'toolbars=no,width=300,height=300,top=50,left=50,resizable=yes');
	iw.document.open();
	iw.document.writeln('<html><head>');
	iw.document.writeln('<title>' + title + '</title>');
	iw.document.writeln('<META HTTP-EQUIV="imagetoolbar" content="no">');
	iw.document.writeln('<script language="javascript" type="text/javascript">function resizeWin(){if (document.all || document.layers) window.resizeTo(document.images[0].width+10,document.images[0].height+40);}</script>');
	iw.document.writeln('</head>');
	iw.document.writeln('<body onload="resizeWin();" style="margin:0px;" onblur="self.close();">');
	iw.document.writeln('<img src="' + path + '" onclick="self.close();" onmouseover="this.style.cursor=\'pointer\';" title="click to close">');
	iw.document.writeln('</body></html>');
	iw.document.close();
}

function goToMedal(medalid){
	if(medalid > 0){
		location.href = '/medal-detail.php?medal=' + medalid;
	}
}

function appendInfo(frm){
	var info = '<OrderLine><prod_code>' + frm.additionalinfo.innerHTML + '</prod_code><item_amount></item_amount><quantity></quantity></OrderLine>';
}

function checkTransaction(frm){
	var req;
	try {
		req = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e){
	}
	req.onreadystatechange = function(){
		if ((req.readyState == 4) && (req.status == 200)){
			switch(req.responseText){
				case 'success':
					frm.submit();
					break;
				case 'fail':
					document.getElementById('msg').innerHTML = 'failed';
					break;
			}
		}
	}
	req.open("GET", "/common/script/transaction.php?merchant=" + frm.merchant.value + "&transid=" + frm.trans_id.value + "&order=" + frm.transxml.value);
	req.send(null);
}

function validEmail(frm){
	var regpat = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})>$|^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/;
	var b = regpat.test(frm.email.value);
	if(!b){
		alert("please enter a valid email address");
	}
	return b;
}