

/* to highlight elements (like tr or td) on mouse over*/
var currentColor='#FF00FF';
function highlightRowOnmouseover(obj){
	currentColor=obj.style.backgroundColor; 
	obj.style.backgroundColor='#ECF2FC'; /* the hightligt color */
}
function highlightRowOnmouseout(obj){
	obj.style.backgroundColor=currentColor;
}
/* how to call the scripts:
onmouseover="javaScript:highlightRowOnmouseover(this)" 
onmouseout="javaScript:highlightRowOnmouseout(this)"
*/

/* DEFAULT BUTTONs */
function goLite(thisButton) { // just use "goLite(this);"
	thisButton.style.color = "#5452D4"; //"#3634B6"; "#FF0000";
	thisButton.style.backgroundImage = "url(img/buttonBGhover.gif)";   
}
function goDim(thisButton) {
	thisButton.style.color = "#040284";		
	thisButton.style.backgroundImage = "url(img/buttonBG.gif)";
}
function goDown(thisButton) {
	thisButton.style.color = "#5452D4"; //"#FF0000";		
	thisButton.style.backgroundImage = "url(img/buttonBGDown.gif)";
}

/* smale buttons */
function goLite18(thisButton) { // just use "goLite(this);"
	thisButton.style.color = "#5452D4"; //"#3634B6"; "#FF0000";
	thisButton.style.backgroundImage = "url(img/buttonBGhover18.gif)";   
}
function goDim18(thisButton) {
	thisButton.style.color = "#040284";		
	thisButton.style.backgroundImage = "url(img/buttonBG18.gif)";
}
function goDown18(thisButton) {
	thisButton.style.color = "#5452D4"; 	
	thisButton.style.backgroundImage = "url(img/buttonBGDown18.gif)";
}

/* mini buttons */
function goLite12(thisButton) { // just use "goLite(this);"
	thisButton.style.color = "#5452D4"; 
	thisButton.style.backgroundImage = "url(img/buttonBGhover12.gif)";   
}
function goDim12(thisButton) {
	thisButton.style.color = "#040284";		
	thisButton.style.backgroundImage = "url(img/buttonBG12.gif)";
}
function goDown12(thisButton) {
	thisButton.style.color = "#5452D4"; 	
	thisButton.style.backgroundImage = "url(img/buttonBGDown12.gif)";
}


/* used in offerForm.jsp to display the recently updated popup  			    */
/* Sadly IE 6 still contains the bug that comboboxes will shine trough any <div */
/* and so one. To "avoid" this all comboboxes that could be behind the popup    */
/* are set to hidden when to popup is visible.                                  */
/* please note: 																*/
/* all the concerned comboboxes are wraped in <span id="xxxxComboBoxSpan 		*/
function showRecentlyUpdated(){
	document.getElementById('recentlyUpdatedDiv').style.visibility='visible';
	document.getElementById('languageComboBoxSpan').style.visibility='hidden';	
	document.getElementById('salesManagerComboBoxSpan').style.visibility='hidden';
	document.getElementById('accountManagerComboBoxSpan').style.visibility='hidden';
	document.getElementById('officeComboBoxSpan').style.visibility='hidden';
	document.getElementById('frameComponentComboBoxSpan').style.visibility='hidden';	
}
function closeRecentlyUpdated(){
	document.getElementById('recentlyUpdatedDiv').style.visibility='hidden';
	document.getElementById('languageComboBoxSpan').style.visibility='visible';	
	document.getElementById('salesManagerComboBoxSpan').style.visibility='visible';
	document.getElementById('accountManagerComboBoxSpan').style.visibility='visible';
	document.getElementById('officeComboBoxSpan').style.visibility='visible';
	document.getElementById('frameComponentComboBoxSpan').style.visibility='visible';	
}
var pseudoLinkTextColor='#00FF00';
function hoverPseudoLink(pseudoLinkTD){
	pseudoLinkTextColor=pseudoLinkTD.style.color;
	pseudoLinkTD.style.color='#FF0000';
	pseudoLinkTD.style.textDecoration='underline';
	pseudoLinkTD.style.cursor='pointer';
}
function resetPseudoLink(pseudoLinkTD){
	pseudoLinkTD.style.color = pseudoLinkTextColor;
	pseudoLinkTD.style.textDecoration='none';
	pseudoLinkTD.style.cursor='default';
}

function submitRefreshRecentlyUpdate() {
	thisForm = document.forms[0];
	thisForm.forward.value = 'showOffer';
	thisForm.refreshRecentlyUpdate.value = 'true';
	thisForm.submit();
}

function showElementById(elementId){
	document.getElementById(elementId).style.visibility='visible';	
}

function hiddeElementById(elementId){
	document.getElementById(elementId).style.visibility='hidden';
}

function submitForm(forward) {
	thisForm = document.forms[0];
	thisForm.forward.value = forward;
	thisForm.submit();
}

