// JavaScript Document
$(function() {

	/*CONTACT FORM*/
	$(".send-contact-email").livequery(function(){
		$(".send-contact-email").click(function(e) {
			e.preventDefault();
			var $this = $(this);
			//var type;
			var type = $this.attr("id").replace(/^send-/,'');
			//console.log(type);
			var selectval = $("#"+type+"-team .field_subject").fieldValue();
			//console.log(selectval[0]);
			$("#email-feedback").load("/include/sendemail.php",
				{
					type: type,
					name : $("#"+type+"-team .field_name").val(),
					email: $("#"+type+"-team .field_email").val(),
					email_confirm: $("#"+type+"-team .field_email_confirm").val(),
					alias: $("#"+type+"-team .field_alias").val(),
					querytype: selectval[0],
					query: $("#"+type+"-team .field_message").val(),
					refer: $("#"+type+"-team .refer").val(),
					sitename: $("#"+type+"-team .sitename").val()
				}
			);
			$("#email-forms").empty();
		});
	});
	
});

function playRoom(iRoomID)
{
    playWin = window.open("/skin/play.php?room=" + iRoomID, "playWin", "height="+screen.height-2+",width="+screen.width-2+",screenY=1,screenX=1,resizable");
}


/* Timed Content
---------------------------*/


function getTime()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
return weekday[d.getDay()];
}

function timed(dir,div,override,includepath,playerClass,url)
{
	var urlmatch, path;

 	urlmatch = url.search("main.php");
	//if (urlmatch==1) path= '/include/timed/';	//there is a match
	//else
	path = '/include/timed/';
	/*if (jQuery.browser.mozilla) console.log("ajax call: "+path+"timed_function.php?day="+today+"&dir="+dir+"&includepath="+includepath+"&playerClass="+playerClass);*/
	//alert(dir);
	var today;
	if (override=="")today = getTime();
	else today = override;

	$(div).load(path+"timed_function.php?day="+today+"&dir="+dir+"&includepath="+includepath+"&playerClass="+playerClass);

}

/* Display Calendar Picker
-----------------------------------*/
	function formSubmitIntercept(sender, event){
		if (event && event.keyCode == 13) {
		datePickerClosed(sender);
		return false;
		}
	}
	function datePickerClosed(dateField){
		(valDate(dateField));
		go(dateField.attributes["formAction"].value,false);			
	} 
	function GameDetail(gameID){
			document.mainForm.gameID.value = gameID;
			go('MYGAMEDETAIL', false, 'mygamesdetail.php');
	}

/* Launch Game to specific tabs
-----------------------------------*/
function launchGame(iRoom,loc,tab,dl) {
        var bGameOpen = false;
        //debugger
        loc = "/skin/play.php";
        if(dl) loc += "?tab=" + tab + "&DL=" + dl + "&cachebuster=" + (Math.random()+'');
        else   loc += "?tab=" + tab + "&cache=" + (Math.random()+'');

        // check if game window already open
        try
        {
          var oTest = playWin.document;
          if (oTest != null)	bGameOpen = true;
                }
        catch(ee)
                {
                bGameOpen = false;
                }

        if (!bGameOpen)
                {
                        h=(screen.height*.9)-54
                        w=(screen.width*.9)

                        if (navigator.appName.indexOf("Microsoft") != -1)
                        {
                                playWin = window.open(loc, "playWin", "height="+h+",width="+w+",top=1,left=1,resizable");
                        }
                        else
                        {
                                playWin = window.open(loc, "playWin", "height="+screen.height-2+",width="+screen.width-2+",screenY=1,screenX=1,resizable");
                }
                playWin.focus();
        }
  else
        {
                playWin.focus();
        }
}

/* Curfon fonts declarations 
---------------------------------*/
Cufon.DOM.ready(function() {
	Cufon.replace([ ' .sub-header, .content h1, .content h2, #loginjoin h2, #loginjoin h3, h2#hdh_login, h2#hdg_login, #left_content h1, #members_balance h3, #members_banking h3, h3#history, #protected_loginform h1, p#or' ]); 
});




