// Browser safe opacity handling function

function setOpacity( value ) {
 document.getElementById("gtce_popup").style.opacity = value / 10;
 document.getElementById("gtce_popup").style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInPopup() {
 for( var i = 0 ; i <= 100 ; i++ )
   setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
   
  	document.getElementById("popup_close").focus();
}

function fadeOutPopup() {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
 }

 setTimeout('closePopUp()', 800 );
}

function closePopUp() {
    //check if form is https
    //if so, change back to http
    var prefix = window.location.protocol;
    if(prefix == "https:")
    {	
        var pageURL = window.location.hostname + window.location.pathname;
        var newURL = "http://" + pageURL;
        window.location = newURL;
	}
    document.getElementById("gtce_popup").style.display = "none";
}

function openPopUp(title, message, icon) {
	
	//display the pop window
 	document.getElementById("gtce_popup").style.display = "block";
 	
 	//set the title
 	document.getElementById("popup_title").innerHTML = title;
 	
 	//set the message
 	document.getElementById("popup_message").innerHTML = message;

 	//set the icon
 	/*if(icon != null)
 	{
 		var imageIcon = document.getElementById("popup_icon");
 		
 		switch(icon)
		{
		case "help":
		  imageIcon.src = "/images/popup/help.gif";
		  break;    
		case "info":
		  imageIcon.src = "/images/popup/info.gif";
		  break;
		case "error":
		  imageIcon.src = "/images/popup/error.gif";
		  break;
		default:
		  imageIcon.src = "/images/popup/help.gif";
		}
 	}*/
 	
 	setOpacity( 0 );
 	fadeInPopup();
 	


 	return false;
} 

function openSSLPopUp(title, message, icon) {

	//test if page is https
	var prefix = window.location.protocol;
	if(prefix == "http:")
	{	
		var pageURL = window.location.href;
		var paramStartPos = pageURL.indexOf ("?");
		var oldURL = window.location.hostname + window.location.pathname;
		if ( paramStartPos == -1 ) 
		{
			oldURL = oldURL + "?displaypopup=true";
		}
		else
		{
			oldURL = oldURL + pageURL.substring(paramStartPos) + "&displaypopup=true";
		}
		var newURL = "https://" + oldURL;
		window.location = newURL;
	}
	else
	{	
		//display the pop window
	 	document.getElementById("gtce_popup").style.display = "block";
	 	
	 	//set the title
	 	document.getElementById("popup_title").innerHTML = title;
	 	
	 	//set the message
	 	document.getElementById("popup_message").innerHTML = message;
	
	 	//set the icon
	 	/*if(icon != null)
	 	{
	 		var imageIcon = document.getElementById("popup_icon");
	 		
	 		switch(icon)
			{
			case "help":
			  imageIcon.src = "/images/popup/help.gif";
			  break;    
			case "info":
			  imageIcon.src = "/images/popup/info.gif";
			  break;
			case "error":
			  imageIcon.src = "/images/popup/error.gif";
			  break;
			default:
			  imageIcon.src = "/images/popup/help.gif";
			}
	 	}*/
	 	
	 	setOpacity( 0 );
	 	fadeInPopup();
 	}


 	return false;
}