function removeComponent(forward, id) {
	thisForm = document.forms[0];
	thisForm.removedComponentId.value = id;
	thisForm.forward.value = forward;
	thisForm.submit();
}
function removeAttachment(forward, id) {
	thisForm = document.forms[0];
	thisForm.removedAttachmentId.value = id;
	thisForm.forward.value = forward;
	thisForm.submit();
}


function orderComponents(orderIndex, orderDirection) {
	thisForm = document.forms[0];
	thisForm.orderIndex.value = orderIndex;
	thisForm.orderDirection.value = orderDirection;
	submitForm('orderComponents');
}

/* menubar.jsp*/
function na() {
    alert("Not yet implemented.");
}

/* productDetails.jsp, workspaceDetails.jsp */
function save() {
	thisForm = document.forms[0];
	thisForm.submit();
}

/* login.jsp */
function setFocus() {
	document.forms[0].userName.focus();
}

function hiddeAllSelect(){
	
	var selects = document.getElementsByTagName('select');
	for(var i = 0; i < selects.length; i++){
		var select = selects[i];	
		select.style.visibility='hidden';
	}	
}

function showAllSelect(){
	
	var selects = document.getElementsByTagName('select');
	for(var i = 0; i < selects.length; i++){
		var select = selects[i];	
		select.style.visibility='visible';
	}	
}



/*
Intended to delete all links + buttons after 1 link or button is clicked.
The idea was to avoid doubleklicking as this might lead to the need of a reboot of the server!
The script below works. But I could not find a way to intercepet the continue with the "submit"
after the scripts where executed :(
*/
function disableAllLinksAndButtons(){

	var as = document.getElementsByTagName('a');	
	for(var i = 0; i < as.length; i++){
		var a = as[i];	
		a.href='javascript:return false();';
	}
		
	var inputs = document.getElementsByTagName('input');
	for(var i = 0; i < inputs.length; i++){
		var input = inputs[i];
		input.disabled='disabled';
	}
}

function switchToWaiting(){

	document.onmouseup = function(e) {	

		// get either event (W3C) or
		// window event object (MSIE)
    	e = e || window.event;
    
		// get either target (W3C) or event source (MSIE)
    	var t = e.target || e.srcElement;

		// when we click a link disable all links and buttons 
		if(t.nodeName.toLowerCase() == 'a'){
			h = t.href;
			t.id = 'ignoreThis';
			disableAllLinksAndButtons();
		}	
		
		// when we click a button disable all links and buttons 
		if((t.nodeName.toLowerCase() == 'input') && (t.type.toLowerCase() == 'button')){
			h = t.href;
			disableAllLinksAndButtons();
		}

		// when we click a img that is nested in a link disable all links and buttons 
		// UNLESS its "target="_blank" (when a new window is opend)
		if(t.nodeName.toLowerCase() == 'img'){
			if(t.parentNode.nodeName.toLowerCase() == 'a'){
				if(t.parentNode.target != '_blank'){				
					h = t.parentNode.href;										
					disableAllLinksAndButtons();					
				}
			}
		}				
	}
}

/* onclick="javascript:test();" */
function test(){
	alert(document.body.scrollTop);
}

/********************************************************************************************/
/* Processing Please Wait Display															*/
/* 																							*/
/* to use this script add:																	*/
/* <body onbeforeunload="showProcessingPleaseWait();">										*/
/* to your JSP's																			*/
/********************************************************************************************/
var tempDisableProcessingPleaseWait = false;
function showProcessingPleaseWait(){
	if(!tempDisableProcessingPleaseWait){
		setTimeout("exceuteShowProcessingPleaseWait()",200);
	}
	tempDisableProcessingPleaseWait= true;
}

function exceuteShowProcessingPleaseWait(){
	hiddeAllSelect();	
	var processingPleaseWaitDiv = document.getElementById('processingPleaseWaitDiv');
		
	var visibleWidth = getVisibleWidth();
	var visibleHeight = getVisibleHeight();
	processingPleaseWaitDiv.style.left=getScrollX() + (visibleWidth / 4);
	processingPleaseWaitDiv.style.top=getScrollY() + (visibleHeight / 4);		
	processingPleaseWaitDiv.style.width=visibleWidth / 2;
	processingPleaseWaitDiv.style.height=visibleHeight / 2;	
	
	processingPleaseWaitDiv.style.visibility='visible';
	processingPleaseWaitDiv.style.display='block';
	
	document.getElementById('processingPleaseWaitDivBG').style.visibility='visible';
	document.getElementById('processingPleaseWaitDivBG').style.display='block';
	startProcessingAnimation();
}

function setTempDisableProcessingPleaseWait(){
	tempDisableProcessingPleaseWait = true;
}

function hideProcessingPleaseWait(){
	stopProcessingAnimation();
	document.getElementById('processingPleaseWaitDivBG').style.visibility='hidden';
	document.getElementById('processingPleaseWaitDiv').style.visibility='hidden';
	document.getElementById('processingPleaseWaitDivBG').style.display='none';
	document.getElementById('processingPleaseWaitDiv').style.display='none';
	document.getElementById('omResponse').style.visibility='hidden';	
	interuptProgresDisplay();
	showAllSelect();	
}


