/**
 * Static Class for namespace and functions
 */
var EEMEA = {
	registrationUrl: {
			test: 	{
				me: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				ru: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				za: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				cz: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				pl: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				hu: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				sk: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp"
			},
			stage: 	{
				me: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				ru: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				za: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				cz: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				pl: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				hu: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				sk: "http://compeu.stage.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp"
			},
			live: 	{
				me: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				ru: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				za: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				cz: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				pl: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				hu: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp",
				sk: "http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp"
			}
	},
	
	termsUrl: {
			me: "http://www.toshiba-europe.com/legal/index.html",
			ru: "http://www.toshiba.it/pc/russia/legal/index.htm",
			za: "http://www.toshiba-europe.com/legal/index.html",
			cz: "http://www.toshiba-czech.com/legal/index.html",
			pl: "http://www.toshiba.pl/legal/index.html",
			hu: "http://www.toshiba.hu/legal/index.html",
			sk: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?LNG=22&service=CE&ID=TERMS_OF_USE"
	},
	
	privacyPolicyUrl: {
			me: "http://gulf.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?service=AE&ID=PRIVACY_POLICY",
			ru: "http://ru.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?service=RU&ID=PRIVACY_POLICY",
			za: "http://gulf.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?service=AE&ID=PRIVACY_POLICY",
			cz: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?LNG=21&service=CE&ID=PRIVACY_POLICY",
			pl: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?LNG=23&service=CE&ID=PRIVACY_POLICY",
			hu: "http://www.toshiba.hu/privacy/index.html",
			sk: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?LNG=22&service=CE&ID=PRIVACY_POLICY"
	},
	
	logoUrl: {
		me: "http://gulf.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/jsp/home.do?service=AE&from=http%3A//www.toshiba-gulf.com/site/",
		ru: "http://ru.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/news_article.jsp?service=RU&ID=CallCentre",
		za: "http://gulf.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/jsp/home.do?service=AE&from=http%3A//www.toshiba-gulf.com/site/",
		cz: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/jsp/home.do?service=CE&LNG=21",
		pl: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/jsp/home.do?service=CE&LNG=20",
		hu: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/csg_national_entry_page.jsp?service=CE&LNG=23",
		sk: "http://ce.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/jsp/home.do?service=CE&LNG=22"
	},
	
	flashMovie: "flash/toshiba_Q2_12e.swf",
	
	flashVersion: 8,
	
	popupWidth: screen.width,
	
	popupHeight: screen.height,
	
	flashMovieWidth: 995,
	
	flashMovieHeight: 700,
	
	isExternalCall: function() {
		var external = (location.href.match(/vista/)) ? true : false;
		return external;	
	},
	
	/**
	 * Creates a pop an focus if popupblocker not working
	 */
	openPopup: function(link, options) {
		var options = options || {};
		var width = options.width || this.popupWidth;
		var height = options.height || this.popupHeight;
		var scrollbars = options.scrollbars || "no"
		
		var w = window.open(link, options.name || "EEMEA", "width=" + width + ", height=" + height + ",locationbar=auto,menubar=no,status=no,resizable=no,scrollbars=" + options.scrollbars);
		
		if(w) w.focus();
	},
	
	getRegistrationUrl: function(language) {
		
		var state = true;
		var server = null;
		
		if (location.host.match(/10\.1\.42\.85/))
			server = "test";
		
		if (server == null)
			server = (location.host.match(/\.stage\./)) ? "stage" : "live";
		
		return this.registrationUrl[server][language];
	},
	
	getTermsUrl: function(language) {
		return this.termsUrl[language];
	},
	getPrivacyPolicyUrl: function(language) {
		return this.privacyPolicyUrl[language];
	},
	getLogoUrl: function(language) {
		return this.logoUrl[language];
	}
};

EEMEA.ClientInfo = Class.create();
EEMEA.ClientInfo.prototype = {
	
	_clientDefaultLanguage: "me",
	
	_clientLanguage: null,
	
	initialize: function(language) {
		this._clientLanguage = language;
	},
	
	getClientLanguage: function() {
		return this._clientLanguage;
	},
	
	/**
	 * @return String default language
	 */
	getClientDefaultLanguage: function() {
		return this._clientDefaultLanguage;
	}
}

function changeBckGrndColor(color) {
	document.body.style.backgroundColor='#'+color;
}

// wrapper functions
function openTermsOfUse(language) {
	var language = language || ClientInfo.getClientDefaultLanguage();
	//EEMEA.openPopup("EEMEA.getTermsUrl(language)", {width: 600, height: 400, scrollbars: "yes", name: "termsofuse"});
	return 	EEMEA.termsUrl[language];	
}

function openPrivacyPolicy(language) {
	var language = language || ClientInfo.getClientDefaultLanguage();
	//EEMEA.openPopup("/" + language + "/privacy_policy.html", {width: 600, height: 400, scrollbars: "yes", name: "privacypolicy"});
	return 	EEMEA.getTermsUrl(language);	
}

Event.observe(window, "load", function() {
	
	// use this only on startpage
	if ($("navigation")) {
		
		var so = new SWFObject("swf/test.swf", "so", "1", "1", EEMEA.flashVersion, "#ffffff");
		var hasFlash = so.installedVer.versionIsValid(so.getAttribute("version"));
		if (hasFlash) {
			Element.show("content");
		} else {
			Element.show("errorFlash");
		}
		
		
		var language = ClientInfo.getClientLanguage();
		var li = $(language);
		if (li) {
			var img = li.getElementsByTagName("img").item(0);
			img.src = decodeURIComponent(img.src).replace(/\[off\]/, "[on]");
			img._clicked = true;
			var link = li.getElementsByTagName("a").item(0).href;
			/*if (hasFlash && link) {
				window.setTimeout("EEMEA.openPopup('" + link + "')", 100);
			}*/
		}
		
		var images = $("navigation").getElementsByTagName("img");
		
		$A(images).each(function(element) {
			
			Event.observe(element, "mouseover", function(e) {
				if (!element._clicked) {
					element.src = decodeURIComponent(element.src).replace(/\[off\]/, "[on]");
				}
			}, false);
						
			Event.observe(element, "mouseout", function(e) {
				if (!element._clicked)
					element.src = decodeURIComponent(element.src).replace(/\[on\]/, "[off]");
			}, false);
			
			Event.observe(element, "click", function(e) {
				Event.stop(e);
				
				$A(images).each(function(element) {
					element.src = decodeURIComponent(element.src).replace(/\[on\]/, "[off]");
					element._clicked = false;
				});
				
				element._clicked = true;
				element.src = decodeURIComponent(element.src).replace(/\[off\]/, "[on]");
				
				var link = element.parentNode.href;
				if (hasFlash && link) {
					EEMEA.openPopup(link);
				}
				return false;
			}.bind(element), false);
		});
	}
});

