function pops_shell(id, content, title, _top, _left, _width, _height) {
	if (! _width) {
		var _width = 200;
	}
	if (! _height) {
		var _height = 200;
	}
	if (! _top) {
		var _top = 0;
	}
	if (! _left) {
		var _left = 0;
	}
	var div = document.createElement('div');
	var div_start = "<div id=\""+id+"\" style=\"background-color: white; z-index: 2; width: " + _width + "px; height: " + _height + "px; padding: 0px; margin: 0px; border: 2px solid black; position: absolute; top: " + _top + "px; left: " + _left + "px;\">";
	// title with closerer
	div_start += '<div style="width: 100%; height: 26px; background: #1c71ff; border-bottom: 2px solid black;" id="'+id+'_title_bar">';

	div_start += '<div style="width: 22px; height: 22px; float: right; margin-right: 2px; margin-bottom: 2px; margin-top: 2px;"><a href="javascript: ;" onclick="pops_close(\''+id+'\');" class="x"><img src="/images/x.png" border="0" width="22px" height="22px" /></a></div>';
	div_start += '<div id="'+id+'_title" style="line-height: 22px; width: '+(_width-30)+'px; color: #ffffff; font-size: 14px; font-weight: bold; '+ (_width - 30) +'px; height: 22px; float: left; margin-top: 4px; margin-left: 5px; overflow: hidden;">'+title+'</div>';

	div_start += '</div>';
	// inner content
	div_start += '<div style="overflow: auto; margin: 2px; padding: 0px; width: 100%; height: 100%;" id="' + id + '_text" name="' + id + '_text">';
	div.innerHTML = div_start + content + "</div></div>";
	if (!document.getElementById(id)) {
		document.body.appendChild(div.firstChild);
		var title = document.getElementById(id+'_title_bar');
		title.onmousedown = pops_register_mouse_ud;
		title.onmouseup = pops_register_mouse_ud;
		//title.onmousemove = pops_register_mouse_move;
		pops_title_adjust_size(id);
		return true;
	}
	return false;
}

function pops_center_screen(id) {
	var offsetY = 0;
	var offsetX = 0;
	if (window.pageYOffset) {
		offsetY = window.pageYOffset;
		offsetX = window.pageXOffset;
	} else {
		offsetY = document.body.scrollTop;
		offsetX = document.body.scrollLeft;
	}
	if (offsetY == 0 && document.documentElement.scrollTop > 0) {
		offsetY = document.documentElement.scrollTop;
		offsetX = document.documentElement.scrollLeft;
	}
	var elm = document.getElementById(id);
	if (elm) {
		var t = elm.style.height.split(/px/);
		elm.style.top = Math.round(((window.innerHeight ? window.innerHeight : document.documentElement.clientHeight) / 2) - (t[0] / 2) + offsetY) + 'px';
		var t = elm.style.width.split(/px/);
		elm.style.left = Math.round(((window.innerWidth ? window.innerWidth : document.documentElement.clientWidth) / 2) - (t[0] / 2) + offsetX) + 'px';
	}
}

function pops_title_adjust_size(id) {
	var elm = document.getElementById(id);
	var elm_title = document.getElementById(id + '_title');
	if (elm && elm_title) {
		var w = elm.style.width.split(/px/);
		elm_title.style.width = (w[0] - 30) + 'px';
	}
}

var pops_register_state = false;
var pops_register_whats_moving = null;
var start_x = 0;
var start_y = 0;
function pops_register_mouse_ud(e) {
	var state = false;
	var from = null;
	if (document.all) {
		pops_register_state = event.button == 1 ? true : false;
		from = event.srcElement.id;
		start_x = event.clientX + document.body.scrollLeft;
		start_y = event.clientY + document.body.scrollTop;
	} else {
		start_x = e.pageX;
		start_y = e.pageY;
		pops_register_state = e.button == 0 ? true : false;
		from = e.target.id;
	}
	pops_register_whats_moving = (pops_register_state == true ? from : null);
}

