﻿
 function myRoom() 
 {
    // alert ('screen.width = ' + screen.width + ' screen.height = ' + screen.height); 
    playerLeft = (screen.width-994)/2;
    playerTop = (screen.height-770)/2;
    // alert ('playerLeft = ' + playerLeft + ' playerTop = ' + playerTop); 
    myRoomWindow = open('Controller.aspx', 'TOC', 'resizable=no, scrollbars=no, top=26, left=30, height=770, width=994');
    self.close ();
}

function closePopup() {
  window.close();
}

function popUp(filename,width,height) {
	popup=window.open(filename,"popup","height="+height+",width="+width+",top=0,left=0,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
}

function popUpNoScroll(filename,width,height) {
	popup2=window.open(filename,"popup2","height="+height+",width="+width+",top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
	popup2.focus();
}

function buyPopup(filename, width, height) {
	popup3=window.open("BuyPopUp.htm","popup3", "height=340,width=546,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=0");
}
function popUpTerms(filename,width,height) {
	popup2=window.open(filename,"popup2","height=800,width=800,top=0,left=0,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
	popup2.focus();
}
function popUpHelp(filename,width,height) {
	popup2=window.open(filename,"help","height=300,width=400,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
	popup2.focus();
}

function popUpGame(filename,width,height) {
    popupG=window.open(filename,"popupG","height="+height+",width="+width+",top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
    if(navigator.vendor){
        // Browser is Safari
	    popupG.resizeTo(width,height+23);
    }else{
	    var ff = navigator.userAgent.indexOf('Firefox');
	    var vista = navigator.userAgent.indexOf('Windows NT 6');
	    var mac = navigator.platform.indexOf('Mac');
	    if (window.XMLHttpRequest &&  ff == -1){
	        // Browser is IE7                                    
		    popupG.resizeTo(width+10,height+81);
	    }else{
		    if(ff > 0){ 
		        // Browser is Firefox
		    	if(vista > 0){
		    		// OS is Vista
		    		popupG.resizeTo(width+6,height+47);
		    	}else{
		    		if(mac > -1){
		    		    // OS X
		    			popupG.resizeTo(width,height+15);
		    		}else{
		    		    // OS is XP
		    		   	popupG.resizeTo(width+6,height+55);
		    		}
				}
		    }else{ 
		        // Browser is IE6
		    	popupG.resizeTo(width+10,height+59);
		    }
	    }
    }
}


function GetCookie(sName)
{
    if (!document.cookie)
		return;
		
    var index = document.cookie.indexOf( sName + "=" );
	if (index == -1)
		return;
	
    var countbegin = (document.cookie.indexOf( "=", index ) + 1);
    var sValue = "";
    if ( 0 < countbegin )
    {
        var countend = document.cookie.indexOf( ";", countbegin );

        if ( countend < 0 )
            countend = document.cookie.length;

        sValue = document.cookie.substring( countbegin, countend );
    }

    return sValue;
}

function buyPopup(filename, width, height) {
	popup3=window.open("BuyPopUp.htm","popup3", "height=420,width=560,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
 }
 function tourPopup(filename, width, height) {
	popup4=window.open("TourPopUp.htm","popup4", "height=400,width=467,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
 }
 
function flashMovie(name) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[name];
	}
	else {
		return document[name];
	}
}

function onPointsUpdate() {
	flashMovie('ePetsFlash').onPointsUpdate();
}

function onGamePointsUpdate() {
//document.write('Suicide Notification');
window.opener.onPointsUpdate();
}

var hap = '';
var hea = '';
var hun = '';

//allow flash to update the meters values whenever they change... to use on session close
function setMeters(percent_happy,percent_heathly,percent_hungry) {
	hap = percent_happy;
	hea = percent_heathly;
	hun = percent_hungry;
}

var mypage_changes = false;

//allow flash to set flag that user has made mypage changes (blocking the meter change of having made no changes in a session)

function setFlagMyPageChanges() {
            mypage_changes = true;
}

var mypage_pals_added = false;

//allow flash to set flag that user has added pals (blocking the meter change of having added no pals in a session)

function setFlagMyPagePalsAdded() {
            mypage_pals_added = true;
}

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject();

function manageSessionClose() {
    /*if (!mypage_changes) {
        hap = hap - 2;
        hea = hea - 2;
        hun = hun - 4;
    }

    if (!mypage_pals_added){
        hap = hap - 2;
        hea = hea - 2;
        hun = hun - 2;
    }
	*/
	//alert("happy, healthy, hungry = ("+hap+","+hea+","+hun+")");
	
	var save_meters_url =  'http://' + domainName + "/WebServices/general.asmx/SaveUserMeterValuesUsingJonathansWay?keyCode="+keycode+"&happyMeter="+hap+"&healthyMeter="+hea+"&hungryMeter="+hun;
	http.open('get', save_meters_url);
	
	if (navigator.appName=="Microsoft Internet Explorer"){
	    http.onreadystatechange = new Function(onMetersSent());
	}
	else{
	    http.onreadystatechange = onMetersSent();
    	}
	
	http.send(null);

}

function onMetersSent() {
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		
	}
}

function pauseVideo() {
    flashMovie('home_theater').pauseVideo();
}

function registerAnother(){
    window.opener.location = "RegisterNewPet.aspx";
    self.close ();
}

function controllerLaunch(url){
    popupController=window.open(url,"popupController","height=694,width=1007,top=0,left=0,resizable=no,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=0");
}

function launchCertificate(kc, sn){
    popUpNoScroll("PrintCertificate.aspx?code=" + kc + "&pn=" + sn ,"792","611");
}

function launchPlaque(kc, sn){
    popUpNoScroll("PrintAwardPlaque.aspx?code=" + kc + "&pn=" + sn ,"595","458");
}

function doPrint(){
    if (document.all){
        document.getElementById('voiceoverFinalInfo').style.display = 'none';
        window.print();
        document.getElementById('voiceoverFinalInfo').style.display = 'block';
    }else{
        window.print();
    }
}