﻿function checkBrowser() { var value = navigator.userAgent; return value; }
// Browsers detection ////////////////////////
var is_ie = ((navigator.appVersion.match(/\bMSIE\b/))?true:false);
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var is_ie6 =(rslt != null && (Number(rslt[1]) < 7));
var is_ie7 =(rslt != null && (Number(rslt[1]) >= 7));
var is_safari = ((navigator.appVersion.match(/\bSafari\b/))?true:false);
var is_firefox = ((navigator.userAgent.toLowerCase().match(/\bfirefox\b/))?true:false);
// Mobile device detection ///////////////////
is_mobile = false;
var mobile_keywords = new Array("iPod", "iPhone", "Windows CE", "PalmOS", "Symbian OS", "PSP", "IEMobile", "Opera Mini", "MIDP", "embedix", "EPOC", "PalmSource", "Android");
for(var i=0;i<mobile_keywords.length;i++)
	if(navigator.userAgent.toLowerCase().indexOf(mobile_keywords[i].toLowerCase())>=0) is_mobile = true;	
//////////////////////////////////////////////

function isIn(string, array){
	for(var i=0;i<array.length;i++){
		if(	array[i] == string) return true;
	}
	return false;
}

// A FIXER
function fix_url(){
	var removeFromUrl = new Array('page', 'f_collection', 'f_type', 'f_product', 'strCountry_adidascom', 'culture');
	var url = window.location.toString();
	var correct_url;
	if(url.indexOf("/culture=")>0){
		correct_url = url.replace(/\/culture=/, "&culture=");
		document.location = correct_url;
		return true;
	}
	if(url.indexOf("?")>0){
		var vars = url.substr(url.indexOf("?")+1).split("&");
		var sharp_url = "";
		for(var j=0;j<vars.length;j++){
			var var_tmp = vars[j].split("=");
			if(!isIn(var_tmp[0], removeFromUrl)) sharp_url +=  var_tmp[1] + "/";
		}
		if(url.indexOf("Default.asp?") >= 0)
			correct_url = url.substring(0, url.indexOf("Default.asp?")) + "#/" + sharp_url;
		else
			correct_url = url.substring(0, url.indexOf("?")) + "#/" + sharp_url;
		document.location = correct_url;
		return true;
	}
}

function OpenURL(_url){
	window.open(_url, "popup", 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) return window[movieName];
    else return document[movieName];
}

if(!is_mobile)
{
	var _l = window.location.toString();
	var _base = (_l.indexOf("#") == -1) ? _l.substr(0, _l.lastIndexOf("/")+1) : _l.substr(0, _l.lastIndexOf("/#")+1);
	
	if(!DetectFlashVer(9,0,115)) document.location = "noflash.asp";
	fix_url();
	setCss();

}

function resizer(){

	document.getElementById("content").style.height = (Math.max(600, document.documentElement.clientHeight) - 90) + "px";
	document.getElementById("content").style.width = (Math.max(995, document.documentElement.clientWidth)) + "px";

}

window.onresize = function() { 

	if(!is_mobile){
		setTimeout("resizer();", 200);
	}
};

function setCss(){
	if(!is_mobile){
		jQuery().ready(function(){
			var header = document.getElementById("header");	
			var content = document.getElementById("content");	
			var footer = document.getElementById("footer");	
			
			/* Adapte CSS for flash*/

			if(content != null){
				content.style.position = "relative";
				content.style.height = (Math.max(600, document.documentElement.clientHeight) - 90) + "px";
				content.style.width = "100%";	
				content.style.minHeight = "512px";	
				content.style.minWidth = "995px";	
				footer.style.position = "absolute";
			}

		});	
	}
}


function setCookie(name, value, expires){
	// expires unit : day
	if(expires != null){
		var date = new Date();
		date.setTime(date.getTime()+(expires*24*60*60*1000));
		expires = "; expires=" + date.toGMTString();
	} else expires = "";
	document.cookie = name + "=" + escape(value) + expires;
}

function getCookie(name){
	var cookies = document.cookie.split(';');
	for(var cookieIterator=0;cookieIterator<cookies.length;cookieIterator++){
		var cookieElement = cookies[cookieIterator].split('=');
		if(trim(cookieElement[0]) == name)	return unescape(cookieElement[1]);
	}
	return null;
}

function ShareThis_show(title, url, icon, summary, content){
	window.open('sharethis.asp?title='+title+'&url='+url+'&icon='+icon+'&summary='+summary+'&content='+content, 'ShareThis', 'height=500, width=365, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}
