//######################################################################################################
//############ stylesheet-weiche   #####################################################################
//######################################################################################################

function weiche(struct)

{
        if ((navigator.appVersion.indexOf("Mac") != -1))
        {
                        if ((navigator.appName == "Microsoft Internet Explorer")) {
                                document.write('<link rel=stylesheet type="text/css" href="' + struct + 'stylemac.css">');
                }
                else{
                        document.write('<link rel=stylesheet type="text/css" href="' + struct + 'stylemacns.css">');
        }}

        else
        {
                if ((navigator.appName == "Microsoft Internet Explorer")) {
                        document.write('<link rel=stylesheet type="text/css" href="' + struct + 'stylepc.css">');
                }
                else{
                        document.write('<link rel=stylesheet type="text/css" href="' + struct + 'stylepcns.css">');
                }
        }

} // end Stylesheet-Weiche

//######################################################################################################
//############ submit funktionen #######################################################################
//######################################################################################################

function ReloadMyself(strForm)
{
	eval('document.' + strForm + '.method = "post"');
	eval('document.' + strForm + '.action = "' + document.location.href + '"');
	eval('document.' + strForm + '.submit()');
	}
	
function SubmitForm(strForm,ziel)
{
	eval('document.' + strForm + '.method = "post"');
	eval('document.' + strForm + '.action = "' + ziel + '"');
	eval('document.' + strForm + '.submit()');
}

// Calculator Popup
function OpenCalc(URL)
{
		_wndCalc = window.open(URL,"Calculator","width=650,height=550,left=100,top=0,resizable=yes,scrollbars=no");
		_wndCalc.opener = top;
		_wndCalc.focus();
}


//--------------------------------------------------------------------------------------------------------------------
// ReBuildQueryString( strQueryString, country, language, OfferID, RatioNew, RatioOld, ShowMax )
//--------------------------------------------------------------------------------------------------------------------
// (Neu-)Aufbau des QueryStrings zu übergebener URL
// mit wichtigen Applikationsparametern
// Grundsätzlicher Zweck :
//		Aufbereitung des QueryStrings für externe Aufrufe mit Redirect, um eine Konsistente Rückkehr zur Applikation
//		zu ermöglichen. ( Globale Suchfunktion snf_new )	
//--------------------------------------------------------------------------------------------------------------------
// Vorgehen :// die Suchfunktion @hp.com führt einen redirect auf die aufrufende Seite durch.// bei den Applikationsseiten muss auf vollständige Parametrisierung dringend geachtet// werden, da Inkonsistenzen mit einem redirect auf die Portalseite bestraft werden.
// // Ansatz : Der QueryString wird abgeschnitten und die wichtigen Applikationsparameter werden//			infolge neu angehängt.//			Nachteil : Neue wichtige Parameter müssen hier ebenfalls gepflegt werden.//			Vorteil  :	Wenn hier etwas vergessen wird, knallt es auffällig und sichtbar,//						andere Optionen hätten Logikfehler in der App zur Folge, die übersehen//						werden oder missinterpretiert werden könnten.//--------------------------------------------------------------------------------------------------------------------
//function ReBuildQueryString( strQueryString, country, language, OfferID, RatioNew, RatioOld, ShowMax ){

					
//	var selfLoc = strQueryString ;					
//	if ( selfLoc.indexOf("?") != -1  ){					//		selfLoc = selfLoc.substring( 0,  selfLoc.indexOf("?") );
//	}
					
						//	selfLoc = selfLoc +  "?country=" + country + "&language=" + language
//			+ "&OfferID=" + OfferID + "&ShowMax=" + ShowMax + "&RN=" + RatioNew +"&RO=" + RatioOld ;	
//	return(selfLoc);


//}
function ReBuildQueryString(strQueryString, country, language)
{				var selfLoc = removeQueryParameters(strQueryString)		selfLoc = selfLoc +  "?country=" + country + "&language=" + language;
	return(selfLoc);
}


