// Globals
var langs = Array();
langs["us_en"]= "en_us";
langs["br_pr"]= "pt_br";
langs["de_de"]= "de_de";
langs["es_es"]= "es_es";
langs["fr_fr"]= "fr_fr";
langs["it_it"]= "it_it";
langs["jp_jp"]= "jp_jp";
langs["nl_nl"]= "nl_nl";
langs["se_se"]= "se_se";
langs["zh_cn"]= "zh_cn";
langs["zh_tw"]= "zh_tw";

function readLocaleCookie(name){
	var nameEQ=name+"=";
	var value;
	var ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		while(c.charAt(0)==' ')
			c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0)
			value=c.substring(nameEQ.length,c.length);
	}

	if (value == undefined){
		//value =  getPWD();
		var location = window.location.href;
		var location_array = location.split("/");
		location_array.reverse();
		value = location_array[1];
		// alert("getting cookie: value["+value+"]");
	}

	return value;
}

//offloadUrl = 'http://dt.sandbox.webkinz.com/'+readLocaleCookie('webkinzLocaleCookie')+'/';
//offloadUrl = 'http://dt.sandbox.webkinz.com/fr_fr/';
// LIVE URL
 offloadUrl = 'http://customerservice.webkinz.com/collectionscatalog/'+readLocaleCookie('webkinzLocaleCookie')+'/';


/**
 * Login or new member popup  screen
 * Last Modified: Konstantin Glazov, Ehsanul, Igor
 */
function pW(page) {
	var url = "http://" + getURL() + "/";
	// if it not be able to find /release/ patern,
	// then it will make an attempt to replase dev with register

    url = url.replace(/release/, "register");
    url = url.replace(/dev/, "register");
    url = url.replace(/backyard/, "register31");
    // temp fix
    url = "http://mci2.webkinz.com";
    if(screen.height == 768)
    {
   		if(navigator.userAgent.toLowerCase().indexOf('aol')>0 && navigator.userAgent.toLowerCase().indexOf('netscape')<0) {
    		window.open(url+"/loader4.php?go="+page+"&aol=1&fs=0", "webkinz", "height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0,fullscreen=yes");
   		} else  {
    		window.open(url+"/loader4.php?go="+page+"&aol=0&fs=1", "webkinz", "height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0,fullscreen=yes");
   		}
  	} else {
   		window.open(url+"/loader4.php?go="+page+"&aol=0&fs=0", "webkinz", "left="+(screen.width-1000)/2+",top="+(screen.height-680)/2+",height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0");
  	}
}

// natalia roque

function pWFree(page) {
	var url = "http://" + getURL() + "/";
	// if it not be able to find /release/ patern,
	// then it will make an attempt to replase dev with register
    url = url.replace(/release/, "register");
    url = url.replace(/dev/, "register");
   // url = url.replace(/backyard/, "register31");
    // temp fix
    var url = "http://register.webkinzdemo.com/";

    if(screen.height == 768)
    {
   		if(navigator.userAgent.toLowerCase().indexOf('aol')>0 && navigator.userAgent.toLowerCase().indexOf('netscape')<0) {
    		window.open(url+"loader4.php?go="+page+"&aol=1&fs=0", "webkinz", "height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0,fullscreen=yes");
   		} else  {
    		window.open(url+"loader4.php?go="+page+"&aol=0&fs=1", "webkinz", "height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0,fullscreen=yes");
   		}
  	} else {
   		window.open(url+"loader4.php?go="+page+"&aol=0&fs=0", "webkinz", "left="+(screen.width-1000)/2+",top="+(screen.height-680)/2+",height=680,width=1000,toolbar=0,titlebar=1,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0");
  	}
}




/**
 * popup box that show tour, the url value must be hardcoded
 */
function pWTour() {
    var url = "http://www.webkinz.com/";
    window.open( url + "SWF/TOUR/siteTour.html", "webkinztour", "left="+(screen.width-750)/2+",top="+(screen.height-500)/2+",height=500,width=750,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0");
}

function internationalDistributors() {
  	//window.open(url, "idl","left="+(screen.width-640)/2+",top="+(screen.height-484)/2+",height=484,width=640,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0");
  	//var lang  = ReadCookie('webkinzLocaleCookie');
	//if(typeof lang != 'string') var lang = 'us_en';
  	//var url = "http://" +getURL()+"/idl/?lang="+langs[lang];
  	var url = "http://mci2.webkinz.com/idl/" + readLocaleCookie('webkinzLocaleCookie') + "/";
  	window.open(url, "idl","left="+(screen.width-640)/2+",top="+(screen.height-484)/2+",height=484,width=640,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=0,resizable=0");
}

