function showPopup (page,width,height,resizeable,scrollbars) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('"+page+"', '" + id + "', 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizeable+',width="+width+",height="+height+"');");
};

function checkIE6 () {
	var Browser = {
	  Version: function() {
	    var version = 999; // we assume a sane browser
	    if (navigator.appVersion.indexOf("MSIE") != -1)
	      // bah, IE again, lets downgrade version number
	      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	    return version;
	  }
	}
	if (Browser.Version() < 7) {
	  document.getElementById('warning_ie6').style.display='block';
	}
}



function showDeliveryAddress (check) {
	var x = document.getElementById ('delivery_address');

	if (check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";
	}
	else {
		x.style.visibility = "hidden";
		x.style.display = "none";
	}		
}



function showPayType (check, idx) {
	var x = document.getElementById ('pay_type_'+idx);

	if (x && check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";		
	}

	for (var i=1;i<10;i++) {
		if (i==idx)
			continue;
		x = document.getElementById ('pay_type_'+i);
		if (x) {
			x.style.visibility = "hidden";
			x.style.display = "none";
		}
	}	
}



/* Ajax popup window stuff */
popupWindowId = '';

function showPopupWindowFilter () {	
	if (WSystem.ieVersion<7) {
		var filterHeight  = jQuery(document).height()-4;
		if (filterHeight<jQuery(window).height())
			filterHeight = jQuery(window).height();
		jQuery('#popupWindowFilter').attr('style', 'position:absolute;left:0;top:0;display:block;width:100%;height:'+filterHeight+'px;');	
	}
	else
		jQuery('#popupWindowFilter').attr('style', 'position:fixed;left:0;top:0;display:block;width:100%;height:100%;');	
	jQuery('#popupWindowFilter').hide();	
	jQuery('#popupWindowFilter').show();	
}

function hidePopupWindowFilter () {
	jQuery('#popupWindowFilter').hide();	
}

function closePopupWindow ()
{
	var obj = document.getElementById (popupWindowId);
	if (obj) {

		
		obj.style.display="none";
		obj.style.visibility = "hidden";

		hidePopupWindowFilter ();	
		WSystem.removeEvent (document,'keyup', onDocumentKeyPress);
		WSystem.removeEvent (document,'mousedown', onDocumentMouseClick);
	}
}

function onDocumentKeyPress (evt) {
	var keyCode = evt.which;
	if (navigator.appName.indexOf("Microsoft")!=-1)
		keyCode = window.event.keyCode;
	if (keyCode==27) { // ESC
		closePopupWindow ();
	}
	return true;
}

this.onDocumentMouseClick = function (evt)  {
	var mouseCoords = WSystem.getMouseCoords (evt);
	var obj = document.getElementById (popupWindowId);
	if (obj) {
		popupCoords = WSystem.getAbsoluteCoords (obj);
		var x  = popupCoords.x;
		var y  = popupCoords.y;
		var x2 = popupCoords.x+parseInt (obj.offsetWidth);
		var y2 = popupCoords.y+parseInt (obj.offsetHeight);
		if (!(
				mouseCoords.x>x && 
		    mouseCoords.x<x2 && 
		    mouseCoords.y>y && 
		    mouseCoords.y<y2 )) {
			// closePopupWindow ();
		}				
	}		
}

function showPopupWindow (id, popupURL, fAutoPrint) {
	var obj = document.getElementById (id);
	if (!obj)
		return;
	
	toggleFlag = true;
	currObjectImgIdx = 0;
	popupWindowId = id;
	var scrollPos = WSystem.getScrollPos ();
	var wndDim		= WSystem.getWindowDim ();
	var wndHeight = wndDim.windowHeight;
	var wndWidth  = wndDim.windowWidth;
	
	var x0 = scrollPos.x;			
	var x1 = x0 + wndWidth;
	var y0 = scrollPos.y;	
	var y1 = y0 + wndHeight;
	
  showPopupWindowFilter ();		
	obj.style.display="block";			


	obj.style.left = (x0+(wndWidth  - parseInt (obj.offsetWidth))  /2)+"px";
	obj.style.top  = (y0+(wndHeight - parseInt (obj.offsetHeight)) /2)+"px";
	
	obj.style.visibility = "visible";	

	// Esc key functions
	WSystem.addEvent (document,'keyup', onDocumentKeyPress, false);
	WSystem.addEvent (document,'mousedown', onDocumentMouseClick, false);

	// Load ajax content
	var fullURL = window.location.protocol+"//"+document.domain+"/"+popupURL;
	if (popupURL!='') {
		jQuery('#'+id+'_content').html ('<div style="text-align:center;"><img src="images/progress.gif" /></div>');
		jQuery.ajax({ url: fullURL, success: function(data) {
		
		
			jQuery('#'+id+'_content').html (data); 			
			
			if (jQuery('#'+id+'_content')) {
				jQuery('#'+id+'_content').jScrollPane({scrollbarWidth: 10, dragMaxHeight:120, scrollbarMargin:20 });			
			}
			
			if (fAutoPrint) {
				window.print ();
				closePopup ();
			}
		}});
	}
}



// Document loaded

$(document).ready(function() {  

	$('#focus_id').focus ();
/*
	
	$(window).resize(function () {
			closePopupWindow ();

	});  
*/       
});