function pops_register_mouse_move(e) {
	var tempX = 0;
	var tempY = 0;
	var mouse = null;
	var from = null;
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
		mouse = event.button == 1 ? true : false;
		from = event.srcElement.id;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
		mouse = e.button == 0 ? true : false;
		from = e.target.id;
	}


	if (pops_register_whats_moving == from && pops_register_state && mouse) {
		var t = from.split(/_title_bar/);
		var elm = document.getElementById(t[0]);
		document.title = (tempX - start_x) + ' + ' + document.body.clientWidth + '      ' + (tempY - start_y) + ' + ' + document.body.clientHeight ;
		y = (tempY - start_y);
		if (y < 5) {
			y = 5;
		}
		x = (tempX - start_x);
		if (x < 5) {
			x = 5;
		}

		elm.style.top = y + 'px';
		elm.style.left = x + 'px';
	} else {
		pops_register_state = false;
		pops_register_whats_moving = null;
	}
}

function pops_close(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).innerHTML = '';
		document.body.removeChild(document.getElementById(id));
	}
}

function pops_shell_image(img_src, title, base_url) {
	if (img_src.match('http') != null) {
		var base_url = '';
	}
	else if (! base_url) {
		var base_url = 'http://www.promoproductscentral.com/images/products/';
	}
	
	var loading_image = '/images/loading.gif';
	var width = 130; // loading image width (120) + a bit
	var height = 160; // loading image width (120) + a bit
	var id = img_src.replace(/[.]|[ ]|[\/]/g, '_');
	var max_width = (window.innerWidth ? window.innerWidth : screen.availWidth) - 50;
	var max_height = (window.innerHeight ? window.innerHeight: document.documentElement.clientHeight) - 100;
	var content = '<center><img src="'+loading_image+'" border="0" id="'+id+'_loading" /><img src="'+base_url + img_src +'" border="0" id="'+id+'_image" style="display: none;" /></center>';
	if (pops_shell(id + '_pop', content, title, null, null, width, height)) {
		pops_center_screen(id + '_pop');
		document.getElementById(id + '_image').onload = function() {
			var r_image = document.getElementById(id + '_image');
			document.getElementById(id + '_loading').style.display = 'none';
			document.getElementById(id + '_pop').style.width = (r_image.width + 50) + 'px';
			document.getElementById(id + '_pop').style.height = (r_image.height + 40) + 'px';
			r_image.style.display = '';
			if (r_image.width > max_width) {
				r_image.width = max_width;
			}
			if (r_image.height > max_height) {
				r_image.height = max_height;
			}
			document.getElementById(id + '_pop').style.width = (r_image.width + 15) + 'px';
			document.getElementById(id + '_pop').style.height = (r_image.height + 40) + 'px';
			pops_title_adjust_size(id + '_pop');
			pops_center_screen(id + '_pop');
		};
	}
}

function pops_shell_iframe(id, src, title, _top, _left, _width, _height) {
	if (! _width) {
		var _width = 200;
	}
	if (! _height) {
		var _height = 200;
	}
	return pops_shell(id, '<iframe src="'+src+'" width="'+(_width - 10)+'" height="'+(_height - 30)+'" frameborder="0" id="'+id+'_iframe"></iframe>', title, _top, _left, _width, _height);
}

var POPS_SPECIAL_QUOTEREQUEST		= 0;
var POPS_SPECIAL_HELPMEFINDIT		= 1;
var POPS_SPECIAL_SAMPLEREQUEST		= 2;
var POPS_SPECIAL_TELLAFRIEND		= 3;
var POPS_SPECIAL_SENDARTWORKSPECS	= 4;
var POPS_SPECIAL_TELLUS			= 5;
var POPS_SPECIAL_PRODUCTREVIEWADDPOP	= 6;

var POPS_SPECIAL_ID	= 0;
var POPS_SPECIAL_SRC	= 1;
var POPS_SPECIAL_TITLE	= 2;
var POPS_SPECIAL_WIDTH	= 3;
var POPS_SPECIAL_HEIGHT	= 4;

