/**
 *	Datei enthält Funktion, die nur noch im alten B2C-Design und B2B verwendet werden.
 * 
 */



/*
	############################################################################
	init: Initiiert den Timer für den Warenkorb
        currentTime = ShoppingBasketModel.getTimeToLive() -> verbleibende Zeit
        bis Warenkorb-Eintraege verfallen. 
        quantity = Anzahl der Warenkorbeinträge

        init(<=basket.getTimeToLive( cuTime )>,
            '<=request.getContextPath()>/<=session.getAttribute("kind")>',
            <=basket.getCount()>,
            true,
            '<=application.getAttribute("imagePath")>/img');
	############################################################################
*/
function init( currentTime, path, quantity, nolight, pImgPath, pSelectedURL, isRelaunch){

    	yellowWarningEarly = 10;
    	yellowWarningLate = 5;

    	var lights = new Boolean(false);
    	
    	if (nolight != null) { 
    		lights = new Boolean(nolight);
    	}
    	if (isRelaunch == null)
    		isRelaunch = "false";
		
 	if( quantity>=1 && isRelaunch == "false") {
 		//kein Warenkorb popup bei OrderPräparation: orderPay, orderAddress, accountlogin, overview, confirmation
		if (!(pSelectedURL.indexOf("/s_orderpay") > -1  ||  pSelectedURL.indexOf("/s_orderaddress") > -1 || pSelectedURL.indexOf("/s_orderoverview") > -1 
				|| pSelectedURL.indexOf("/s_accountlogin") > -1 || pSelectedURL.indexOf("/s_orderconfirmation") >-1)) {
			isTimeYellow = 0;
		     
		//		urlYellow = "/eventstore/warningbasket";

			if (hinweisfenster)
				urlYellow = hinweisfenster;
		
//			alert("hinweisfenster " + hinweisfenster.substr(20) +  " Ende");
		        
		         timeYellow1 = currentTime - yellowWarningEarly * 60;   
		         timeYellow2 = currentTime - yellowWarningLate * 60;   
		         timeRed = currentTime;  
		
			if ( timeYellow2 >= 0 ) {
				if (lights==1 ) {
					window.timer_yellow2 = window.setTimeout( "popupYellow( urlYellow,true,yellowWarningLate,0 )", timeYellow2*1000 );
				} else 
					window.timer_yellow2 = window.setTimeout( "popupYellow( urlYellow,false,yellowWarningLate, 0)", timeYellow2*1000 );
			}			
			/* früher gelber Timeout */
			if ( timeYellow1 >= 0 ) {
				if (lights==1 ) {
			        	 window.timer_yellow1 = window.setTimeout( "popupYellow( urlYellow,true,yellowWarningEarly,1 )", timeYellow1*1000 );
				} else 
					window.timer_yellow1 = window.setTimeout( "popupYellow( urlYellow,false,yellowWarningEarly,1 )", timeYellow1*1000 );
			} else  {
				isTimeYellow = 1; /* Gelber Status aktuell */		
			}
		}
	}
 
 
}
		
/*
	############################################################################
	popupYellow: Öffnet das Warnfenster für den Status gelb
	############################################################################
*/                                                                                               
function popupYellow( windowYellow,show,timeout,type ){
        //window.ttl = timeout;
        if (type==0)
        	fenstername = "FensterRot";
        else
        	fenstername = "FensterGelb"

//	alert("windowYellow " + windowYellow.substr(20) +  " Ende");
        	
	var PopupYellow = window.open( windowYellow,fenstername,"width=400,height=350,screenX=0,screenY=0"); 
//	PopupYellow.currcss = currcss;
//	PopupYellow.currbasket = currbasket;

	if (PopupYellow)
		PopupYellow.focus();
}

function changeImageOld(name_id, name_src, name_doc2) {
	if (isNaN(name_id)==false) { 	
		document.getElementById(name_id).src=name_src;
		//document.images[name_id].src = name_src;		
		while (!document.images[name_id].complete) { }		 
	} else {
		if (document.all) {
		   	document.all[name_id].src = name_src;
		} else {	
		   document[name_id].src = name_src;
		   while (!document[name_id].complete) { }
		}
	}	
	document.getElementById(name_doc2).className='waitCursor';
	   // document.sendOrder.submit();
   return false;
}



function preloadAbme(imgObj, imgSrc) {
    if (document.images) {
        eval(imgObj+' = new Image()');
        eval(imgObj+'.src = "'+imgSrc+'"');
    }
}

function chgAbme(name_doc, name_src) {

//	if (isNaN(name_doc)==false) {
//		alert(name_src.src);
//		document.images[name_doc].src = eval(name_src+".src");		
		document.all[name_doc].src = name_src.src;
//	}	
}

function activateView(listDiv) {
	if ($(listDiv)) {
		if ($(listDiv).style.display == 'block') {
			$(listDiv).style.display = 'none';
		} else {
			$(listDiv).style.display = 'block';
		}
	}
}

function CheckAll(formName){
	if(document[formName].ALL){
		var c = document[formName].ALL.checked;
	}
	for (var i=0;i<document[formName].elements.length;i++){
		var e = document[formName].elements[i];
		var subE = e.name.substring(0,4);
		if(subE == 'pos_' || subE == 'oof_' || subE == 'osf_' || subE == 'del_') e.checked = c;
   	}
}

