/* utils */
function windowOpener(windowUri, windowWidth, windowHeight, windowOptions)
{	
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    var newWindow = window.open(windowUri, '', 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight +
		',' + windowOptions);

	if (newWindow) newWindow.focus(); 
}

function openPopup(url, parameters) {
	window.open(url, "LevisPopup", parameters);
}

function openMinimalPopup(url, parameters) {
	parameters += "status=0,toolbar=0,location=0,menubar=0";
	openPopup(url, parameters);
}

function getOSName(){
	var OSName = "";
	if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
	if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
	if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
	if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
	return OSName;
}

function changeSection(browserTitle, sectionName) {	
  if(browserTitle != "") {
	document.title = browserTitle;
  }
  window.location.hash = "#" + sectionName;
}

function getDomain() {
	return window.location.host;
}

/* renvois l'url de base en cours */
function getBaseUrl(){
	var currentUrl
	var aUrl
	currentUrl=document.location.href;
	aUrl = currentUrl.split("#");	
	return aUrl[0];	
}
function getBaseParams(){
	var currentUrl
	var aUrl
	currentUrl=document.location.href;
	aUrl = currentUrl.split("#");	
	return aUrl[1];	
}
function getUrlSection(){
	var currentUrl
	var aUrl
	var aParams
	currentUrl=document.location.href;
	aUrl = currentUrl.split("#");
	if(aUrl.length>1){	
		aParams = aUrl[1].split("/");	
		return aParams[0];
	}else{
		return undefined;
	}	
}
function getUrlInternalName(){
	var currentUrl
	var aUrl
	var aParams
	currentUrl=document.location.href;
	aUrl = currentUrl.split("#");
	if(aUrl.length>1){	
		aParams = aUrl[1].split("/");	
		return aParams[1];
	}else{
		return undefined;
	}	
}
function setUrl(section, internalName, displayName){
	var url
	url = getBaseUrl() + "#" + section;
	if (internalName != undefined){
		url += "/"+internalName;
	}
	document.location.href = url;
	document.title = "Levi - " + section.toUpperCase() + " - " + displayName.toUpperCase();
}

function getUrlParam(name)
{ 
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec( window.location.href ); 
	if( results == null )    return ""; 
	else return results[1];
}

/* REGIONS FOR 501 */
function getRegion(){
	return regionCode;
}

function isEurope(){
	if(getRegion() == "EUROPE"){
		return true
	}
	return false
}

function isAsia(){
	if(getRegion() == "ASIA"){
		return true
	}
	return false
}

function isLatAm(){
	if(getRegion() == "SOUTH_AMERICA"){
		return true
	}
	return false
}

// Communication between the main Flashes and the sound player in the header
function SoundPlayer_doAction( idAction, pValue, pTime ) {
    document.getElementById("flashmain").doCommand( idAction, pValue, pTime );
}

function SoundPlayer_update( listXml, pStartPlaying ) {
    document.getElementById("flashmain").updateList( listXml, pStartPlaying );
}

// Navigation methods

// Called by the accessories section
function openPhones(){
    window.location = "http://www.modelabs.com/levis/";
}
/* open media */
function openMakingOffBlue() {	
	window.location = "http://" + getDomain() + "/" + languageCode + "_" + countryCode + "/media-center.html#home/Catwalk_Blue";
}
function openMakingOffLEJ() {	
	window.location = "http://" + getDomain() + "/" + languageCode + "_" + countryCode + "/media-center.html#home/LEJ_BOY_HD";
}
function openMakingOffRedTab() {	
	window.location = "http://" + getDomain() + "/" + languageCode + "_" + countryCode + "/media-center.html#home/REDTAB_GUYS_HD";
}
function openMakingOffLVC() {	
	window.location = "http://" + getDomain() + "/" + languageCode + "_" + countryCode + "/media-center.html#home/LVC_HD1";
}

/* STORE LOCATOR */
function navigateToStoreLocator(productCode) {
	var querystring_str = "";
	
	if(isAsia()){
		window.location = "http://www.ap.levi.com/store_locator.asp";
	} else {
		if(productCode != ""){
			querystring_str = "?collection=" + productCode;
		}
		window.location = "/" + locale + "/store-locator.html" + querystring_str;
	}
}
function navigateToRedTabStoreLocator() {
	navigateToStoreLocator("redtab");
}
function navigateToBlueStoreLocator() {
	navigateToStoreLocator("blue");
}
function navigateToLejStoreLocator() {
	navigateToStoreLocator("lej");
}
function navigateToLvcStoreLocator() {
	navigateToStoreLocator("lvc");
}

/* RED TAB */
function navigateToRedtab() {
	window.location = "http://eu.levi.com/" + languageCode + "_" + countryCode + "/levis_collections/levis-jeans.html";
}

/* SHOP */
function navigateToShop(productCode) {
	var destUrl = "http://eu.levi.com/" + locale +"/shop/";
	if(productCode != undefined) {destUrl += "products/" + productCode + ".html";}
	
	navigateAndClearProductFinder(destUrl);
}
function navigateToProductFinder(gender, params){
	var destUrl = "http://eu.levi.com/" + locale +"/shop/products/"+gender;
	if(params != undefined) {destUrl += "?"+params;}
	
	navigateAndClearProductFinder(destUrl);
}
function navigateToTopBottom(gender, params){
	var destUrl = "http://eu.levi.com/" + locale +"/shop/top-bottom/"+gender;
	if(params != undefined) {destUrl += "?"+params;}
	
	navigateAndClearProductFinder(destUrl);
}

