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.0
  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 && document.getElementById) x=document.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_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0 
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
	if (restore) selObj.selectedIndex=0; 
} 

/* tabs */

function showtab(tab){
	resettabs();
	document.getElementById("tab_"+tab).className="tab_s";
	if (document.getElementById(tab)) {
		document.getElementById(tab).style.display="";
	}
}

function resettabs() {
	var litab,idname;
	
	// get all LIs in tabs, loop over them 
	litab=document.getElementById('tabs').getElementsByTagName('li');
	
	for(i=0;i<litab.length;i++) {
		litab[i].className="tab";
		idname = litab[i].id.replace(/tab_([a-z0-9]+)$/i,'$1');
		if (document.getElementById(idname)) {
			document.getElementById(idname).style.display="none";
		}
	}
}

// --------------------------------------------------------------------------

function checkForm(form,errorClass,OKClass)	{
	var required = new Array;
	required = form['required'].value.split(",");
	var field = '';
	for (var c=0; c<required.length; c++)	{
		field = required[c];
		if (!form[field].length || form[field].type == 'select-one')	{
			if ((form[field].type == 'radio' || form[field].type == 'checkbox') && form[field].checked != true)	{
				form[field].focus();
				form[field].className=errorClass;
				return false;
			}
			else if (form[field].value == "")	{
				form[field].focus();
				form[field].className=errorClass;
				return false;
			}
			else	{ form[field].className=OKClass; }
		}
		else	{
			var checked = false;
			for (i = 0; i < form[field].length; ++i)	{
				if (form[field][i].checked == true)	{
					checked = true;
					break;
				}
			}
			if (!checked)	{
				form[field][0].focus();
				for (i = 0; i < form[field].length; ++i)	{
					form[field][i].className=errorClass;
				}
				return false;
			}
			else	{
				for (i = 0; i < form[field].length; ++i)	{
					form[field][i].className=OKClass;
				}
			}
		}
	}
	return true;
}

// --------------------------------------------------------------------------

function updateBillingAdr(cbox)	{
	if (cbox.checked == true)	{
		var form = document.mainform;
		form.billing_firstname.value = form.contact_firstname.value;
		form.billing_lastname.value = form.contact_lastname.value;
		form.billing_address.value = form.contact_address.value;
		form.billing_zipcode.value = form.contact_zipcode.value;
		form.billing_city.value = form.contact_city.value;
		initSelectBoxValue(form,'billing_country',form.contact_country.value);
		form.billing_email.value = form.contact_email.value;
	}
}

// --------------------------------------------------------------------------

function updateSize(cut,defaultlbl)	{
	var sizes = new Array(3);
	sizes[0] = new Array('S', 'M', 'L', 'XL', 'XXL');
	sizes[1] = new Array('S', 'M', 'L', 'XL');
	sizes[2] = new Array();
	
	var id = 0;
	if (cut.options[cut.selectedIndex].value == 'women')
		id = 1;
	else if (cut.options[cut.selectedIndex].value == '')
		id = 2;
		
	var combo = document.getElementById('size');
	combo.options.length = 0;
	combo.options[0] = new Option(defaultlbl,'');
	
	for (i=0;i<sizes[id].length;i++)	{
		combo.options[i+1] = new Option(sizes[id][i],sizes[id][i]);
	}
}

// --------------------------------------------------------------------------

function initSelectBoxValue(form,fld,val)	{
	for (i = 0; i < form[fld].options.length; ++i)	{
		if (form[fld].options[i].value == val)	{
		  form[fld].options.selectedIndex = i;
		  break;
		}
	}
}

// --------------------------------------------------------------------------

function initSelectBoxText(form,fld,txt)	{
	for (i = 0; i < form[fld].options.length; ++i)	{
		if (form[fld].options[i].text == txt)	{
		  form[fld].options.selectedIndex = i;
		  break;
		}
	}
}

// --------------------------------------------------------------------------

function initRadioValue(form,fld,val)	{
	if (!form[fld].length)	{
		if (form[fld].value == val)	{
		  form[fld].checked = true;
		}
		return;
	}
	for (i = 0; i < form[fld].length; ++i)	{
		if (form[fld][i].value == val)	{
		  form[fld][i].checked = true;
		  break;
		}
	}
}
