//== OPEN POPUPS ==

//build path to the popup html files
//use the baseUrl as defined in the launching HTML page
//ie, if the baseUrl is set as 'flash/' then the path is 'flash/popups/'
//else it is just 'popups/'
var pathToPopUps
if (baseURL) {
	pathToPopUps = baseURL + 'popups/';
}
else {
	pathToPopUps = 'popups/';
}

var glReferrer = "http://europenikerunning.com"

function getPrivacyPolicyPopUp(locale){
	switch (locale){
	case "en_gb":
		window.open('http://www.nike.com/privacy/eu_england.jsp','privacypolicy');
	break;
	case "en_eu":
		window.open('http://www.nike.com/privacy/eu_england.jsp','privacypolicy');
	break;
	case "en_uk":
		window.open('http://www.nike.com/privacy/eu_england.jsp','privacypolicy');
	break;
	case "de_de":
		window.open('http://www.nike.com/privacy/eu_deutsch.jsp','privacypolicy');
	break;
	case "es_es":
		window.open('http://www.nike.com/privacy/eu_espanol.jsp','privacypolicy');
	break;
	case "fr_fr":
		window.open('http://www.nike.com/privacy/eu_francais.jsp','privacypolicy');
	break;
	case "it_it":
		window.open('http://www.nike.com/privacy/eu_italiano.jsp','privacypolicy');
	break;
	case "pl_pl":
		window.open('http://www.nike.com/privacy/eu_england.jsp','privacypolicy');
	break;
	}
}

function getProfilePopUp(locale) {
	openPopupNoHandle(getEMEADomain()+'/emea/shared/profile.jsp?language=' + locale,550,530,'yes','profile');
}

function getPasswordPopUp(locale) {
	locale = upperCaseCountry(locale);
	openPopupNoHandle(getEMEADomain()+'/emea/shared/forgot/forgot_password.jsp?language=' + locale,550,530,'yes','password');
}

//used to alert users of change of username to email
function getConvertPopUp(locale) {
	locale = upperCaseCountry(locale);
	openPopupNoHandle(getEMEADomain()+'/emea/shared/converted.jsp?language=' + locale,550,500,'yes','convertprofile');
}

function getRunningLog(strUserName,strUserStats,strLocale, strActionProfile){
	if (strActionProfile=='infomissing') {
		getProfilePopUp(strLocale);
	} else if (strActionProfile=='convert') {
		getConvertPopUp(strLocale);
	} else {
		openPopupNoHandle('/europerunning/train/running_log/default.htm?username=' + strUserName + '&userstats=' + strUserStats + '&lang=' + strLocale,950,475,'no','traininglog');
	}
}

function openNikeFree(locale) {
	openPopup(pathToPopUps + "free.htm?l="+locale, 774, 542, true, "openNikeFree");
}

function openMayfly(locale) {
	openPopup(pathToPopUps + "mayfly.htm?l="+locale, 774, 542, true, "mayFly");
}

function openMeetBill(locale) {
	openPopup(pathToPopUps + "meetBill.htm?l="+locale, 774, 542, true, "meetBill");
}

function openNikeId() {
	window.open('http://nikeid.nike.com/nikeid/index.jhtml?ref=' + glReferrer + '#category,running');

}

function openNikePlus() {
	window.open('http://www.nike.com/nikeplus/?l=en_GB&ref=' + glReferrer + '#overview');
}


function openNikeIdMens() {
    window.open('http://nikeid.nike.com/nikeid/index.jhtml;nisessionid=0BDWAKPS0TGO0CQCGJDCF3Y?_requestid=550973#free,running,n_free_0503_public,male&ref=' + glReferrer);
}

function openNikeIdWomens() {
    window.open('http://nikeid.nike.com/nikeid/index.jhtml;nisessionid=0BDWAKPS0TGO0CQCGJDCF3Y?_requestid=550973#free,running,n_free_0503_public_w,female&ref=' + glReferrer);
}

function openRunLondon() {
    window.open('http://www.runlondon.com?ref=' + glReferrer);
}

//== OPEN POPUPS ==
function openPopup(strGoTo,iWidth,iHeight,strScrollbars,strWinName){

	if (strScrollbars == 'yes'){
		iWidth += 16;
	}
	strParams = "scrollbars=" + strScrollbars + ",status=0,height=" + iHeight + ",width=" + iWidth;
	newWindow = window.open(strGoTo,strWinName,strParams);
	var w = screen.availWidth;
	var h = screen.availHeight;
	if(newWindow) {
		if (!isNaN(w) && w != null){
			var leftPos = (w-iWidth)/2;
			var topPos = (h-iHeight)/2;
			newWindow.moveTo(leftPos,topPos);
		} else {
			newWindow.moveTo(1,1);
		}
		newWindow.focus();
		newWindow = null;
	}
}

function openPopupNoHandle(strGoTo,iWidth,iHeight,strScrollbars,strWinName){
	if (strScrollbars == 'yes'){
		iWidth += 16;
	}
	strParams = "scrollbars=" + strScrollbars + ",status=0,height=" + iHeight + ",width=" + iWidth;
	window.open(strGoTo,strWinName,strParams);
}

function launchFull(name,url,blnCenter){
	var ratio = 987/693;
	if(screen.width > 1024) {
		width = 1016;
		height = 712;
	} else {
		height = screen.height - (2*28);
		width = (height * ratio);
		if(width > screen.width-8) {
			width = screen.width-8;
			height = (screen.width/ratio)+barHeight;
		}
		if(navigator.appVersion.indexOf("Mac") != -1)
			//height -= 5;
		
		if(navigator.appVersion.indexOf("Mac") != -1 && document.all){
			if(screen.width == 1280 && screen.height == 1024)
				height +=12;
			if(screen.width == 1024 && screen.height == 768)
				height +=55;
		}
	}
	
	var str = "width="+width+",height="+height+",scrollbars=no";
	if (blnCenter==false){//Don't create a handle on the new window to avoid 'access denied' error
		window.open(url,name,str);
	} else {
		name = window.open(url,name,str);
		name.focus();
	}
}
