var langId = GetParam("lang=id",0);
var did = GetParam("dist=id",1);
var primeDid = GetParam("pdist=id",1);
var langImg = GetParam("img=url","General/"); 
var dlUrl = GetParam("dl=url","http://216.152.173.130/dl/did"+did+"/installcasino.exe"); 

var activeLink,preloadFlag = false;

function CheckValidFrm(Frm)
{
 var i;
 var currName,currFld,pattern;

 for (i=0; i<Frm.length; i++)
 {
 	currFld = Frm.elements[i];
	
	if (!currFld.disabled && currFld.id && currFld.id.indexOf("~") != -1 && Number(currFld.id.split("~")[1]) == 1) 
	{
		currName = currFld.id.split("~")[0];
		
		switch (currFld.type)
		{
			case "text":
				pattern = /\w+\W*/
				if (currFld.name == "Email")
					pattern = /^(\w+((-\w+)|(\.\w+))*){2,30}\@((\w(\.?))+(-\w+)*){2,20}\.[a-zA-Z]{2,7}((\.[a-zA-Z]{2,10})?)$/
				else if (currFld.name == "Username")
					pattern = /^[a-zA-Z0-9_]{5,10}$/
				
				if (!pattern.test(currFld.value))
					return DisableAction(currFld,"Valid " + currName + " is required");
			break;

			case "password":
				pattern = /^\w{6,10}$/
				if (!pattern.test(currFld.value))
						return DisableAction(currFld,"Valid " + currName + " is required");
	
			 	else if(currFld.value.toLowerCase() != Frm.ConfPassword.value.toLowerCase())
			 		 	return DisableAction(Frm.ConfPassword,"Password is not confirmed correctly");
			break;
			
			case "textarea":
				pattern = /\w*\W*/
				if (currFld.name == "SiteDesc")
					pattern = /\w+\W*/

				if (!pattern.test(currFld.value))
						return DisableAction(currFld,currName + " is required");
						
				if (currFld.value.length > 250)
					return DisableAction(currFld,currName + " must not exceed 250 characters");
			break;
			
			case "select-one":
				if (currFld.name != "State" && currFld.selectedIndex <= 0)
					return DisableAction(currFld,"Valid " + currName + " is required");
					
				if (currFld.name == "Country" && (currFld.value == "US" || currFld.value == "CA") && Frm.State.selectedIndex == 0)
					return DisableAction(Frm.State,"Valid State is required");
				
				
			break;
		}
 	
 	}
  }
  
  	if (Frm.Country)
  	{
  		Frm.Country.options[Frm.Country.selectedIndex].value = Frm.Country.options[Frm.Country.selectedIndex].text;
  		Frm.State.options[Frm.State.selectedIndex].value = Frm.State.options[Frm.State.selectedIndex].text;
 	}
 }

 
function ToggleState(Ctrl)
{
 var Frm = Ctrl.form
 if (Frm.State)
 	Frm.State.selectedIndex = 0;
		
 if (Ctrl)
 {
 	 
	 var sList = Frm.AllStates
	 var cs = Frm.State
	 cs.length = 1
	 cs.disabled = true
	 if (Ctrl.value == "US" || Ctrl.value == "CA")
	 {
	 	cs.disabled = false;
	 	for (i=sList.length-1;i>=0;i--)
		{
			if (sList.options[i].value.indexOf("~" + Ctrl.value) != -1)
			{
				sListArr = sList.options[i].value.split("~");
				stateId = sListArr[0];
				
				
				cState = new Option(sList.options[i].text,stateId);
				cs.add(cState,1);
				
				if (cState.value == Frm.cState.value)
					cState.selected = true;
			}
		}
		
		cs.options[0].value = "N/A";
		
	    //document.all.StateRow.style.display = "block";
	 }
	 else
	 {
	    cs.selectedIndex = 0;	
	    //document.all.StateRow.style.display = "none";
	 }
 }
}


function DisableAction(Ctrl,Msg)
{
 alert(Msg);
 if (Ctrl.type.indexOf("select") == -1) 
 	Ctrl.select();
 Ctrl.focus();
 return false;
}

function GetParam(strCk,retVal)
{
	var str = document.cookie
	var start = str.indexOf(strCk)
	if (start == -1)
		return retVal;
	else
	{	
		start+=(strCk.length+1);
		var end = str.indexOf(";",start)
		if (end == -1)
			end = str.length;
		
		var val = unescape(str.substring(start,end))
		return ((val == "" || val == "undefined") ? retVal : val);
	}
}

function GetUrlParam(win,param,def)
{
	var paramArr,val = def;
	
	if (win.location.href.toLowerCase().indexOf(param + "=") != -1)
	{

		paramArr = win.location.href.split("&")
		if (paramArr.length > 1 && paramArr.length != "undefined")
		{
			for (var i=0;i<paramArr.length;i++)
			{
				if (paramArr[i].toLowerCase().indexOf(param + "=") != -1)
					val = paramArr[i].split("=")[1];
			}
		}
		else
			val = win.location.href.toLowerCase().split(param + "=")[1];

	}
	
	if (val == "")
		val = def;
	return val;
}

