//######################################################################################################
//############ 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( ziel)
{
	var strForm = "globalform";
	
	eval('document.' + strForm + '.method = "post"');
	eval('document.' + strForm + '.action = "' + ziel + '"');
	eval('document.' + strForm + '.submit()');
}

// Retailer Popup ( B2B Trade-In ProductInfo )
function OpenRetailerPop( Position, PositionDetail, Index , title )
{

		var target = "ProductInfo_RetailerPopup.asp?Pos=" + Position + "&Det=" + PositionDetail + "&t=&Ind=" + Index;

		_wndRetailer = window.open(target, title ,"width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
		_wndRetailer.opener = top;
		_wndRetailer.focus();
}

// Summary Popup ( B2B Trade-In Summary )


function OpenSummaryPopupAddress(SID)
{	
	_wndSummary = window.open("summary_popupAddressData.asp?firstOpen=1&SID="+SID,"SummaryPopup","width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenSummaryPopupPickupAddress(SID)
{
	var _wndSummary;
	_wndSummary = window.open("summary_popupPickupAddress.asp?firstOpen=1&SID="+SID,"SummaryPopup","width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenSummaryPopupResellerAddress(SID)
{
	var _wndSummary;
	_wndSummary = window.open("summary_popupResellerAddress.asp?firstOpen=1&SID="+SID,"SummaryPopup","width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenSummaryPopupPickupData(SID)
{
	var _wndSummary;
	_wndSummary = window.open("summary_popupPickupData.asp?firstOpen=1&SID="+SID,"SummaryPopup","width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenSummaryPopupBankData(SID)
{
	var _wndSummary;
	_wndSummary = window.open("summary_popupBankData.asp?firstOpen=1&SID="+SID,"SummaryPopup","width=440,height=220,left=100,top=0,resizable=yes,scrollbars=no");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenFinalPopupPackingSlip(OfferID,CustomerEmail)
{
	var _wndSummary;
	_wndSummary = window.open("PackingSlip.asp?firstOpen=1&OfferID="+OfferID+"&CustomerEmail="+CustomerEmail,"FinalPopupPacking","width=634,height=350,left=50,top=0,resizable=yes,scrollbars=yes");
	_wndSummary.opener = top;
	_wndSummary.focus();
}


function OpenFinalPopupPrintableVersion()
{
	var _wndSummary;
	_wndSummary = window.open("final_popupPrintableVersion.asp?firstOpen=1","FinalPopupPrintable","width=600,height=400,left=0,top=0,resizable=yes,scrollbars=yes");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

function OpenFinalPopupPackageLable(OfferID,CustomerEmail)
{
	var _wndSummary;
	_wndSummary = window.open("PackageLable.asp?firstOpen=1&OfferID="+OfferID+"&CustomerEmail="+CustomerEmail,"FinalPopupPackage","width=634,height=350,left=50,top=0,resizable=yes,scrollbars=yes");
	_wndSummary.opener = top;
	_wndSummary.focus();
}



function OpenSummaryPopupPrintableVersion()
{
	var _wndSummary;
	_wndSummary = window.open("Summary_popupPrintableVersion.asp?firstOpen=1","SummaryPopupPrintable","width=600,height=400,left=0,top=0,resizable=yes,scrollbars=yes");
	_wndSummary.opener = top;
	_wndSummary.focus();
}

// 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 = "dispatcher.asp";
	document.myForm.submit();
}

function selectProgram(actionID, programID)
{
	document.myForm.actionID.value = actionID;
	document.myForm.programID.value = programID;
	document.myForm.action = "dispatcher.asp";
	document.myForm.submit();
}

function setFocus(target)
{
	window.location.hash = target;
}

function callPrintable()
{
	window.open(document.location.href + "&print=1", "NSSPrint", "width=800,height=600,scrollbars=yes,left=10,top=10");
}

function openAddAddress(siteID)
{
	window.open("additionalAddress.asp?siteID=" + siteID, "NSSAdd", "width=600,height=500");
}

function editBank()
{
	window.open("bankDetails.asp", "NSSAdd", "width=600,height=500");
}



function showFileUp(offerID, SessionID)
{
	
	var wndFileUp = window.open("epop.asp?sid=" + SessionID + "&offerid=" + offerID, "HPFileUp", "width=300,height=200");
	wndFileUp.focus();
}

function showEVAFileUp(offerID, SessionID)
{
	var wndFileUp = window.open("epop.asp?sid=" + SessionID + "&offerid=" + offerID + "&iseva=1", "HPFileUp", "width=300,height=200");
	wndFileUp.focus();
}

function adjust(   ){
		//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 approval_markAllPositions(valueToSet)
{
	positionCount = document.getElementsByName("positionCount")[0].value;

	for(i=1; i<=positionCount; i++)
	{	
		elementName = "position_status_" + i;
		if(document.getElementsByName(elementName)[0].value == valueToSet)
		{
			document.getElementsByName(elementName)[0].checked = true;
		}
		else if(document.getElementsByName(elementName)[1].value == valueToSet)
		{
			document.getElementsByName(elementName)[1].checked = true;
		}
	}
}

function approval_checkStatus()
{
	positionCount = document.getElementsByName("positionCount")[0].value;
	blnFoundApproved = false;
	blnFoundDeclined = false;
	countFound = 0;
	
	for(i=1; i<=positionCount; i++)
	{	
		elementName = "position_status_" + i;
		if(document.getElementsByName(elementName)[0].checked == true)
		{
			blnFoundApproved  = true;
			countFound++;
		}
		else if(document.getElementsByName(elementName)[1].checked == true)
		{
			blnFoundDeclined = true;
			countFound++;
		}
	}

	if(blnFoundApproved && blnFoundDeclined)
	{
		document.getElementsByName("all")[0].checked = false;
		document.getElementsByName("all")[1].checked = false;
	}
	else if(blnFoundApproved && countFound == positionCount)
	{
		document.getElementsByName("all")[0].checked = true;
	}
	else if(blnFoundDeclined && countFound == positionCount)
	{
		document.getElementsByName("all")[1].checked = true;
	}
}