// returns the Visible width for Moz and friends or IE
function getVisibleWidth(){
	if(isMOZ()){
		return window.innerWidth;
	}
	else {
		return document.body.offsetWidth;
	}
}

// returns the Visible height for Moz and friends or IE 
function getVisibleHeight(){
	if(isMOZ()){
		return window.innerHeight;
	}
	else {		
		return document.body.offsetHeight;
	}
}

function getScrollX() {
	var scrOfX = 0;
  	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
    	scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
    	scrOfX = document.body.scrollLeft;
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    	//IE6 standards compliant mode
    	scrOfX = document.documentElement.scrollLeft;
  	}
  	return scrOfX;
}

function getScrollY() {
	var scrOfY = 0;
  	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
    	scrOfY = document.body.scrollTop;
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    	//IE6 standards compliant mode
    	scrOfY = document.documentElement.scrollTop;
  	}
  	return scrOfY;
}








/*
simple Animation for processing please wait
*/
var animationColorBLANK = '#EEEEED';
var animationSeed = 0;
var doAnimation = 1;

var aniColors = ['#E7EBEE','#DFE7F0','#D8E4F1','#D0E0F2'];//['#F8FFFF', '#E4F4FF','#D0E0F2','#BCCCDE'];
var animationTDids = ['processing_ani_0','processing_ani_1','processing_ani_2','processing_ani_3','processing_ani_4','processing_ani_5','processing_ani_6','processing_ani_7','processing_ani_8','processing_ani_9'];

function startProcessingAnimation(){	
	colorAnimationTds();
}

function stopProcessingAnimation(){
	doAnimation = -1;
}

function colorAnimationTds(){

	if(animationSeed < -12){
		animationSeed = 0;
	}

	for(var i = 0; i < animationTDids.length; i++){		
		var curColor = getColorForColorZa(i + 3 + animationSeed);	
		document.getElementById(animationTDids[i]).style.backgroundColor = curColor;		
	}
	
	animationSeed = animationSeed -1;
	if(doAnimation == 1){
		setTimeout("colorAnimationTds()",200);
	}
}

function getColorForColorZa(colorZa){
	
	if(colorZa > aniColors.length || colorZa < 0){
		return animationColorBLANK;
	}
	else{
		return aniColors[colorZa];
	}
}

function isMOZ(){
	if (!document.all) {
		return true;
	}
	else {
		return false;
	}
}


/* for ajax and show offer state*/
var req;
var reqCancelButton;
var stopProgresDisplay = -1;

function startProgresDisplay(){
	setTimeout("retrieveURL('requestStateForUser.do')",1000);
	setTimeout("retrieveURLCancelButton('requestCancelButtonCompose.do')",1100);
}

function interuptProgresDisplay(){
	stopProgresDisplay= 1;
}

function retrieveURL(url) {
	if(stopProgresDisplay == -1){
	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
    	req.onreadystatechange = processStateChange;
    	try {
	    	req.open("GET", url, true);
		} catch (e) {
	    	alert(e);
		}
    	req.send(null);
   		} else if (window.ActiveXObject) { // IE
    		req = new ActiveXObject("Microsoft.XMLHTTP");
     		if (req) {
       			req.onreadystatechange = processStateChange;
       			req.open("GET", url, true);
       			req.send();
     		}
   		}
   	}
}

  function processStateChange() {
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response
      	var omResponseDiv = document.getElementById("omResponse");
        omResponseDiv.innerHTML = req.responseText;
        omResponseDiv.style.visibility='visible';
        omResponseDiv.style.display='block';
		omResponseDiv.scrollTop = omResponseDiv.scrollHeight; 
        setTimeout("retrieveURL('requestStateForUser.do')",100);
        
        //alert(req.responseText);
      } else {
        alert("Problem: " + req.statusText);
      }
    }
  }
 
function retrieveURLCancelButton(url) {
	if (window.XMLHttpRequest) { // Non-IE browsers
		reqCancelButton = new XMLHttpRequest();
    	reqCancelButton.onreadystatechange = processStateChangeCancel;
    	try {
	    	reqCancelButton.open("GET", url, true);
		} catch (e) {
	    	alert(e);
		}
    	reqCancelButton.send(null);
   		} else if (window.ActiveXObject) { // IE
    		reqCancelButton = new ActiveXObject("Microsoft.XMLHTTP");
     		if (reqCancelButton) {
       			reqCancelButton.onreadystatechange = processStateChangeCancel;
       			reqCancelButton.open("GET", url, true);
       			reqCancelButton.send();
     		}
   		}
}

  function processStateChangeCancel() {
    if (reqCancelButton.readyState == 4) { // Complete
      if (reqCancelButton.status == 200) { // OK response     
      	var cancelButtonTarget = document.getElementById("cancelButtonTarget");
        cancelButtonTarget.innerHTML = reqCancelButton.responseText;
      } else {
        alert("Problem: " + req.statusText);
      }
    }
  }  
