// JavaScript Document

var winW = 1024, winH = 768;
var anax = 0, anay = 400;
var anaw = 929, anah = 902;
var difx = 0, dify = 0;
var maxzindex = 1;
var currentw = 0;
var currenth = 0;
var currentdiv = null;
var currentx = 0;
var currenty = 0;
var editmode = false;
var profileshow = false;
var defaultstr = "1:220:75:1:209,2:-1:24:1:182,3:241:174:1:277,4:368:3:1:305,5:460:1:1:300,6:444:159:1:276,7:681:4:1:270,8:657:255:1:280,9:-5:196:1:234,10:237:302:1:227,11:443:317:1:237,12:228:517:1:240,13:14:533:1:300,14:610:378:1:284,15:504:514:1:291,16:661:693:1:288,17:20:780:1:292,18:864:1:1:10003,";

function editprofile()
{
	editmode = true;
}

function saveprofile()
{
	var mantar = document.getElementById("allxy").value;
	setCookie("mantar",mantar,1000);
	window.open("Default.aspx?S=1&R"+Math.random(),"_top");
}

function resetprofile()
{

var answer = confirm ("This will delete all your changes to the bingo area. Are you sure?")
if (answer)
{
	setCookie("mantar",defaultstr,1000);
	window.open("Default.aspx?S=1&R"+Math.random(),"_top");
}

}

function getmaindiv()
{
	if(winW>anaw)
		anax = parseInt((winW - anaw) / 2);
	else
		anax = 16;
		
	//alert("Anax " + anax + ": "+ anay)
}



function showprofile()
{
	var variable = "hidden";
	if(profileshow == false)
		{
		profileshow = true;
		
		obj = document.getElementById("LoadingProfile");
		obj.style.visibility = "visible";
		
		variable = "visible";
		obj = document.getElementById("hand2");
		obj.style.visibility = "visible";
		obj = document.getElementById("hand1");
		obj.style.visibility = "hidden";
		
		obj = document.getElementById("profilpictd");
		obj.className = 'prpic_open';
		


		}
	else
		{
		profileshow = false;
		variable = "hidden";
		
		obj = document.getElementById("hand1");
		obj.style.visibility = "visible";
		obj = document.getElementById("hand2");
		obj.style.visibility = "hidden";
		
		
		obj = document.getElementById("profilpictd");
		obj.className = 'prpic';
		

		
		}
		
		
		changecss("#anaDiv","visibility",variable);
		changecss("#anaDiv2","visibility",variable);
		
		var allcoord = document.getElementById("allxy").value;
		var mycoords = allcoord.split(",");
		for(i = 0 ; i < mycoords.length ; i++)
			{
				var coord = mycoords[i].split(":");
				var subid = parseInt(coord[0]);
				if(subid > 0)
				changecss("#apDiv"+subid,"visibility",variable);		
			}
	    
	    window.setTimeout (function () { 
	    obj = document.getElementById("LoadingProfile");
		obj.style.visibility = "hidden";
	    }, 1000);

}



function set(divid, e)
{
	if(!editmode)
	return;
	
	if (!e)
	var e = window.event;

	currentdiv = divid;
    //var s = 'X=' + window.event.clientX +  ' Y=' + window.event.clientY ;
	var obj = document.getElementById("apDiv"+divid);
	
	obj.style.borderWidth = "3px";
	obj.style.borderStyle = "dashed";
	obj.style.borderColor = "#fe137f";
	obj.style.cursor = "move";
	
	currentw = parseInt(obj.offsetWidth);
	currenth = parseInt(obj.offsetHeight);
	subx = parseInt(obj.offsetLeft);
	suby = parseInt(obj.offsetTop);
	difx = e.clientX - subx;
	dify = e.clientY - suby;

	maxzindex++;
	changecss("#apDiv"+divid,"z-index",maxzindex);

}

function SetValues(e)
{

	if (!e)
	var e = window.event;

	if(currentdiv != null)
		{	
			if(checkAvailable(e.clientX-difx, e.clientY-dify))
			{
			setPosition("apDiv"+currentdiv,"left",e.clientX-difx);
			setPosition("apDiv"+currentdiv,"top",e.clientY-dify);
			currentx = e.clientX-difx;
			currenty = e.clientY-dify;
			}
		}
	
	
	//var s = 'X=' + e.clientX +  ' Y=' + e.clientY ;
    //document.getElementById('divCoord').innerText = s;	
}  

