var wi = ["wi_ideal","wi_trend","wi_fibonacci","wi_patterns","wi_osc1","wi_osc2"];
function WI(id)
{
	if(document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
	else
	{
		document.getElementById(id).style.display = "block";
	}
	for(var i=0; i<wi.length; i++)
	{
		
		if(wi[i]!= id)
		{
			document.getElementById(wi[i]).style.display="none"
		}
	}
}

var wa = ["wa_technical","wa_trend","wa_chart","wa_fibonacci","wa_andrew","wa_steps","wa_money","wa_live","wa_strategy"];
function WA(id)
{
	if(document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
	else
	{
		document.getElementById(id).style.display = "block";
	}
	for(var i=0; i<wa.length; i++)
	{
		
		if(wa[i]!= id)
		{
			document.getElementById(wa[i]).style.display="none"
		}
	}
}

var wx = ["wx_fundamentals","wx_forex","wx_terminology","wx_candlestick","wx_patterns","wx_technical","wx_live","wx_money"];
function WX(id)
{
	if(document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
	else
	{
		document.getElementById(id).style.display = "block";
	}
	for(var i=0; i<wx.length; i++)
	{
		
		if(wx[i]!= id)
		{
			document.getElementById(wx[i]).style.display="none"
		}
	}
}

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 changeColor(cur,color){
	cur.style.background = color;
}

// prompt confirm delete message
function confirmDelete(frm) 
{
  var noChecked = 0; // Change to 1 when a checkbox is checked.

  for(var i=0;i < frm.length;i++) 
  {
	if(frm.elements[i].type == "checkbox" && frm.elements[i].checked == true)
	{
	  noChecked = 1;
	}
  }

  if(noChecked == 0) // No record selected. Prompt error message.
  {
	alert("Please select a record to delete!");
	return false;
  }	
  if (confirm("Are you sure you want to delete this record?") == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

// prompt confirm delete message
function confirmUpdate(frm) 
{
  var noChecked = 0; // Change to 1 when a checkbox is checked.

  for(var i=0;i < frm.length;i++) 
  {
	if(frm.elements[i].type == "checkbox" && frm.elements[i].checked == true)
	{
	  noChecked = 1;
	}
  }

  if(noChecked == 0) // No record selected. Prompt error message.
  {
	alert("Please select a record to update!");
	return false;
  }	
  if (confirm("Are you sure you want to update this record?") == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

// prompt confirm delete message
function confirmDel(msg)
{
  if (confirm(msg) == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

ns4=(navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? 1 : 0;
ie4=(document.all && !document.getElementById)? 1 : 0;
ie5=(document.getElementById && document.all)? 1 : 0;
ns6=(document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? 1: 0;
w3c=(document.getElementById)? 1 : 0;

wid=(ie4||ie5)?window.document.body.clientWidth-20:window.innerWidth-36

if(ns4){document.write ('<layer name="di1"></layer>')}else{document.write ('<div id="di1" style="position:absolute;z-index:100" ></div>')}

outd=""

if(w3c)div1=document.getElementById('di1')
if(ie4)div1=document.all['di1']
if(ns4)div1=document.layers['di1']

function move_div(x,y){
	if (isNaN(x+y))return
	if(ns4){div1.moveTo(x,y)}else{div1.style.left=x+'px';div1.style.top=y+'px';}
}

function write_div(text){
	if(ns4){
		div1.document.open();
		div1.document.write(text);
		div1.document.close();
	}
	else {div1.innerHTML=text;}
}
 
function big(n){
ondiv=n
		write_div("<a href=javascript:void(0) onmouseout='big_hide()' onmouseover='ondiv=1'><table cellspacing=0 cellpadding=0 border=0 bgcolor=#FFFFE8><tr><td height=1 bgcolor=#000000 colspan=5></td></tr><tr><td width=1 bgcolor=#000000></td><td colspan=3 height=2></td><td width=1 bgcolor=#000000></td></tr><tr><td width=1 bgcolor=#000000></td><td width=2></td><td class=content>"+n+"</td><td width=2></td><td width=1 bgcolor=#000000></td></tr><tr><td width=1 bgcolor=#000000></td><td colspan=3 height=2></td><td width=1 bgcolor=#000000></td></tr><tr><td height=1 bgcolor=#000000 colspan=5></td></tr></table></a>");
		move_div(x,y);
}

function big_hide(){
	ondiv=0;
	t3=window.setTimeout('big_hide2()',100)
}

function big_hide2(){
if (ondiv==0){
	write_div("");
	move_div(-1000,-1000)}
}

y=x=0
function dragIt(evt){if(ie4||ie5){x=window.event.clientX+document.body.scrollLeft; y=window.event.clientY+document.body.scrollTop}else {x=evt.pageX ; y=evt.pageY }}

document.onmousemove = dragIt
if(ns4){document.captureEvents( Event.MOUSEMOVE )}

// valid form fieldboxs
function validFrm(str) 
{
  	// General declare for messages.
  	var i,p,nm,counter,condition,errors='',args,title,val;
  	counter = 0;
  	args = str.split(",");
	// loop through all the fields
  	for (i=1; i<(args.length-1); i+=2) 
  	{  
    	if (counter == 0) 
		{
    		condition=args[i+1];
	 		nm=(findObj(args[i])); 
			title=nm.name;
			check=nm.checked;
			val=nm.value;
			// check for empty fields
			if (val !="") 
	    	{
				if (condition.indexOf('P')!=-1) 
            	{
					if (val.length < 4)
					{
						errors=title+' must be at least 4 characters.\n';
						counter = i;
					}
	        	}
				else if (condition.indexOf('C')!=-1) 
            	{
                	if (check == false)
					{
						errors=title+' box is not check.\n';
						counter = i;
					}
	        	}
				// verify number
            	else if (condition.indexOf('N')!=-1) 
            	{
                	if (isNaN(val))
					{
						errors=title+' must be a number.\n';
						counter = i;
					}
	        	}
				// verify email
				else if (condition.indexOf('E')!=-1) 
				{ 
			    	p=val.indexOf('@');
					x=val.indexOf('.');
					myExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
				
               		// if (p<1 || p==(val.length-1)) 
			   		if(myExp.test(val) == false)
					{
						errors=title+' must be a valid e-mail address.\n';
						counter = i;
					}
				}
        	}
        	else if (condition.charAt(0) == 'V') 
			{
				errors =title+' is required.\n'; 
				counter = i;
			}
		}
  	} 
	// 	displays error message
  	if (counter != 0) 
  	{
  		alert(errors);
		nm.focus();
		return false;
  	}
  	else
  	{
	  	if (confirm("Confirm " + args[0] + "?") == 0)
	  	{
			if (args[1] == null)
			{
				return false;
			}
			else
			{
		  		(findObj(args[1])).focus();
			}
		  	return false;
	  	}
		else
		{
			return true;
		}
  	}
}

// valid form fieldboxs
function validFrm2(str) 
{
  	// General declare for messages.
  	var i,p,nm,counter,condition,errors='',args,title,val;
  	counter = 0;
  	args = str.split(",");
	// loop through all the fields
  	for (i=1; i<(args.length-1); i+=2) 
  	{  
    	if (counter == 0) 
		{
    		condition=args[i+1];
	 		nm=(findObj(args[i])); 
			title=nm.name;
			check=nm.checked;
			val=nm.value;
			// check for empty fields
			if (val !="") 
	    	{
				if (condition.indexOf('P')!=-1) 
            	{
					if (val.length < 4)
					{
						errors=title+' must be at least 4 characters.\n';
						counter = i;
					}
	        	}
				else if (condition.indexOf('C')!=-1) 
            	{
                	if (check == false)
					{
						errors=title+' box is not check.\n';
						counter = i;
					}
	        	}
				// verify number
            	else if (condition.indexOf('N')!=-1) 
            	{
                	if (isNaN(val))
					{
						errors=title+' must be a number.\n';
						counter = i;
					}
	        	}
				// verify email
				else if (condition.indexOf('E')!=-1) 
				{ 
			    	p=val.indexOf('@');
					x=val.indexOf('.');
					myExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
				
               		// if (p<1 || p==(val.length-1)) 
			   		if(myExp.test(val) == false)
					{
						errors=title+' must be a valid e-mail address.\n';
						counter = i;
					}
				}
        	}
        	else if (condition.charAt(0) == 'V') 
			{
				errors =title+' is required.\n'; 
				counter = i;
			}
		}
  	} 
	// 	displays error message
  	if (counter != 0) 
  	{
  		alert(errors);
		nm.focus();
		return false;
  	}
  	else
  	{
		return true;
  	}
}

function findObj(n, d) 
{
	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=findObj(n,d.layers[i].document);
  	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function checkTrialTotal(total)
{
	temp = 0;
	for(i=0;i<total;i++)
	{
		if(document.getElementById("checkbox"+i).checked)
		{
			temp++;
		}
	}
	if(temp > 1)
	{
		alert("Only 1 category are allow for trial!");
		return false;
	}
	else
	{
		return true;
	}
}

function checkReferral()
{
	for(i=1;i<=10;i++)
	{
		if(document.getElementById("Email Address "+i).value == "" && document.getElementById("Name "+i).value != "")
		{
			alert("Email Address " + i + " is required.\n"); 
			document.getElementById("Email Address "+i).focus();
			return false;
		}
		else if(document.getElementById("Email Address "+i).value != "" && document.getElementById("Name "+i).value == "")
		{
			alert("Name " + i + " is required.\n"); 
			document.getElementById("Name "+i).focus();
			return false;
		}
	}
	return true;
}
function checkReportTotal(total)
{
	temp_sgd_before = 0;
	temp_usd_before = 0;
	temp_sgd = 0;
	temp_usd = 0;
	temp = 0
	temp_string = "";
	for(i=0;i<total;i++)
	{
		if(document.getElementById("checkbox"+i).checked)
		{
			if (i==0)
			{
				temp_string = "1";
			}
			else
			{
				temp_string = temp_string + ",1";
			}
			temp_sgd_before = temp_sgd_before + Number(document.getElementById("price_sgd"+i).value);
			temp_usd_before = temp_usd_before + Number(document.getElementById("price_usd"+i).value);
			if (temp == 0)
			{
				temp_sgd = temp_sgd + Number(document.getElementById("price_sgd"+i).value);
				temp_usd = temp_usd + Number(document.getElementById("price_usd"+i).value);
			}
			else if (temp == 1)
			{
				temp_sgd = temp_sgd + Number(document.getElementById("price_sgd"+i).value) - Number(document.getElementById("more").value);
				temp_usd = temp_usd + Number(document.getElementById("price_usd"+i).value) - Number(document.getElementById("more_usd").value);
			}
			else
			{
				temp_sgd = temp_sgd + Number(document.getElementById("price_sgd"+i).value) - Number(document.getElementById("more2").value);
				temp_usd = temp_usd + Number(document.getElementById("price_usd"+i).value) - Number(document.getElementById("more2_usd").value);
			}
			temp++;
		}
		else
		{
			if (i==0)
			{
				temp_string = "0";
			}
			else
			{
				temp_string = temp_string + ",0";
			}
		}
	}
	
	document.getElementById("temp_string").value = temp_string;
	document.getElementById("bprice_sgd").value = temp_sgd_before;
	document.getElementById("bprice_usd").value = temp_usd_before;
	document.getElementById("price_sgd").value = temp_sgd;
	document.getElementById("price_usd").value = temp_usd;
	//var pro = document.getElementById("Promotion Code").value;
	//alert(temp_sgd);
	//var proArray = new Array();
	//proArray = pro.split(',');
	//promotion = Number(proArray[1]);
	//temp_sgd = temp_sgd * ((100 - promotion)/100);
	//temp_usd = temp_usd * ((100 - promotion)/100);
	
	if (document.getElementById("Month Payment").value == 1 || document.getElementById("Month Payment").value == 0)
	{
		document.getElementById("Price (SGD)").value = r2(temp_sgd);
		document.getElementById("Price (USD)").value = r2(temp_usd);
	}
	else if (document.getElementById("Month Payment").value == 3)
	{
		document.getElementById("Price (SGD)").value = r2(temp_sgd * ((100 - Number(document.getElementById("three months").value))/100))*3;
		document.getElementById("Price (USD)").value = r2(temp_usd * ((100 - Number(document.getElementById("three months").value))/100))*3;
	}
	else if (document.getElementById("Month Payment").value == 6)
	{
		document.getElementById("Price (SGD)").value = r2(temp_sgd * ((100 - Number(document.getElementById("six months").value))/100))*6;
		document.getElementById("Price (USD)").value = r2(temp_usd * ((100 - Number(document.getElementById("six months").value))/100))*6;
	}
}

function r2(n) { 

  ans = n * 1000 
  ans = Math.round(ans /10) + "" 
  
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
} 

function checkCategory(total)
{
	temp = 0;
	for(i=0;i<total;i++)
	{
		if(document.getElementById("checkbox"+i).checked)
		{
			temp++;
		}
	}
	if(temp == 0)
	{
		alert("Need to select at least one category!");
		return false;
	}
	else
	{
		return true;
	}
}
