// JavaScript Document
function switch1(div,tt) {
	for(var i=0; i<tt; i++)
	{ 
		obj=document.getElementById(i);
		obj.style.display=(i==div)? "block" : "none"; 
	}
}
function switch2(div,tt) {
	for(var i=0; i<tt; i++)
	{
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(i).style.display = 'none';
		}
		else {
			if (document.layers) { // Netscape 4
				document.i.display = 'none';
			}
			else { // IE 4
				document.all.i.style.display = 'none';
			}
		}
	}
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(div).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.div.display = 'block';
		}
		else { // IE 4
			document.all.div.style.display = 'block';
		}
	}
}

function togglediv(hideShow) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		state=document.getElementById(hideShow).style.display;
		if ( state == 'block') {
			document.getElementById(hideShow).style.display = 'none';
			state= 'hidden';
		}
		else {
			document.getElementById(hideShow).style.display = 'block';
			state= 'block';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			state=document.hideShow.display;
			if ( state == 'block') {
				document.hideShow.display = 'none';
				state= 'hidden';
			}
			else {
				document.hideShow.display = 'block';
				state= 'block';
			}
		}
		else { // IE 4
			state=document.all.hideShow.style.display;
			if ( state == 'block') {
				document.all.hideShow.style.display = 'none';
				state= 'hidden';
			}
			else {
				document.all.hideShow.style.display = 'block';
				state= 'block';
			}
		}
	}
}

function validate_custinfo() //validate customer information during checkout
{	
	if (document.custinfo_form.cko_name.value=="")
	{
		alert("Please enter your name.");
		return false;
	}
	if (document.custinfo_form.cko_contactnumber.value=="")
	{
		alert("Please enter your contact number");
		return false;
	}
	if (document.custinfo_form.cko_email.value=="")
	{
		alert("Please enter your email");
		return false;
	}
	if (emailValidator(document.custinfo_form.cko_email))
	{
		alert("Invalid Email");
		return false;
	}
	if (document.custinfo_form.cko_address.value=="")
	{
		alert("Please enter your address");
		return false;
	}
	if (document.custinfo_form.cko_postalcode.value=="")
	{
		alert("Please enter your postal code");
		return false;
	}
	if (!(document.custinfo_form.cko_country.selectedIndex > 0))
	{
		alert("Please select your country");
		return false;
	}
	if (radioValidator(document.custinfo_form.cko_shipment))
	{
		alert("Please select a shipment mode");
		return false;
	}
	if (radioValidator(document.custinfo_form.cko_payment))
	{
		alert("Please select a payment mode");
		return false;
	}

	return true;
}

function radioValidator(elem)
{
	// set var radio_choice to false
	var radio_choice = false;
	var morethanonechoice = false;
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < elem.length; counter++)
	{   // If a radio button has been selected it will return true (If not it will remain false)
		morethanonechoice = true;
		if (elem[counter].checked)
			radio_choice = true; 
	}
	if (morethanonechoice===false) {
		if (elem.checked)
			radio_choice = true; 
	}
	if (!radio_choice){ // nothing selected
		return true;
	}
	
	return false;
}

function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return false;
	}else{
		//email invalid
		elem.focus();
		return true;
	}
}

var ProdImg_default=""; var ProdImg_defaulturl="";
function ProdImgSwap(imgurl,img,preview){
	
	if (preview=='fix') {
		ProdImg_default = img;
		ProdImg_defaulturl = imgurl;
		
		content = '<a href="'+imgurl+'" onclick="return ProdImgPopup(this.href)"><img src="'+img+'" border=0></a>';
	}
	else if (preview=='preview'){
		content = '<a href="'+imgurl+'" onclick="return ProdImgPopup(this.href)"><img src="'+img+'" border=0></a>';
	}
	else {
		content = '<a href="'+ProdImg_defaulturl+'" onclick="return ProdImgPopup(this.href)"><img src="'+ProdImg_default+'" border=0></a>';
	}
	
	responsediv='ProdImg_Standard';
	if (document.getElementById) {document.getElementById(responsediv).innerHTML  = content;}else {if (document.layers) {document.responsediv.innerHTML = content;}else {document.all.responsediv.innerHTML = content;}}
	
	return false;
}
function ProdImgPopup(href){
	Width=400;
	Height=300;
	TopPosition= (pageHeight()-Height)/2;
	LeftPosition= (pageWidth()-Width)/2;
	settings ='height='+Height+',width='+Width+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no';
	
	window.open(href,'MIYOC_ProdImgPopup',settings);
	return false;
}
function ProdImgPopupResize(w,h){
	window.moveTo(0,0);
	if (w==800 || h==600){
		if (w==800 && h<=300) h=300;
		else if (w<=400 && h==600) w=400;
	}
	else if (w<=400 && h<=300){
		w=400; h=300;
	}
	else{
		if (w<=400) w=400;
		else if (h<=300) h=300;
	}
	
	window.resizeTo(w+50,h+120);

	TopPosition= ((screen.height-h)/2) -70;
	LeftPosition= (screen.width-w)/2;
	window.moveTo(LeftPosition,TopPosition);
}
function ProdImgPopupFullscrn(){
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}