function findObj(n, d) { //v3.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=findObj(n,d.layers[i].document); return x;
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CenterPopUp(Url,WindowWidth,WindowHeight)
{
	var WindowTop = (screen.availHeight/2) - (WindowHeight/2);
	var WindowLeft = (screen.availWidth/2) - (WindowWidth/2);
	var WindowProps = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+WindowWidth+',height='+WindowHeight+',left='+WindowLeft+',top='+WindowTop+',screenx='+WindowLeft+',screeny='+WindowTop;
	PopUpWindow = window.open(Url,"",WindowProps);
}

function CenterPopUpNoScrollBars(Url,WindowWidth,WindowHeight)
{
	var WindowTop = (screen.availHeight/2) - (WindowHeight/2);
	var WindowLeft = (screen.availWidth/2) - (WindowWidth/2);
	var WindowProps = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+WindowWidth+',height='+WindowHeight+',left='+WindowLeft+',top='+WindowTop+',screenx='+WindowLeft+',screeny='+WindowTop;
	PopUpWindow = window.open(Url,"",WindowProps);
}
function resizeWin(WindowWidth,WindowHeight)
{
	var WindowTop = (screen.Height/2) - (WindowHeight/2);
	var WindowLeft = (screen.Width/2) - (WindowWidth/2);
	
	window.resizeTo(WindowWidth,WindowHeight);
	window.moveTo(WindowLeft,WindowTop);
}
function PreviewPopUp(WhatImage) 
{
	var Url = 'Preview_Window.html?WhatImage='+WhatImage;
	var WindowWidth = 405;
	var WindowHeight = 393;
	var WindowTop = (screen.availHeight/2) - (WindowHeight/2);
	var WindowLeft = (screen.availWidth/2) - (WindowWidth/2);
	var WindowProps = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+WindowWidth+',height='+     WindowHeight+',left='+WindowLeft+',top='+WindowTop+',screenx='+WindowLeft+',screeny='+WindowTop;
	PreviewWindow = window.open(Url,"PreviewWindow",WindowProps);
	if (PreviewWindow.opener == null) PreviewWindow.opener = self;
	return;
}
function displayStateField()
{
    if (document.all.CountrySelect.value == 'United States')
    {
        document.all.CanadaStateList.style.visibility='hidden';
        document.all.CanadaStateList.style.display='none';
        document.all.USAStateList.style.visibility='visible';
        document.all.USAStateList.style.display='block';
    }
    else if (document.all.CountrySelect.value == 'Canada')
    {
        document.all.USAStateList.style.visibility='hidden';
        document.all.USAStateList.style.display='none';
        document.all.CanadaStateList.style.visibility='visible';
        document.all.CanadaStateList.style.display='block';
    }
    else
    {
        document.all.USAStateList.style.visibility='hidden';
        document.all.USAStateList.style.display='none';
        document.all.CanadaStateList.style.visibility='hidden';
        document.all.CanadaStateList.style.display='none';
    }
}
function ToggleHiddenField(FieldId)
{
    if (document.getElementById(FieldId) != null)
    {
        if (document.getElementById(FieldId).style.display == 'none')
        {
            document.getElementById(FieldId).style.display = '';
        }
        else
        {
            document.getElementById(FieldId).style.display = 'none';
        }
    }
}
/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer=1 //index of message array for hidden div
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%;" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
    var scrollerinstance=this
    if (window.addEventListener) //run onload in DOM2 browsers
    window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
    else if (window.attachEvent) //run onload in IE5.5+
    window.attachEvent("onload", function(){scrollerinstance.initialize()})
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
    setTimeout(function(){scrollerinstance.initialize()}, 500)
    }

    // -------------------------------------------------------------------
    // initialize()- Initialize scroller method.
    // -Get div objects, set initial positions, start up down animation
    // -------------------------------------------------------------------

    pausescroller.prototype.initialize=function(){
    this.tickerdiv=document.getElementById(this.tickerid)
    this.visiblediv=document.getElementById(this.tickerid+"1")
    this.hiddendiv=this.hiddendiv=document.getElementById(this.tickerid+"2")
    this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility="visible"
    var scrollerinstance=this
    document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
    document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
    if (window.attachEvent) //Clean up loose references in IE
    window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
    setTimeout(function(){scrollerinstance.animateup()}, this.delay)
    }


    // -------------------------------------------------------------------
    // animateup()- Move the two inner divs of the scroller up and in sync
    // -------------------------------------------------------------------

    pausescroller.prototype.animateup=function(){
    var scrollerinstance=this
    if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
    this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
    this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
    setTimeout(function(){scrollerinstance.animateup()}, 50)
    }
    else{
    this.getinline(this.hiddendiv, this.visiblediv)
    this.swapdivs()
    setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
    }
    }

    // -------------------------------------------------------------------
    // swapdivs()- Swap between which is the visible and which is the hidden div
    // -------------------------------------------------------------------

    pausescroller.prototype.swapdivs=function(){
    var tempcontainer=this.visiblediv
    this.visiblediv=this.hiddendiv
    this.hiddendiv=tempcontainer
    }

    pausescroller.prototype.getinline=function(div1, div2){
    div1.style.top=this.visibledivtop+"px"
    div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
    }

    // -------------------------------------------------------------------
    // setmessage()- Populate the hidden div with the next message before it's visible
    // -------------------------------------------------------------------

    pausescroller.prototype.setmessage=function(){
    var scrollerinstance=this
    if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
    setTimeout(function(){scrollerinstance.setmessage()}, 100)
    else{
    var i=this.hiddendivpointer
    var ceiling=this.content.length
    this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
    this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
    this.animateup()
    }
    }

    pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
    if (tickerobj.currentStyle)
    return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
    return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
    return 0
}