// JavaScript Document
//preload button image for animation
var loginimg = new Array();

loginimg[0] = preload_img("/images/loginbox/button-login.png");
loginimg[1] = preload_img("/images/loginbox/button-login15.png");
loginimg[2] = preload_img("/images/loginbox/button-login30.png");

var regimg = new Array();

regimg[0] = preload_img("/images/loginbox/button-reg.png");
regimg[1] = preload_img("/images/loginbox/button-reg15.png");
regimg[2] = preload_img("/images/loginbox/button-reg30.png");

var submitimg = new Array();

submitimg[0] = preload_img("/images/loginbox/button-submit30.png");
submitimg[1] = preload_img("/images/loginbox/button-submit15.png");
submitimg[2] = preload_img("/images/loginbox/button-submit.png");
submitimg[3] = preload_img("/images/loginbox/button-submit-15.png");
submitimg[4] = preload_img("/images/loginbox/button-submit-30.png");

var resetimg = new Array();

resetimg[0] = preload_img("/images/loginbox/button-reset30.png");
resetimg[1] = preload_img("/images/loginbox/button-reset15.png");
resetimg[2] = preload_img("/images/loginbox/button-reset.png");
resetimg[3] = preload_img("/images/loginbox/button-reset-15.png");
resetimg[4] = preload_img("/images/loginbox/button-reset-30.png");

var confirmimg = new Array();
confirmimg[0] = preload_img("/images/loginbox/2leftbutton-confirm30.png");
confirmimg[1] = preload_img("/images/loginbox/2leftbutton-confirm15.png");
confirmimg[2] = preload_img("/images/loginbox/2leftbutton-confirm.png");

var resetRimg = new Array();
resetRimg[0] = preload_img("/images/loginbox/2rightbutton-reset.png");
resetRimg[1] = preload_img("/images/loginbox/2rightbutton-reset15.png");
resetRimg[2] = preload_img("/images/loginbox/2rightbutton-reset30.png");

var next_rndex = 0;
var intvID;

function doRotate(oid, arrname)
{
	var arr = eval(arrname);
	
	if(next_rndex >= arr.length)
	{
		next_rndex = 0;
	}
	
	//this variable is defined in navtree.js.
	if(is_ie5_5up)
	{
		document.getElementById(oid).filters(0).src = arr[next_rndex].src;
	}
	else
	{
		document.getElementById(oid).src = arr[next_rndex].src;
	}
	next_rndex++;
}

function startRotate(oid, arrname)
{
	next_rndex = 0;
	intvID = window.setInterval("doRotate('"+oid+"', '"+arrname+"')", 100);
}

function stopRotate()
{
	window.clearInterval(intvID);
}

var clockwise = false; //default anticlockwise

function doSwing(oid, arrname)
{
	var arr = eval(arrname);

	if(next_rndex == arr.length - 1)
	{
		clockwise = true;
	}
	else if(next_rndex == 0)
	{
		clockwise = false;
	}
	
	//this variable is defined in navtree.js.
	if(is_ie5_5up)
	{
		document.getElementById(oid).filters(0).src = arr[next_rndex].src;
	}
	else
	{
		document.getElementById(oid).src = arr[next_rndex].src;
	}
	
	
	if(clockwise)
	{
		next_rndex--;
	}
	else
	{
		next_rndex++;
	}
}

function startSwing(oid, arrname)
{
	next_rndex = 0;
	intvID = window.setInterval("doSwing('"+oid+"', '"+arrname+"')", 100);
}

function stopSwing()
{
	window.clearInterval(intvID);
}