var t;  var RateFullstar=""; var RateHalfstar=""; var RateNostar="";
function ProdRating(id,val,curRating){
	clearTimeout(t);
	
	if (val<6)
		var reps=val+1;
	else
		var reps=curRating;
	
	var content="";
	for (i=0;i<5;i++){		
		if (reps>=1){
			content = content+'<img src="'+RateFullstar+'" border="0" onmouseover="ProdRating('+id+','+i+','+curRating+')" onmouseout="ProdRating('+id+',9,'+curRating+')" onmousedown="ProdRatingSave('+id+','+i+')" style="cursor:pointer">';
			reps = reps - 1;
		}
		else if (reps>0 && reps<1){
			content = content+'<img src="'+RateHalfstar+'" border="0" onmouseover="ProdRating('+id+','+i+','+curRating+')">';
			reps = reps - reps;
		}
		else {
			content = content+'<img src="'+RateNostar+'" border="0" onmouseover="ProdRating('+id+','+i+','+curRating+')">';
		}
	}
	
	WriteDiv('ratingspan'+id,content);
	
	t=setTimeout( "ProdRating("+id+",9,"+curRating+")" ,800);
}
function ProdRatingSave(a,b){
	window.location = '../../index.php?mode=rate&a='+a+'&b='+(b+1);
}

function SureDefaultParams(sel,choice){
	return confirm('This item is available in different "'+sel+'".\nThe default choice is "'+choice+'".\n\nAre you sure you want to add this item to your shopping cart?');
}

function AddtocartMethod1(href,price,paramsel,paramchoice){
	var t=1;
	if (typeof paramsel != 'undefined' ) {
		t = SureDefaultParams(paramsel,paramchoice);
	}
	
	if (t==1){
		ShowAddtocartBox('Adding item to your shopping cart...');
		ajaxFunction_AddtoCart(href,price);
	}
	
	return false;
}

var ShowAddtocartBox_BackgroundColour; var ShowAddtocartBox_BorderColour;
function ShowAddtocartBox(content){
	var div='addtocartlayer';
	var width = 300;
	var height = 50;
	
	ResizeDiv(div,width,height);
	
	if (ShowAddtocartBox_BackgroundColour == undefined)
		ShowAddtocartBox_BackgroundColour = '#D1F7CF';
	if (ShowAddtocartBox_BorderColour == undefined)
		ShowAddtocartBox_BorderColour = '#26B273';
	RecolorDiv(div,ShowAddtocartBox_BackgroundColour,ShowAddtocartBox_BorderColour);
	
	var x = ((pageWidth()-width)/2) + posLeft();
	var y = ((pageHeight()-height)/2) + posTop();
	ReposDiv(div,x,y);
	DispDiv(div,'block');
	WriteDiv(div,'<table width=100% height=100%><tr><td align=center>'+content+'</td></tr></table>');
}

function WriteDiv(responsediv,content){if (document.getElementById) {document.getElementById(responsediv).innerHTML = content;}else {if (document.layers) {document.responsediv.innerHTML = content;}else {document.all.responsediv.innerHTML = content;}}}
function ResizeDiv(responsediv,w,h){if (document.getElementById) {document.getElementById(responsediv).style.width = w;document.getElementById(responsediv).style.height = h;}else {if (document.layers) {document.responsediv.style.width = w;document.responsediv.style.height = h;}else {document.all.responsediv.style.width = w;document.all.responsediv.style.height = h;}}}
function ReposDiv(responsediv,l,t){if (document.getElementById) {document.getElementById(responsediv).style.left = l;document.getElementById(responsediv).style.top = t;}else {if (document.layers) {document.responsediv.style.left = l;document.responsediv.style.top = t;}else {document.all.responsediv.style.left = l;document.all.responsediv.style.top = t;}}}
function RecolorDiv(responsediv,bg,border){if (document.getElementById) {document.getElementById(responsediv).style.backgroundColor = bg;document.getElementById(responsediv).style.borderColor = border;document.getElementById(responsediv).style.borderStyle = 'solid';document.getElementById(responsediv).style.borderWidth = '1px';}else {if (document.layers) {document.responsediv.style.backgroundColor = bg;document.responsediv.style.borderColor = border;document.responsediv.style.borderStyle = 'solid';document.responsediv.style.borderWidth = '1px'}else {document.all.responsediv.style.backgroundColor = bg;document.all.responsediv.style.borderColor = border;document.all.responsediv.style.borderStyle = 'solid';document.all.responsediv.style.borderWidth = '1px'}}}
function DispDiv(responsediv,state){if (document.getElementById) {document.getElementById(responsediv).style.display=state;}else {if (document.layers) {document.responsediv.style.display=state;}else {document.all.responsediv.style.display=state;}}}

function ajaxFunction(responsediv,page){
xmlhttp=GetXmlHttpObject(); if(xmlhttp==null){alert("Your browser does not support XMLHTTP!");return;}
xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4) WriteDiv(responsediv,xmlhttp.responseText) }
xmlhttp.open("GET",page,true);xmlhttp.send(null);}

function ajaxFunction_RefreshPage(refreshto,page){
xmlhttp=GetXmlHttpObject(); if(xmlhttp==null){alert("Your browser does not support XMLHTTP!");return;}
xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4) window.location=refreshto; }
xmlhttp.open("GET",page,true);xmlhttp.send(null);}

function ajaxFunction_AddtoCart(page,price){
xmlhttp=GetXmlHttpObject(); if(xmlhttp==null){alert("Your browser does not support XMLHTTP!");return;}
xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4) {
	varCartItems = varCartItems+1;
	varCartPrice = varCartPrice+price;
	ShowAddtocartBox('Item has been added to your shopping cart.<br><b>'+varCartItems+' item(s), Subtotal: '+varCartPrice.toFixed(2)+'</b>');
	WriteDiv('yoccartitems',varCartItems);
	WriteDiv('yoccartprice',varCartPrice.toFixed(2));
}}
xmlhttp.open("GET",page,true);xmlhttp.send(null);
}

function stateChanged(){if (xmlhttp.readyState==4){document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}}
function GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}

function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} 
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} 
function posRight() {return posLeft()+pageWidth();} 
function posBottom() {return posTop()+pageHeight();}