function ReBuildQueryStringForProductInfo(strQueryString, country, language, program)
{				var selfLoc = removeQueryParameters(strQueryString)		selfLoc = selfLoc +  "?country=" + country + "&language=" + language + "&program=" + program;
	return(selfLoc);
}

//--------------------------------------------------------------------------------------------------------------------

function removeQueryParameters(strQueryString)
{
	var selfLoc = strQueryString ;					
	if ( selfLoc.indexOf("?") != -1 )
	{							selfLoc = selfLoc.substring( 0,  selfLoc.indexOf("?") );
	}			
	return(selfLoc);
}
	
// generic popup window opener for DigiDev
function open_pop(url) {
	var pop_win = window.open(url,'pop_win','left=25,top=25,width=500,height=500,scrollbars=yes');
	pop_win.focus();
	return false;
}
//##################### NSS specific #########################
function submitMyForm(actionID, positionID)
{
	document.myForm.actionID.value= actionID;
	document.myForm.positionID.value = positionID
	document.myForm.action = "/buyandtry/dispatcher.asp";
	document.myForm.submit();
}

function selectProgram(actionID, programID)
{
	document.myForm.actionID.value = actionID;
	document.myForm.programID.value = programID;
	document.myForm.action = "/buyandtry/dispatcher.asp";
	document.myForm.submit();
}

function setFocus(target)
{
	window.location.hash = target;
}

function callPrintable()
{
	window.open(document.location.href + "&print=1", "BATAdd", "width=600,height=600,scrollbars=yes,left=10,top=10");
}

function openAddAddress(siteID)
{
	window.open("additionalAddress.asp?siteID=" + siteID, "BATAdd", "width=600,height=300");
}

function openSalesRepPopUp()
{
	window.open("salesreppopup.asp", "BATAdd", "width=600,height=300");
}

function editBank()
{
	window.open("bankDetails.asp", "BATAdd", "width=600,height=220");
}

function openOptions()
{
	window.open("pickupoptions.asp?siteID=13", "BATAdd", "width=600,height=170");
}

function showPackingSlip(strOfferID, strName)
{
	window.open("packingslip.asp?offerID=" + strOfferID + "&customerEmail=" + strName, "BATAdd", "width=600,height=500,scrollbars=yes");
}

function showFileUp(offerID, SessionID, epopmode)
{
	window.open("epop.asp?sid=" + SessionID + "&offerid=" + offerID + "&epop_mode=" + epopmode, "HPFileUp", "width=300,height=200");
}

function showPackagelable(strOfferID, strName)
{
	window.open("packagelable.asp?offerID=" + strOfferID + "&customerEmail=" + strName, "BATAdd", "width=600,height=500,scrollbars=yes");
}

function printMe()
{
	if(!window.print)
		if (navigator.userAgent.indexOf("Mac") != -1)
			alert("Press Apple-P to print this site");
		else
			alert("Press Ctrl-P to print this site");
	else
		window.print();
}

function adjust_OLD(   ){
		//final resize
		if (document["getElementById"]) { 
			wheight = document.getElementById("hoehe").offsetTop + 10;
            wwidth = document.getElementById("breite").offsetParent.offsetLeft + 10;
		}
		else if (document.all) {
			wheight = hoehe.offsetTop + 10;
            wwidth = breite.offsetParent.offsetLeft + 10;
		}
		else if (document.layers) {
			wheight = document.nshoehe.pageY + 50;
            wwidth = document.nsbreite.pageX + 50; 
		}
			
		wwidth = 600;
		var maxheight = screen.availHeight;
		if (wheight > maxheight)
				wheight = maxheight;
		var maxwidth = screen.availWidth;
		if (wwidth > maxwidth)
				wwidth = maxwidth;
					
			
		window.resizeTo(wwidth,wheight);
}

