/*
* Load popup 
* copyright Cetus
* author 
*/
		  
var tb_pathToImage = "images/loadingAnimation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox, div.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});


//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = null;
	var a = this.id || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(title, url, imageGroup) {//function called when the user clicks on a thickbox link
	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6			
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'></div>");//add loader to the page
		$('#TB_load').show();//show loader		
		
		TB_WIDTH = 220;
		TB_HEIGHT = 120;
		tb_showIframe();
		tb_position();
		if(0 === 0){//code to show html			
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;		
			var warningContent = "Xin lưu ý đây chỉ là thông tin tham khảo dành cho cán bộ y tế. Vui lòng click xác nhận nếu là cán bộ y tế và có nhu cầu tìm hiểu thêm thông tin sản phẩm.";
			var caption = 'Trước khi bạn tiếp tục...';		
			/* Show title and content of warning*/
					if($("#TB_window").css("display") === "block"){						
						if(0 === 0){//ajax no modal
						$("#TB_window").append("<div id='TB_ajaxWindowTitle'>"+caption+"</div><img src='images/cross.png' onclick='tb_remove();' style='cursor:pointer;float:right;padding:15px 15px 5px 5px;'/><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'>"+warningContent+"</div><div id='TB_closeAjaxWindow'><input type='button' value='Xác nhận' onclick='tb_go2NewWindow("+url+");' style='width:80px'/> <input type='button' value='Trở về'onclick='tb_remove();' style='width:80px'/></div>");					
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}			
//			$("#TB_closeWindowButton").click(tb_remove);
//			$("#TB_openWindowButton").click(tb_go2NewWindow);
			document.onkeyup = function(e){   
			if (e == null) { // ie
			  		keycode = event.keyCode;
			} else { // mozilla
			  		keycode = e.which;
			}
			if(keycode == 27){ // close
			  		tb_remove();
			}  
		  };
		}		
		
	} catch(e) {
		//nothing here
	}
}

/********************************************************/
//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

/*Redirect to others page*/
function tb_go2NewWindow(url){
	if(url == 1){	
		document.location.href = 'meiji_gold1.php';
	}else{
		document.location.href = 'meiji_gold2.php';
	}
}

/*Remove all setting */
function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}
/*position view on x,y desktop */
function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}
/*verify type of brownser*/
function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


