/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var loading=0;

function loadPopup(url, width, height){

		loading=1;
	$('<div id="popupContent"><div class="popHeader"><a href="javascript:disablePopup();"><img src="/images/closew.png" border="0" hspace="8" align="absmiddle">Close</a></div><iframe id="my_frame" onload="showPopup('+ width + ',' + height +')" name="my_iframe' + Math.round(Math.random()*1000) + '" frameborder="0" hspace="0" scrolling="auto" width="'+ width+'" height="' + height + '" src="' + url + '"></iframe><div id="popupFooter"></div></div><div id="backgroundPopup"></div>').appendTo("body");
   
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});		
	
}

//loading popup with jQuery magic!
function showPopup(width, height){
	//loads popup only if it is disabled
	
	if(popupStatus==0){
		popupStatus = 1;
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		$("#loadingPop").remove();		
		centerPopup(width, height);
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContent").fadeIn("slow");
		
		
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		popupStatus = 0;
		loading=0;
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContent").fadeOut("slow", function() {
		$("#popupContent").remove();			
		});
		
	}
}

//centering popup
function centerPopup(width, height){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupHeader").height() + $("#popupFooter").height() + height;
	var popupWidth = width+40;
	var theBody = document.getElementsByTagName("BODY")[0];
		
	//theBody.style.overflow = "hidden";
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(theBody.scrollLeft,10);
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
			
	//centering
	$("#popupContent").css({
		"position": "absolute",
		"top": (scTop + ((fullHeight - (popupHeight+10)) / 2)),
		"left":(scLeft + ((fullWidth - popupWidth) / 2))
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function showLoading(x,y){
	
	$('<div id="loadingPop"></div>').appendTo("body");
	$('#loadingPop').html('<span class="loadingInfo"><img src="/_common/img/smallLoading.gif" hspace="10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loading Information..</span>');
	$("#loadingPop").css({
		"position": "absolute",
		 "z-index":1,
		"top": y+20,
		"left":x-120
	});
}


function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}

function getCalculator(width,height){ 
f = document.calcForm
metal = f.metal.value; 
amount = f.amount.value;
units = f.units.value;
refreshP =0;
var url='/calculator.php?refreshP='+refreshP + '&unit='+units+'&amount='+amount+'&metal='+ metal +'&random='+ Math.round(Math.random()*1000);
loadPopup(url,width,height);
return false;
}

function getImg(src,width,height){
var url=src +'?random='+ Math.round(Math.random()*1000);
loadPopup(url,width,height);
}

function getQuote(){
width=800;
height=600;
var sym = document.sinfo.ticker.value;
if(sym=='Enter Symbol'){
        url='http://caseyresearch.stockgroup.com/sn_symbollookup.asp?search=yes';
}else{
url='http://caseyresearch.stockgroup.com/sn_overview.asp?ticker=' + sym;
}
loadPopup(url,width,height);
return false;
}

function getSymbol(){
width=800;
height=600;
url='http://caseyresearch.stockgroup.com/sn_symbollookup.asp?search=yes';
loadPopup(url,width,height);
} 