function adjust(){
		//final resize
		if (document["getElementById"]) { 
			wheight = document.getElementById("hoehe").offsetTop + 40;
            //wwidth = document.getElementById("breite").offsetParent.offsetLeft + 40;
		}
		else if (document.all) {
			wheight = hoehe.offsetTop + 40;
            //wwidth = breite.offsetParent.offsetLeft + 40;
		}
		else if (document.layers) {
			wheight = document.nshoehe.pageY + 70;
            //wwidth = document.nsbreite.pageX + 50; 
		}
		
		wwidth = 600;
		wheight += 30;
		
		var maxheight = screen.availHeight;
		if (wheight > maxheight)
				wheight = maxheight;
		var maxwidth = screen.availWidth;
		if (wwidth > maxwidth)
				wwidth = maxwidth;
					
			
		window.resizeTo(wwidth,wheight);
}


function genMailLink(rec, dom, tld, subj, bod, lnkTxt, underline) {
	var ml, lnk, outp;
	
	ml = rec;
	ml += "@";
	ml += dom;
	ml += ".";
	ml += tld;
	
	lnk = "mailto:" + ml;
	
	if(subj != "")
		lnk += "?subject=" + subj;
		
	if(bod != "") {
		if(lnk.indexOf("?") != -1)
			lnk += "&amp;";
		else
			lnk += "?";
			
		lnk += "body=" + bod;
	}
	
	if(lnkTxt != "")
		ml = lnkTxt;
	
	outp = "<a href=\"" + lnk + "\"";
	if(underline == 1)
		outp = outp + " class=\"udrline\" ";
	outp = outp + ">" + ml + "</a>";
	
	document.write(outp);
}

function genMailRef(rec, dom, tld, subj, bod) {
	var ml, lnk;
	
	ml = rec;
	ml += "@";
	ml += dom;
	ml += ".";
	ml += tld;
	
	lnk = "mailto:" + ml;
	
	if(subj != "")
		lnk += "?subject=" + subj;
		
	if(bod != "") {
		if(lnk.indexOf("?") != -1)
			lnk += "&amp;";
		else
			lnk += "?";
			
		lnk += "body=" + bod;
	}
	
	document.write(lnk);
}

function OpenTermsPopupPrintableVersion()
{
	var _wndSummary;
	_wndSummary = window.open("terms.asp?print=1","SummaryPopupPrintable","width=600,height=400,left=0,top=0,resizable=yes,scrollbars=yes");
	_wndSummary.opener = top;
	_wndSummary.focus();
}


function changeCountry(resellerID, simdate, usedb, isLive, shortcutmode) {

	var dd = document.getElementById('dd_selectCountry');
	
	var val = dd.value;
	var url = "";
	
	if(val != null && val != "") {
		var arr = val.split("-");
		
		if (arr.length == 2) {
			url = "/buyandtry/" + arr[0] + "/" + arr[1] + "/";
			
			if (!isNaN(resellerID)) {
				if (resellerID != 0)
					url += "?resellerID=" + resellerID;
			}
			
			isLive = (isLive == "true" || isLive == "wahr");

			if(!isLive && simdate != "") {
				if(url.indexOf("?") != -1)
					url += "&";
				else
					url += "?";
					
				url += "simdate=" + simdate;
			}
			
			if(!isLive && usedb != "") {
				if(url.indexOf("?") != -1)
					url += "&";
				else
					url += "?";
					
				url += "usedb=" + usedb;
			}
			
			if(!isLive && !isNaN(shortcutmode)) {
				if (shortcutmode != 0) {
					if(url.indexOf("?") != -1)
						url += "&";
					else
						url += "?";
				
					url += "shortcutmode=" + shortcutmode;
				}
			}
			
			location.href = url;
		}
	}


}


function ShowAdditionalTextModuleForNewProduct(selectControlId, targetDiv, arrAdditionalTextModules) {
	var dd = null;
	var div = null;
	var prodId = 0;
	

	dd = document.getElementById(selectControlId);
	div = document.getElementById(targetDiv);
		
	if(dd == null || div == null)
		return;
			
	prodId = dd.value;
		
	if(prodId <= 0) {
		div.style.display = "none";
		return;
	}
		
	if(arrAdditionalTextModules[prodId]["available"]) {
		div.style.display = "block";
		div.innerHTML = arrAdditionalTextModules[prodId]["text"];
	}
	else {
		div.style.display = "none";
	}
}
