function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function changeImages() {
	if (document.images ) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


function changeMenu(item){
	item = document.getElementById(item);
	if (item.style.display == 'none' || item.style.display == '' ){
		item.style.display = 'block';
	} else {
		item.style.display = 'none';
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		menu01over = newImage("images/menu01o.gif");
		menu02over = newImage("images/menu02o.gif");
		menu03over = newImage("images/menu03o.gif");
		menu04over = newImage("images/menu04o.gif");
		menu05over = newImage("images/menu05o.gif");
		menu06over = newImage("images/menu06o.gif");
		menu07over = newImage("images/menu07o.gif");
		menu08over = newImage("images/menu08o.gif");
		preloadFlag = true;
	}
}

function focusError(item){
	item.focus();
	item.style.background='#FF0000';
	setTimeout("focusErrorDo(document.getElementById('" + item.id + "'))", 2000);
}


function focusErrorDo(item){
	item.style.background='';
}

function toggleLoading(st){
	if ( st == 1 ){
		document.getElementById('loadingHolder').style.display = "block";
		document.getElementById('loadingHolder').focus();
	} else {
		document.getElementById('loadingHolder').style.display = "none";
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){ return false; }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
	if (str.indexOf(at,(lat+1))!=-1){ return false; }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
	if (str.indexOf(dot,(lat+2))==-1){ return false; }
	if (str.indexOf(" ")!=-1){ return false; }
	return true;			
}
function containTurkishCharacter(str){
   //var tCharacs=['ç','ğ','ı','ö','ş','ü','Ç','Ğ','İ','Ö','Ş','Ü'];
   var tCharacs=['\u0130','\u0131','\u00D6','\u00F6','\u00DC'
       ,'\u00FC','\u00C7','\u00E7','\u011E','\u011F','\u015E','\u015F'];
   
   for(c in tCharacs){
       if(str.indexOf(tCharacs[c])!=-1){
	   return true;
       }
   }
   return false;
}
function focusError(item){
	item.focus();
	item.style.background='#FF0000';
	setTimeout("focusErrorDo(document.getElementById('" + item.id + "'))", 2000);
}

function focusErrorDo(item){
	item.style.background='';
}

function changeTab(i){
	switch (i) {
		case 0:
			document.getElementById('tab01_content').style.display = "block";
			document.getElementById('tab01').style.backgroundImage = "url(images/tabbg01.gif)";
			document.getElementById('tab02_content').style.display = "none";
			document.getElementById('tab02').style.backgroundImage = "url(images/tabbg02.gif)";
		break;
		case 1:
			document.getElementById('tab01_content').style.display = "none";
			document.getElementById('tab01').style.backgroundImage = "url(images/tabbg02.gif)";
			document.getElementById('tab02_content').style.display = "block";
			document.getElementById('tab02').style.backgroundImage = "url(images/tabbg01.gif)";
		break;
	}
}

function checkUsername(){
	var usern = document.getElementById('usernameID').value; 
	if ( usern.length > 3 && usern.length < 15 ) {
		xmlHttp = GetXmlHttpObject();
		if ( xmlHttp == null )
		{
			alert ("Browser does not support HTTP Request");
			return;
		} else {
			var url="engine/checkUsername.php";
			url=url+"?q="+usern;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange=function () {
				if ( xmlHttp.readyState==1 ){
					document.getElementById('registerResult').innerHTML = '<font color="blue">&nbsp;&nbsp;Kontrol ediliyor...</font>';
				}
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{
					if ( xmlHttp.responseText == "false" ){
						document.getElementById('registerResult').innerHTML = '<font color="red">&nbsp;&nbsp;Biri ismini çalmış !</font>';
						document.getElementById('nameErrorID').value = true;
					} else if ( xmlHttp.responseText == "short" ) {
						document.getElementById('registerResult').innerHTML = '<font color="red">&nbsp;&nbsp;isim cok kisa! <3</font>';     
						document.getElementById('nameErrorID').value = true;
					} else if ( xmlHttp.responseText == "bad" ) {
						document.getElementById('registerResult').innerHTML = '<font color="red">&nbsp;&nbsp;İsim gecersiz!</font>';
						document.getElementById('nameErrorID').value = true;
					} else {
						document.getElementById('registerResult').innerHTML = '<font color="green">&nbsp;&nbsp;Tamam !</font>';
						document.getElementById('nameErrorID').value = false;
						showRegister2();
					}
				}
			}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
		return;
	} else {
		document.getElementById('registerResult').innerHTML = '';
		return false;
	}
}


function checkEmail(){
	var email = document.getElementById('emailID').value; 
	if ( email.length > 4 && email.length < 256 ) {
		xmlHttpEmail = GetXmlHttpObject();
		if ( xmlHttpEmail == null )
		{
			alert ("Browser does not support HTTP Request");
			return;
		} else {
			var url="engine/checkEmail.php";
			url=url+"?q="+email;
			url=url+"&sid="+Math.random();
			xmlHttpEmail.onreadystatechange=function () {
				if ( xmlHttpEmail.readyState==1 ){
					document.getElementById('registerResultEmail').innerHTML = '<font color="blue">&nbsp;&nbsp;Kontrol ediliyor...</font>';
				}
				if (xmlHttpEmail.readyState==4 || xmlHttpEmail.readyState=="complete")
				{
					if ( xmlHttpEmail.responseText == "false" ){
						document.getElementById('registerResultEmail').innerHTML = '<font color="red">&nbsp;&nbsp;E-mail adresi kayıtlı !</font>';
						document.getElementById('emailErrorID').value = true;
					} else if ( xmlHttpEmail.responseText == "short" ) {
						document.getElementById('registerResultEmail').innerHTML = '<font color="red">&nbsp;&nbsp;E-mail çok kısa! <3</font>';     
						document.getElementById('emailErrorID').value = true;
					} else if ( xmlHttpEmail.responseText == "bad" ) {
						document.getElementById('registerResultEmail').innerHTML = '<font color="red">&nbsp;&nbsp;E-mail geçersiz!</font>';
						document.getElementById('emailErrorID').value = true;
					} else {
						document.getElementById('registerResultEmail').innerHTML = '<font color="green">&nbsp;&nbsp;E-mail geçerli.</font>';
						document.getElementById('emailErrorID').value = false;
						showRegister2();
					}
				}
			}
			xmlHttpEmail.open("GET",url,true);
			xmlHttpEmail.send(null);
		}
		return;
	} else {
		document.getElementById('registerResultEmail').innerHTML = '';
		return false;
	}
}


function setAvatar(id){
	xmlHttp = GetXmlHttpObject();
	if ( xmlHttp == null )
	{
		alert ("Browser does not support HTTP Request");
		return;
	} else {
		var url="engine/setavatar.php";
		url += "?i="+id;
		url += "&sid="+Math.random();
		xmlHttp.onreadystatechange=function () { 
			if ( xmlHttp.readyState==1 ){
				toggleLoading(1);
			}
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				if ( xmlHttp.responseText == "true" || xmlHttp.responseText == "open" || xmlHttp.responseText == "close" ){
					var cc = 1;
					while ( document.getElementById('avatar'+cc) == null ? false:true ){
						if ( id == cc && xmlHttp.responseText != "close"){
							document.getElementById('avatar'+cc+'color').value = '#9FCFFF';
							document.getElementById('avatar'+cc).style.background = '#9FCFFF';
						} else {
							document.getElementById('avatar'+cc+'color').value = '#e4e7ef';
							document.getElementById('avatar'+cc).style.background = '#e4e7ef';
						}
						cc++;
					}
				} else {
					alert("Hata:"+xmlHttp.responseText);
				}
				toggleLoading(0);
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function openGameWin(gameid,salon){
	resWidth = 980;//980 defaultW
	resHeight = 680;//680 defaultH
	nRandom = Math.random().toString().split(".")[1];
	opened = window.open('games/gamewin.php?id='+gameid+'&salon='+salon, 'gamewin','toolbar=0,location=0,hotkeys=0,directories=0,status=no,menubar=0,left='+((screen.width / 2) - (resWidth / 2))+',top='+((screen.height / 2) - (resHeight / 2))+',screenX=0,screenY=0,scrollbars=no,resizable=0,hotkeys=0,titlebar=0,width='+resWidth+',height='+resHeight+'');
	opened.focus();
}

function gamePanel(id){
	var i = genRand();
	var a = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="983" height="686" id="game_'+id+'" align="middle">';
	a += '<param name="allowScriptAccess" value="always" />';
	a += '<param name="allowNetworking" value="all" />';
	a += '<param name="movie" value="flash/game_'+id+'.swf?r='+i+'" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#E6E6E6" /><embed src="flash/game_'+id+'.swf?r='+i+'" allowNetworking="all" quality="high" bgcolor="#E6E6E6" width="983" height="686" name="game_'+id+'" menu="false" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	a += '</object>';
	document.write(a);
}

function Salon(){
	var i = genRand();
	var a = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="700" height="600" id="salonlar" align="middle">';
	a += '<param name="allowScriptAccess" value="sameDomain" />';
	a += '<param name="movie" value="games/flash/salonlar.swf?r='+i+'" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="games/flash/salonlar.swf?r='+i+'" quality="high" bgcolor="#ffffff" width="700" height="600" name="salonlar" align="middle" allowScriptAccess="sameDomain" menu="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	a += '</object>';
	document.write(a);
}

function onCloser(){
	return false;
}

function shake(){
	window.focus();
}

function genRand(){
	var i = Math.round(100000000*Math.random());
	return i;
}


function setInfo(info) {
    //alert(info);
    //var app = document.getElementById("Saloons");
    //app.script.setInfo(info);
    //document.applets[0].setInfo();
    //app.script.testFunc();

    var applet = document.getElementById("Saloons");
    applet.script.setInfo(info);

}



function deneme(){
	//alert("deneme called");
	xmlHttp = GetXmlHttpObject();
	if ( xmlHttp == null )
	{
		alert ("Browser does not support HTTP Request");
		return;
	} else {
		var url="/info.php";
		xmlHttp.onreadystatechange=function () {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				setInfo(xmlHttp.responseText);
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	return;


//return getCookie('ABSESSION');

}

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 "";
}


