function ShowPopUp(strDivName)
{
	try{
		var objDiv = document.getElementById(strDivName);
		var diffHeight=(document.documentElement.scrollHeight/2)-document.documentElement.scrollTop;
		objDiv.style.display = "inline";
		var obj_width = getWinWidth()/2 - objDiv.offsetWidth/2;
		if (obj_width < 0)
		    obj_width = 0;
		objDiv.style.left= obj_width +'px';
		$(objDiv).show();
		resizeOverlay();
	}
	catch(e){}
	return false;
}

function resizeOverlay(){
	var overlay = $('#overlay');
	var dw = Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth);
	var dh = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight);
	overlay.width(dw);
	overlay.height(dh);
	overlay.show();	
}

function getWinWidth()
{
    if (window.innerWidth)
    {
    	w = window.innerWidth;
    	if (document.body.scrollHeight && document.body.scrollHeight >= getWinHeight())
    		w-=15;
    	return w;
    }
    else if (document.documentElement && document.documentElement.clientWidth) 
  		return document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		return document.body.clientWidth;
  	else if (document.body && document.body.parentNode && document.body.parentNode.clientWidth) 
 		return document.body.parentNode.clientWidth;
}

function getWinHeight()
{
    if (window.innerHeight) return window.innerHeight;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		return document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		return document.body.clientHeight;
  	else if (document.body && document.body.parentNode && document.body.parentNode.clientHeight) 
  		return document.body.parentNode.clientHeight;
}
function ShowOverlay()
{
	$('#overlay').show(); 
}

function HideOverlay()
{
	$('#overlay').hide();
}

function CloseProductImagePopUp(DivName){
	$('#' + DivName).hide();
	$('#overlay').hide();
}

function change_setting(){
	return confirm("Changing your setting will delete your selection. Are you sure you want to do this?");
}

function change_diamonds(){
	return confirm("Changing your diamonds will delete your selection. Are you sure you want to do this?");
}

function change_diamond(){
	return confirm("Changing your diamond will delete your selection. Are you sure you want to do this?");
}

function show_similar(){
	// This is used for diamond similar tab and setting related tab.
	if($('#similar_tab_detail').is('.active')) {
	$('#similar_tab_detail').removeClass('active');
	$('#similar_tab_similar').addClass('active');
	$('#similar_div_detail').hide();
	$('#similar_div_similar').show();
	}
}

function show_detail(){
	// This is used for diamond similar tab and setting related tab.
	if($('#similar_tab_similar').is('.active')){
		$('#similar_tab_detail').addClass('active');
		$('#similar_tab_similar').removeClass('active');
		$('#similar_div_detail').show();
		$('#similar_div_similar').hide();
    }
}

function get_print_url(){
	var cur_url = location.href;
	var pattern = /[^#]+/
	var res = cur_url.match(pattern);
	if (res) {
		cur_url = res[0]
	}
	if (cur_url.indexOf('?') >= 0) {
		return cur_url + '&print=True';
	} else {
		return cur_url + '?print=True';
	}
}

function changepic(img_id, img, dict) {
	/* replace img_id div with img, and traverse dict replace dict key div with dict value src.*/
	$("#" + img_id).attr("src", img);
	try{
		for (var id in dict) {
			$("#" + id).children("img").attr("src", dict[id]);
		}
	}
	catch(e){}
}
