

// javascript
// Author Simon Hobbs
// used by the index page of spinroom and skins (called by pages derived from normalPage.dwt)
//

// openGameHelp: Simon Hobbs: used by games.html to open the chartwell games help in a window
// needs to be changed to handle skinning.
function openGameHelp(helpPage) {
	if (helpPage !="")
		{dummy = window.open("http://games.thespinroom.com/spinroom/help/en/" + helpPage,"POP_HELP","scrollbars=yes,width=450,height=500");
		dummy.focus();
		}
}

// login from form and popup result in a new window.
		function login(fm) {
			var domain = document.domain + ""; //Don't want to refer to the actual document.domain
			var path="/SpinroomCAPI/jsp/login_do.jsp";
			fm.action="https://" + domain + path;
			
			var w = 480, h = 340;

			if (document.all || document.layers) {
			   w = screen.availWidth;
			   h = screen.availHeight;
			}
			
			var popW = 685, popH = 415;
	 		var leftPos = (w-popW)/2, topPos = (h-popH)/2;
            var gamewin = window.open('','GAMEMENU','resizable,scrollbars,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
			fm.target="GAMEMENU";
            var OID = getCookie("OIDTracker");
            if (OID != null) {
			   fm.oid.value = OID;
			}
			
			gamewin.focus();
	    // reset stops it working.
    	//			fm.reset()
			var cmd = "clearLoginBoxes()";
			setTimeout(cmd,20000);
		}

// clears the login boxes after a login attempt
function clearLoginBoxes () {
	if (document.forms['LOGIN']) {
		document.forms['LOGIN'].username.value="";
		document.forms['LOGIN'].password.value="";
	}
}

function do_forgotPassword(){
			var w = 480, h = 340;

			if (document.all || document.layers) {
			   w = screen.availWidth;
			   h = screen.availHeight;
			}
			
			var popW = 750, popH = 520;
			var leftPos = (w-popW)/2, topPos = (h-popH)/2;
            var forgotwin = window.open('/SpinroomCAPI/jsp/forgotpassword.jsp','GAMEMENU','resizable,scrollbars,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
//			var forgotwin = window.open('/SpinroomCAPI/jsp/forgotpassword.jsp','new_one',"status,menubar,resizable");
//			fm.REFERRER.value=top.referrer;
			forgotwin.focus();


}

		function register() {
			var w = 480, h = 340;

			if (document.all || document.layers) {
			   w = screen.availWidth;
			   h = screen.availHeight;
			}
			
			var popW = 750, popH = 500;
			var leftPos = (w-popW)/2, topPos = (h-popH)/2;
			var registerwin = window.open("/SpinroomCAPI/jsp/reg_createaccount.jsp","BANKWINDOW","resizable,scrollbars, width=" + popW + ", height=" + popH + ", top=" + topPos + ", left=" + leftPos + " ");
			
			//var registerwin = window.open('http://londontest:8080/servlet/spinroom2?skin=rpc&l=1&site=spinroom&lg=guest&locale=&dateformat=&playmode=&skin=rpc&p=sr_createaccount','new_one','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
			registerwin.focus();
		}

// SWH: grab the referrer the first time called only!
function storeREFERRER() {

  if (getCookie("REFERRERTracker") == null) {
    if (document.referrer) {
      setCookie("REFERRERTracker", document.referrer, "", "", "", false);
    }
  }
} // storeREFERER()

// SWH: this should be called on the onLoad() of every page to set the cookies.
function storeInfo() {
  storeTracking();
  storeREFERRER();
  
}  // storeInfo()

function chartwellSkin() {
	document.write("original2");
}

function name() {
	document.write("The Spin Room");
}

// Gets a parameter from the url. If two values are the same
// Only return the first one
function getParameter(parameter) {
	if (location.search != "") {
		// key / values pairs are seperated by &
		var params = location.search.substr(1).split("&")        
		for (var i=0; i<params.length; i++) {
			// paramHash[0] will contain the key
			// paramHash[1] will contain the value
			var paramHash = params[i].split("=");
			if (paramHash[0] == parameter) {
				return paramHash[1];
			}
		}
		//We didn't find any parameter with this value
		return null;
	}
}  // getParameter()

//function to store the origin id or the banner tag
function storeTracking() {
	var OID = getParameter("OID");
	var bTagId = getParameter("btagid");
	if (OID != null) {
		setCookie("OIDTracker", OID, "", "", "", false);
	}
	if (bTagId != null) {
		//miliseconds * second * minutes * hours * days
		var timeToLive =1000*60*60*24*45;
		var now = new Date().getTime();
		var expirationTime = now + timeToLive;
		var expirationDate = new Date()
		expirationDate.setTime(expirationTime);
		setCookie("BTAGTracker", bTagId, expirationDate, "", "", false);
	}
}  // storeTracking()