// Client Side Eventing (for SAP Portal EP 5.0)
// 2003-05-01, M. Lob, TRINEA Consulting GmbH
	try {document.domain=document.location.host.substr(document.location.host.indexOf('.')+1);} catch(e) {} // 5.0 SP 5 requirement
	var event_debug=false;
	var CArray = null;
	var xxx=null;
	
	if(this.netscape) {
		try {xxx = top.document;} catch(e) {}
		//xxx=navigator;
	}
	else {
		var agent=window.navigator.userAgent;
		if( agent.indexOf('MSIE') != -1){
			version = agent.substr( agent.indexOf('MSIE')+4);
			version = version.substr(0, version.indexOf(';'));
			//alert(version);
			if(version >= 5.5 && version < 7.0)
				xxx=navigator;
		}		
		if(xxx==null)
			xxx=window.top;
	}	
	try {
		if(xxx.commArray == null)
			xxx.commArray=new Array;
		CArray = xxx.commArray;
	}
	catch(e) {
		//alert('ClientComm.js' + e + " || " + document.domain + " || " + window.navigator.userAgent);
	}

	function MyEvent(sEvent, fFunction) {
		this.sEvent=sEvent;
		this.fFunction=fFunction;
		this.oWin = self.name;
	} // create()
		
	function event_subscribe(sEvent, fFunction) {
		var bOK=false;
		
		if(CArray) {
			for(i=0; i<CArray.length; i++) {
				if(CArray[i]!=null && CArray[i].sEvent==sEvent 
						&& CArray[i].fFunction == fFunction
						&& CArray[i].oWin == self.name ) {
					bOK=true;
					break;
				} // same function	
			} // check all entries in the comm dispatcher array

			if( bOK == false ){
				CArray[CArray.length]= new MyEvent(sEvent, fFunction);
				if(event_debug)
					alert('successfully subscribed event [' + sEvent + ']');
			}
			
			if(event_debug)
				alert('event [' + sEvent + '] subscribed with function [' + fFunction.toString() + ']');
			bOK=true;

			
			
		} // comm dispatcher initilaized
		else
			if(event_debug)
				alert('error: comm array uninitialized');
		return(bOK);
	} // subscribe()
	
	function GetParents( w ){
		for( i=0; i<w.parent.frames.length; i++ ){
			if( w.parent.frames[i].name == w.name ){
				if( w.parent == top ) {
					return "Top: " + w.parent.name + " " + i + "=" + w.name;
				} else {
					return GetParents( w.parent ) + "." + i + "=" + w.name;
				}
			}
		}
	}

	function event_unsubscribe(sEvent, fFunction) {
		var bOK=false;
		
		if(CArray) {
			for(i=0; i<CArray.length; i++) {
				if(CArray[i]!=null && CArray[i].sEvent==sEvent 
						&& CArray[i].fFunction == fFunction
						&& CArray[i].oWin == self.name ) {
					CArray[i]=null;
					bOK=true;
					if(event_debug)
						alert('successfully unsubscribed event [' + sEvent + ']');
					break;
				} // same function	
			} // check all entries in the comm dispatcher array
		} // comm dispatcher initilaized
		else
			if(event_debug)
				alert('error: comm array uninitialized');
		return(bOK);
	} // subscribe()


	function event_send(sEvent, sData) {
		var iOK=0;
		if(CArray) {
			for(var i=0; i<CArray.length; i++) {
				if(CArray[i]!=null && CArray[i].sEvent==sEvent) {
					if(event_debug)
						alert("Sending Event " + typeof(CArray[i].fFunction));
					try {
						if( this.netscape ){
							(CArray[i].fFunction)(arguments[1], arguments[2]);
						} else {
							(CArray[i].fFunction)(arguments[1], arguments[2]);
						}
						iOK++;
					}
					catch(e) {};	
				}	
			} // check all entries in the comm dispatcher array
		} // comm dispatcher initialized
		return iOK;
	} // send()
	
	function event_register(sEvent) {
		return false;
	} 
	

	// open another page in the portal	
	function portalpage(spage, bfromCMS){

		try {
			if((typeof(parent.EPCM) == 'object') && (parent.EPCM.getVersion()> '6.0')) { // EP6ff
				// alert(parent.EPCM.getVersion());
				var navThis=parent.parent.document.forms['frmChangeContent'].elements['NavigationTarget'].value;
				
				// Added by Satyam on 24th Oct 2006 to solve the portal Favorites runtime error
				
				// ***** Portal Favorites runtime error code starts here  ******		
				if(navThis.indexOf('navurl')!= -1)// Only when the page is accessed from Portal favorites or History
				{
					//Getting the Long URL of the current navigation target from the History framework object
					LURL=parent.EPCM.getSAPTop().gHistoryFrameworkObj.GetActiveTrackingEntryValue().getUrl();
					//The above LURL contains both nav URL and LURL.So the below code for getting only the Long URL
					navThis=LURL.substr(LURL.lastIndexOf('&LURL=')+6,LURL.length);
				}
				// ***** portal Favorites runtime error Code Ends here  ******		

				var navBase=navThis.substr(0, navThis.lastIndexOf('/'));

				if(navBase.indexOf('/WS_Hidden')!= -1)
					navBase=navBase.substr(0, navBase.lastIndexOf('/WS_Hidden'));
					
				var navTarget=null;
				var quickLink=null;
				switch(spage) {
					case 'com.zs.ProductCatalogOrder':	navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_product_catalog_order'; quickLink='product_catalog_order'; break;
					case 'com.zs.OrderProcess':			navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_orderprocess'; quickLink='orderprocess'; break;
					case 'com.tlg.OrderProcess':		navTarget=navBase+'/'+'WS_Hidden_2/com.tlg.pg_orderprocess'; break;	
					case 'com.zs.QuotationProcess':		navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_quotationprocess'; break;
					case 'com.zs.InquiryProcess': 		navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_inquiryprocess'; break;
					case 'com.zs.order.state': 			navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_orderstate'; break;
					case 'com.zs.inquiry.state': 		navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_myinquiry_status'; break;
					case 'com.zs.quotation.state': 		navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_myoffer_search_order'; break;
					case 'com.zs.myaccount': 			   navTarget=''; break;

					// not needed
					case 'com.zs.PriceList':			   navTarget=''; break; // N9
					case 'com.zs.OnSale':				   navTarget=''; break; // On Sale (CH)
					
					case 'zs.tecton2': 					navTarget=navBase+'/'+'WS_Hidden/com.zs.pg_tecton_0'; break;
					case 'zs.tecton': 					navTarget=navBase+'/'+'com.zs.pg_tecton'; break;
					// via Quicklink with synchronized Navigation
					//case 'zs.tecton2': 					   navTarget='QUICKLINK'; quickLink='tecton'; break;
					default:	alert('unknown navigation target ::'+spage+'::'); break;
				}


				if(navTarget != null) {
					// navTarget = navTarget.replace("WS_Hidden/WS_Hidden/","WS_Hidden/");
					if(navTarget == '')
						alert('please specify final EP6 navigation target for ::'+spage+'::');
					else if (navTarget=='QUICKLINK') {
						//alert(document.location.protocol + '//' + document.location.hostname + '/irj/portal/' + quickLink);
						top.location.href=document.location.protocol + '//' + document.location.hostname + '/irj/portal/' + quickLink;
					} else {
						if (typeof(parent.frameworkSupport) == 'object') { //light weight framework?
							if(quickLink == null)  // extract from navTarget
								quickLink=navTarget.substr(navTarget.lastIndexOf('.')+4); // 4 = .pg_
							top.location.href=document.location.protocol + '//' + document.location.hostname + '/irj/portal/' + quickLink;
						} else {
							parent.EPCM.doNavigate(navTarget);
						}
					}
				}
			} // EP6ff
			else { // EP5
				var shref = document.location.protocol;
				if(bfromCMS) {
					var iIdx=document.location.search.indexOf('sFrom=');
					if(iIdx != -1) {
						shref=document.location.search.substr(iIdx+6);
					}
					else
						shref+='//'+document.location.hostname;
				}
				else 
					shref+='//'+document.location.hostname;
				shref+='/hrnp$30001/' + 'localhost';
				switch(document.location.protocol) {
					case 'http:':
						shref+=':80';
						break;
					case 'https:':
						shref+=':443';
						break;
				}

				shref+='/Action/PageBuilder[myPage]?pageName='+spage;
				window.parent.location.href=shref;
			} //EP5
		}catch(e) {
			alert('portalpage('+spage+'): '+e);
		}
	}

