/* CartWorks.com Popup Static Pages */
var psp_cached_img_loader = null;
var alt_post_params = null;
var txt = '';


function psp_myFinish( cacheElem ){
	var imgs = document.getElementsByTagName("img");
	for(var i=0; i<imgs.length; i++){
		if (imgs[i].id.search('upsell_img_'!= -1)) {
			imgs[i].style.display='';
		}
	}
} 

function psp_f_scrollTop() {
	return psp_f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function psp_f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function open_dyn_page_popup(pageid) {

var req = new Subsys_JsHttpRequest_Js();
req.onreadystatechange = function() {
	if (req.readyState == 4) {
		if (req.responseJS != null && req.responseJS[0] != null) { 
			if (req.responseJS[0]) {  
				txt = req.responseJS[0]['static_page_content'];  
				document.getElementById('static_page_popup_div').innerHTML = txt;	
				document.getElementById('static_page_popup_div').style.display = 'block';

				if (static_page_popup_in_shadowbox) {
					var sh_box_height = document.getElementById('static_page_popup_div').offsetHeight;
	
					document.getElementById('static_page_popup_div').style.display = 'none';
					document.getElementById('static_page_popup_div').innerHTML = '';
	    				Shadowbox.open({
        					player:		'html',
						content:	txt,
						options:	{displayNav: false, onFinish : psp_myFinish}, 
						height:		sh_box_height,	
        					width:      	390 
    					});
				} else {
		            		m_psp_left = (document.body.clientWidth-400)/2;
	            			document.getElementById('static_page_popup_div').style.left = m_psp_left+"px";
				
		          		m_psp_top = 30 + psp_f_scrollTop();
        	    			document.getElementById('static_page_popup_div').style.top = m_psp_top+"px";
				}
			} else {
				document.getElementById('static_page_popup_div').innerHTML = '';
				document.getElementById('static_page_popup_div').style.display = 'none';
			}
	        } else {
        		document.getElementById('static_page_popup_div').innerHTML = '';
            		document.getElementById('static_page_popup_div').style.display = 'none';
        	}		
	}
}

	var post_params = [];

	if (alt_post_params != null) {
		post_params = alt_post_params;
		alt_post_params = null;
	} else {
		post_params = {ajaxmode:'Y', pageid:pageid};
	}

	if (psp_cached_img_loader != null) {
        	document.getElementById('static_page_popup_div').innerHTML = psp_cached_img_loader;
	} else {
        	psp_cached_img_loader = document.getElementById('static_page_popup_div').innerHTML;
	}

	if (!static_page_popup_in_shadowbox) { 
		document.getElementById('static_page_popup_div').style.display = 'block';
		m_psp_left = (document.body.clientWidth-400)/2;
		document.getElementById('static_page_popup_div').style.left = m_psp_left+"px";
		m_psp_top = 30 + psp_f_scrollTop(); 
		document.getElementById('static_page_popup_div').style.top = m_psp_top+"px";
	}

	req.caching = false;
	req.open('POST', 'popup_static_page.php', true);
	req.send(post_params);
}

//mouse down on dragged DIV element
function psp_startdrag(t, e) {
	if (e.preventDefault) e.preventDefault(); //line for IE compatibility
	e.cancelBubble = true;
	window.document.onmousemoveOld = window.document.onmousemove;
	window.document.onmouseupOld = window.document.onmouseup;
	window.document.onmousemove=psp_dodrag;
	window.document.onmouseup=psp_stopdrag;
	window.document.draged = t;
	t.dragX = e.clientX;
	t.dragY = e.clientY;
	return false;
}
//move the DIV
function psp_dodrag(e) {

	if (!e) e = event; //line for IE compatibility
	t = window.document.draged;
	t.style.left = (t.offsetLeft + e.clientX - t.dragX)+"px";
	t.style.top = (t.offsetTop + e.clientY - t.dragY)+"px";

	t.dragX = e.clientX;
	t.dragY = e.clientY;
	return false;
}
//restore event-handlers
function psp_stopdrag() {
   window.document.onmousemove=window.document.onmousemoveOld;
   window.document.onmouseup=window.document.onmouseupOld;
}
/* CartWorks.com Popup Static Pages */