function displayCtyList()
{
	if(is_ie)
	{
		var opy_str = "filter:alpha(opacity = 60);";
	}
	else
	{
		var opy_str = "opacity:0.6;";
	}
	
	document.getElementById('ctylist').innerHTML = "<img id=\"us_img\" onClick=\"selectPayWay(this, 2);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/selectcountry_us.gif\" width=\"180\" height=\"90\" border=\"0\">&nbsp;<img id=\"sg_img\" onClick=\"selectPayWay(this, 1);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/selectcountry_sg.gif\" width=\"180\" height=\"90\" border=\"0\">&nbsp;<img id=\"my_img\" onClick=\"selectPayWay(this, 3);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/selectcountry_my.gif\" width=\"180\" height=\"90\" border=\"0\">&nbsp;<img id=\"other_img\" onClick=\"selectPayWay(this, 4);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/selectcountry_others.gif\" width=\"180\" height=\"90\" border=\"0\">";
	
}

function selectPayWay(obj, index)
{
	var imgarr = new Array();
	imgarr[0] = "us_img";
	imgarr[1] = "sg_img";
	imgarr[2] = "my_img";
	imgarr[3] = "other_img";
	
	restoreIMGOpa(imgarr);
	
	if(is_ie)
	{
		obj.filters["alpha"].opacity = 100;
	}
	else
	{
		obj.style.opacity = 1;
	}
	
	if(is_ie)
	{
		var opy_str = "filter:alpha(opacity = 60);";
	}
	else
	{
		var opy_str = "opacity:0.6;";
	}
	
	switch(index)
	{
		case 4:	//other countries
			location.href='retail.php#others';
			break;
		case 3:	//malaysia
			location.href='retail.php#my';
			break;
		case 2:	//United States
			showPdList(2);
			document.getElementById('step3').style.display = "none";
			document.getElementById('step2').style.display = "block";
			//document.getElementById('paywaylst').innerHTML = "<img id=\"wt_img\" onClick=\"showStep3(this, 2);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-WT.gif\" width=\"100\" height=\"60\">&nbsp; <img id=\"tt_img\" onClick=\"showStep3(this, 2);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-tt.gif\" width=\"100\" height=\"60\">&nbsp; <img id=\"ppl_img\" style=\"cursor:pointer; "+opy_str+"\" onClick=\"location.href='oshop.php';\" src=\"/images/logo-paypal.gif\" width=\"100\" height=\"60\" border=\"0\">";
			document.getElementById('paywaylst').innerHTML = "<img id=\"wt_img\" onClick=\"showStep3(this, 2);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-WT.gif\" width=\"100\" height=\"60\">&nbsp; <img id=\"tt_img\" onClick=\"showStep3(this, 2);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-tt.gif\" width=\"100\" height=\"60\">&nbsp; <img id=\"ppl_img\" style=\"cursor:pointer; "+opy_str+"\" onClick=\"location.href='http://shop.mmosite.com/';\" src=\"/images/logo-mmo.jpg\" width=\"100\" height=\"60\" border=\"0\">";
			document.getElementById('usd').style.display = "block";
			document.getElementById('sgd').style.display = "none";
			break;
		case 1:	//Singapore
		default:
			showPdList(1);
			document.getElementById('step3').style.display = "none";
			document.getElementById('step2').style.display = "block";
			document.getElementById('paywaylst').innerHTML = "<br><br><img id=\"enets_img\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-enets.gif\" width=\"100\" height=\"60\" onClick=\"location.href='oenets.php';\">&nbsp; <img id=\"ezy_img\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-ezy.gif\" width=\"100\" height=\"60\" onClick=\"location.href='oezy.php';\">&nbsp;<img id=\"ib_img\" onClick=\"showStep3(this, 1);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-IB.gif\" width=\"100\" height=\"60\">&nbsp; <img id=\"chq_img\" onClick=\"showStep3(this, 1);\" style=\"cursor:pointer; "+opy_str+"\" src=\"/images/logo-cheque.gif\" width=\"100\" height=\"60\">";
			document.getElementById('sgd').style.display = "block";
			document.getElementById('usd').style.display = "none";
			break;
	}
}