function visitWebkinzeStore() {
	var lang  = ReadCookie('webkinzLocaleCookie');
	if(typeof lang != 'string' || lang.length != 5) var lang = 'us_en';
	//var url = "http://" +getURL()+"/leavingWebkinz.php?lang="+langs[lang];
    var url = "http://mci2.webkinz.com/leavingWebkinz.php?lang="+langs[lang];
    fullScreen(url);
}

function renewalinfo() {
	window.open("renewal_information.html", "ri","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=800,width=817,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function policy() {
   	window.open("privacy.html", "privacy", "left="+(screen.width-550)/2+",top="+(screen.height-600)/2+",height=600,width=550,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function terms() {
   	window.open("terms.html", "terms", "left="+(screen.width-750)/2+",top="+(screen.height-600)/2+",height=600,width=750,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function ownership() {
   	window.open("terms.html", "terms", "left="+(screen.width-750)/2+",top="+(screen.height-600)/2+",height=600,width=750,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function contactUs() {
   	window.open("contact.html", "contactus", "left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=800,width=817,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function webkinz_day() {
   	window.open("webkinz_day.html", "webkinz_day","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=600,width=700,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function dicekinz_faq() {
   	window.open("dicekinz_faq.html", "dicekinz_faq","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=800,width=817,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function magicWInfo() {
   	window.open("webkinzW.html", "WebkinzW","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=800,width=817,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function faq() {
   	window.open("faq/index.html", "faq","left="+(screen.width-817)/2+",top="+(screen.height-620)/2+",height=620,width=817,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function launch1024() {
   	window.open("launch1024.html", "launch1024","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=800,width=725,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
}

function contactUsRetail() {
//   	window.open("http://www.ganz.com/contact/rep_contact.html", "contactusretail","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=600,width=670,toolbar=0,titlebar=0,location=50,status=0,directories=0,menubar=0,scrollbars=1,resizable=1");
window.open(offloadUrl+"product_lines.html", "storelocator","left="+(screen.width-640)/2+",top="+(screen.height-484)/2+",height=484,width=657,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=0");
}

function storelocator() {
  	window.open(offloadUrl+"product_lines.html", "storelocator","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=593,width=670,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=0");
}

function catalog() {
  	//window.open(offloadUrl+"index.html", "collectionscatalogtest","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=593,width=670,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=0");
    window.open(offloadUrl+"index.html", "collectionscatalogtest","left="+(screen.width-817)/2+",top="+(screen.height-800)/2+",height=593,width=720,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=0");
}

function issue() {
   	window.open("regissue.html", "issues", "left="+(screen.width-550)/2+",top="+(screen.height-600)/2+",height=600,width=550,toolbar=0,titlebar=0,location=0,status=0,directories=0,menubar=0,status=0,directories=0,menubar=0,scrollbars=1,resizable=0");
}


/**
 * Return url
 * author: Konstantin Glazov
 */
function getURL() {
    var location = window.location.href;
	var location_array = location.split("/");
	return location_array[2];
}

/*
function pT() {
  	if(screen.width == 800 && screen.height == 600)  {
   		if(navigator.userAgent.toLowerCase().indexOf('aol')<1)  {
    		document.getElementById('results').innerHTML = "Your browser is set to 800 by 600 resoltuion, website will open in fullscreen mode<br>";
   		}
  	}
}
*/
function pT() {
  	if(screen.width == 1000 && screen.height == 680) {
   		if(navigator.userAgent.toLowerCase().indexOf('aol')<1)  {
    		document.getElementById('results').innerHTML = "Your browser is set to 1000 by 680 resoltuion, website will open in fullscreen mode<br>";
   		}
  	}
}

function ReadCookie(cookieName) {
	var theCookie = ""+ document.cookie;
	var ind = theCookie.indexOf(cookieName);
	if (ind == -1 || cookieName == "") return "";
	var ind1 = theCookie.indexOf(';',ind);
	if (ind1 == -1) ind1 = theCookie.length;
	return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function SetCookie(cookieName,cookieValue,nDays) {
	 var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, scrollbars=yes');
}