var pops_special_pop_option_array = new Array();

pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST][POPS_SPECIAL_ID]	= 'quote_request_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST][POPS_SPECIAL_SRC]	= '/request_quote.php';
pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST][POPS_SPECIAL_TITLE]	= 'Quote Request Cart';
pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_QUOTEREQUEST][POPS_SPECIAL_HEIGHT]	= 500;

pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT][POPS_SPECIAL_ID]	= 'help_me_find_it_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT][POPS_SPECIAL_SRC]	= '/help_me_find.php';
pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT][POPS_SPECIAL_TITLE]	= 'Help Me Find It';
pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_HELPMEFINDIT][POPS_SPECIAL_HEIGHT]	= 500;

pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST][POPS_SPECIAL_ID]	= 'sample_request_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST][POPS_SPECIAL_SRC]	= '/sample_request.php';
pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST][POPS_SPECIAL_TITLE]	= 'Request A Sample';
pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_SAMPLEREQUEST][POPS_SPECIAL_HEIGHT]	= 500;

pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND][POPS_SPECIAL_ID]	= 'tell_a_friend_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND][POPS_SPECIAL_SRC]	= '/tell_a_friend.php';
pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND][POPS_SPECIAL_TITLE]	= 'Tell A Friend';
pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_TELLAFRIEND][POPS_SPECIAL_HEIGHT]	= 500;

pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS][POPS_SPECIAL_ID]		= 'send_artworkspecs_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS][POPS_SPECIAL_SRC]		= '/send_artworkspecs.php';
pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS][POPS_SPECIAL_TITLE]	= 'Email Art Work Specifications To A Colleague';
pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_SENDARTWORKSPECS][POPS_SPECIAL_HEIGHT]	= 240;

pops_special_pop_option_array[POPS_SPECIAL_TELLUS] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_TELLUS][POPS_SPECIAL_ID]	= 'tell_us_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_TELLUS][POPS_SPECIAL_SRC]	= '/tell_us.php';
pops_special_pop_option_array[POPS_SPECIAL_TELLUS][POPS_SPECIAL_TITLE]	= 'Tell Us';
pops_special_pop_option_array[POPS_SPECIAL_TELLUS][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_TELLUS][POPS_SPECIAL_HEIGHT]	= 500;

pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP] = new Array();
pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP][POPS_SPECIAL_ID]	= 'product_review_add_pop_php_pop';
pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP][POPS_SPECIAL_SRC]	= '/product_review_add_pop.php';
pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP][POPS_SPECIAL_TITLE]	= 'Add A Product Review';
pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP][POPS_SPECIAL_WIDTH]	= 400;
pops_special_pop_option_array[POPS_SPECIAL_PRODUCTREVIEWADDPOP][POPS_SPECIAL_HEIGHT]	= 350;

function pops_special_pop_get_id(src) {
	for (var i=0; i < pops_special_pop_option_array.length; i++) {
		if (pops_special_pop_option_array[i][POPS_SPECIAL_SRC] == src) {
			return i;
		}
	}
	return (-1);
}

function pops_special_pop_close(which) {
	pops_close(pops_special_pop_option_array[which][POPS_SPECIAL_ID]);
}

function pops_special_pop(which, getline) {
	if (!getline) {
		var getline = '';
	}
	var width = pops_special_pop_option_array[which][POPS_SPECIAL_WIDTH];
	var height = pops_special_pop_option_array[which][POPS_SPECIAL_HEIGHT];
	var id = pops_special_pop_option_array[which][POPS_SPECIAL_ID];
	var src = pops_special_pop_option_array[which][POPS_SPECIAL_SRC] + getline;
	var title = pops_special_pop_option_array[which][POPS_SPECIAL_TITLE];
	if (pops_shell_iframe(id, src, title, null, null, width, height)) {
		pops_center_screen(id);
	}
}