function showStep3(obj, flag)
{
	var imgarr = new Array();
	if(flag == 2)	//us
	{
		imgarr[0] = "wt_img";
		//imgarr[1] = "mo_img";
		imgarr[1] = "tt_img";
		//imgarr[3] = "cc_img";
		imgarr[2] = "ppl_img";
	}
	else if(flag == 1)
	{
		imgarr[0] = "enets_img";
		imgarr[1] = "ezy_img";
		imgarr[2] = "ib_img";
		imgarr[3] = "chq_img";
	}
	
	restoreIMGOpa(imgarr);
	
	if(is_ie)
	{
		obj.filters["alpha"].opacity = 100;
	}
	else
	{
		obj.style.opacity = 1;
	}
	
	if(obj.id == "chq_img")
	{
		document.getElementById('bytt').style.display = "none";
		document.getElementById('bycheck').style.display = "block";
	}
	else
	{
		document.getElementById('bytt').style.display = "block";
		document.getElementById('bycheck').style.display = "none";
	}
	
	document.getElementById('step3').style.display = "block";
}

function calcTotal(id)
{
	var total = 0;
	
	if(document.getElementById('ELBPack').checked)	//caribbean pack
	{
		if(!document.getElementById('ELBPack_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('ELBPack_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('ELBPack').value) * parseFloat(document.getElementById('ELBPack_qty').value);
	}
	
	if(document.getElementById('cpack').checked)	//caribbean pack
	{
		if(!document.getElementById('cpack_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('cpack_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('cpack').value) * parseFloat(document.getElementById('cpack_qty').value);
	}
		
	if(document.getElementById('rum70').checked)	//virtual pin
	{
		if(!document.getElementById('rum100_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum100_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum70').value) * parseFloat(document.getElementById('rum100_qty').value);
	}
	
	if(document.getElementById('rum350').checked)	//virtual pin
	{
		if(!document.getElementById('rum300_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum300_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum350').value) * parseFloat(document.getElementById('rum300_qty').value);
	}
	/*
	if(document.getElementById('rum500').checked)	//500 rum code
	{
		if(!document.getElementById('rum500_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum500_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum500').value) * parseFloat(document.getElementById('rum500_qty').value);
	}
	*/
	if(document.getElementById('rum760').checked)	//700 rum code
	{
		if(!document.getElementById('rum700_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum700_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum760').value) * parseFloat(document.getElementById('rum700_qty').value);
	}
	
	if(document.getElementById('rum1080').checked)	//700 rum code
	{
		if(!document.getElementById('rum1000_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum1000_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum1080').value) * parseFloat(document.getElementById('rum1000_qty').value);
	}
	
	if(document.getElementById('rum2150').checked)	//700 rum code
	{
		if(!document.getElementById('rum2000_qty').value.match(/^\d{1,2}$/))
		{
			document.getElementById('rum2000_qty').value = 0;
		}
		
		total += parseFloat(document.getElementById('rum2150').value) * parseFloat(document.getElementById('rum2000_qty').value);
	}
	
	document.getElementById(id).innerHTML = numberformat(total, 2);
}

function showPdList(cty)
{
	switch(cty)
	{
		case 3:	//sg for order proc
			var target = "include/sg2plist.php";
			break;
		case 1:	//sg
			var target = "include/sgplist.php";
			break;
		case 2:	//us
		default:
			var target = "include/usplist.php";
			break;
	}
	
	var pReq = makeReq();
	
	if(pReq)
	{
		pReq.open("GET", target, true);
	
		pReq.onreadystatechange = function()
		{
			if(pReq.readyState == 4 && pReq.status == 200)
			{
				document.getElementById('plist').innerHTML = pReq.responseText;
			}
			else
			{
				document.getElementById('plist').innerHTML = "<center><br><img src='/images/progress_loading.gif' align='center'>&nbsp;Loading...</center>";
			}
		};
		pReq.send(null);
	}
}