function setPosition(divid, key, value)
{
	var obj = document.getElementById(divid);
	
	if(obj != null)
	{
	    if(key == "top")
	    {
	    obj.style.top = value+"px";
	    }
	    else if(key == "left")
	    {
	    obj.style.left = value+"px";
	    }
	}
	else
	{
	    alert("Obje Not Found : "+ divid);
	}
	//changecss(divid,key,value);
	
	//alert(divid + "-" + key + " - " + value);
}

function checkAvailable(x, y)
{
	anax1 = anax - 30;
	anax2 = anax + anaw - currentw + 30;
	anay1 = anay;
	anay2 = anay + anah - currenth + 30;
	
	if(x > anax1 && x < anax2 && y > anay1 && y < anay2)
		return true;
	
	return false;
}

function resetdiv()
{
	if(currentdiv == null)
		return;
	
	var obj = document.getElementById("apDiv"+currentdiv);
	obj.style.borderWidth = "0px";
	obj.style.cursor = "default";
	
	
	var allcoord = document.getElementById("allxy").value;
	var newcoord = "";
	var mycoords = allcoord.split(",");
	for(i = 0 ; i < mycoords.length ; i++)
		{
			var coord = mycoords[i].split(":");
			var subid = parseInt(coord[0]);
			if(subid == currentdiv)
			{
			
			var subx = parseInt(coord[1]);
			var suby = parseInt(coord[2]);
			var subvisible = parseInt(coord[3]);
			var subzindex = parseInt(coord[4]);
		
				newcoord = newcoord + subid + ":" + (currentx - anax) + ":" + (currenty - anay) + ":" + subvisible + ":" + maxzindex +","
	
			}
			else if (subid > 0)
			{
				newcoord = newcoord + mycoords[i]+","
			}
		
		}
	
	document.getElementById("allxy").value = newcoord;
	currentdiv = null;

}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}



function resize()
{
	
	if(document.getElementById("allxy") == null)
	return;
	
	if (parseInt(navigator.appVersion)>3) 
		{
		 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth;
		  winH = window.innerHeight;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  winW = document.body.offsetWidth;
		  winH = document.body.offsetHeight;
		 }
		}
	
	//alert("Window " + winW + ": "+ winH)
	
	getmaindiv();
	
	
	//check cookie
	var mantar = getCookie('mantar');
	if (mantar==null || mantar=="")
	{
		mantar = defaultstr;
	}
	
	document.getElementById("allxy").value = mantar;
	
	
	
	var allcoord = mantar;
	
	//var reply = prompt("Hey there, good looking stranger!  What's your name?", allcoord);

	
	var mycoords = allcoord.split(",");
	
	
	for(i = 0 ; i < mycoords.length ; i++)
		{
			var coord = mycoords[i].split(":");
			
			//alert(mycoords[i]);
			var subid = parseInt(coord[0]);
			//alert(subid);
			if (subid > 0)
			{
			var subx = parseInt(coord[1]);
			var suby = parseInt(coord[2]);
			var subvisible = parseInt(coord[3]);
			var subzindex = parseInt(coord[4]);
		
		
			if(subvisible == 0)
			changecss("#apDiv"+subid,"visibility","hidden");
			
			
			
			
			
			setPosition("apDiv"+subid,"left",subx + anax);
			
			setPosition("apDiv"+subid,"top",anay + suby);

			//alert(subx);
			changecss("#apDiv"+subid,"z-index",subzindex);
			
			if(maxzindex < subzindex)
				maxzindex = subzindex;
			}
		
		}
    window.setTimeout (function () { 
	    obj = document.getElementById("LoadingProfile");
	    if(obj != null)
		obj.style.visibility = "hidden";
	    }, 1000);
}


function changecountry(id)
{
url = "http://www.bingoconcierge.com";

if(id == 1)
    {
        url = "http://se.bingoconcierge.com";
    }
else if(id == 2)
    {
        url = "http://fr.bingoconcierge.com";
    }  
else if(id == 3)
    {
        url = "http://it.bingoconcierge.com";
    }
else if(id == 4)
    {
        url = "http://es.bingoconcierge.com";
    }  
else if(id == 5)
    {
        url = "http://pt.bingoconcierge.com";
    } 
else if(id == 6)
    {
        url = "http://nl.bingoconcierge.com";
    }  
    
window.open(url,"_top");
    
}
