﻿var isIE = document.all;
/**********************************************************/
/* Insert IFRAME Control to TablrRow
/* Dynamic insert a table row bellow which contain a IFRAME
/**********************************************************/
function jsAddIFRAME(srcURL,h) {
	//-- Remove old frame
	var LastIF = document.all('IFEditing');
	if (LastIF!=null) {
		var TD = LastIF.parentElement;
		var TR = TD.parentElement;
		for (var TABLE=TR;TABLE.tagName!='TABLE';TABLE=TABLE.parentElement);
		TABLE.deleteRow(TR.rowIndex);
		if (window.LastIFEditingEvent==event.srcElement) return false;
	}
	//-- Now add new frame
	var OBJ = event.srcElement;
	for (var TR=OBJ;TR.tagName!='TR';TR=TR.parentElement);
	for (var TABLE=TR;TABLE.tagName!='TABLE';TABLE=TABLE.parentElement);
	var nextTR = TABLE.insertRow(TR.rowIndex+1);
	var TD = nextTR.insertCell();
	TD.colSpan = TR.cells.length;
	var s = '<iframe id="IFEditing" width="100%"';
	if (h!=null) s = s + ' height="' + h + '"';
	s = s + ' src=\"'+srcURL+'\"></iframe>';
	TD.innerHTML = s;
	window.LastIFEditingEvent = event.srcElement;
	return false;
}
//-- For frame window call only
function jsRemoveIFRAME() {
	var p = parent;
	var LastIF = p.document.all('IFEditing');
	if (LastIF!=null) {
		var TD = LastIF.parentElement;
		var TR = TD.parentElement;
		for (var TABLE=TR;TABLE.tagName!='TABLE';TABLE=TABLE.parentElement);
		TABLE.deleteRow(TR.rowIndex);
	}
	return false;
}
function getObj(id){
	var d = document;
	return d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id]
}
function getElement(evt){
	return (document.all?evt.srcElement:evt.target);
}

/***************************************************************/
/* MENU
/***************************************************************/
var _allowHide = false;
var _showPopup = false;
function ProductView(ID,Lang){
	var Url = AppPath + 'popup.aspx?ctrl=productdetail&productid=' + ID + '&scroll=no&lang=' + Lang;
	OpenDefine2(Url,615,350);
}
function AddToCart(item, ID){
	FBasket.location.href = "basket.aspx?ID=" + ID;
	item.style.visibility = "hidden";
}
/***************************************************************/
/* MENU
/***************************************************************/
function goTo( url ) {
	window.location.href = url;
}
function MenuBar(tableCellRef, hoverFlag, menuPopup) {
	if (hoverFlag) {
		tableCellRef.style.color  = 'red';
		tableCellRef.style.cursor = 'hand';
		if (menuPopup != 0){
			MenuOver(tableCellRef, "divMenu"+menuPopup);
		}
	} else {
		tableCellRef.style.color = '';
		if (menuPopup != 0){
			MenuOut();
		}
	}
}
function MenuBarClick(tableCellRef, navStyle, url) {
	MenuBar(tableCellRef, 0, navStyle);
	goTo(url);
}
function LBLClick(Url, Width, Height, Name){
   if (Name == null) Name = "DefaultWindow";
   var Options = "height=" + Height + ",width=" + Width + ",center=yes,menubar=no,resizable=no,status=no,toolbar=no,";
   window.open(Url,Name,Options,true); 
   return false;
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function GetParentElement(e,tagName) {
	var newE = e;
	for (; (newE.tagName!=tagName)||(newE==null); newE = newE.parentElement);
	return newE;
}
function MenuOver(item, menuValue){
	var objDiv = document.getElementById("divMenu");
	if (objDiv == null) return;
	objDiv.style.left = event.x + 165 - event.offsetX - 5;
	objDiv.style.top  = event.y + ietruebody().scrollTop - event.offsetY;
	objDiv.style.visibility = "visible";
	window.execScript("var Value = " + menuValue + ";");
	objDiv.innerHTML  = Value;
}
function MenuOut(){
	var obj = document.elementFromPoint(event.x,event.y);
	while(obj != null){
		if (obj.tagName == "DIV"){
			if (obj.id == "divMenu") break;
		}
		obj = obj.parentElement;
	}
	if (obj != null){
		if (obj.id == "divMenu") return;
	}
	var objDiv = document.getElementById("divMenu");
	if (objDiv == null) return;
	objDiv.style.visibility = "hidden";
}
function Search(item, App){
	var obj = document.getElementById(item);
	if (obj != null){
		goTo(App + 'search/default.aspx?q='+obj.value);
	}
}
/***************************************************************/
/* VOTE
/***************************************************************/
function VoteCheck(item){
   var obj = document.getElementsByName("VoteSelect");
   if (obj.value == null) obj.value = "";
   var voteid = "(" + item.id.replace("rdo","") + ")";
   var values = obj.value;
   values = values.replace(voteid,"");
   if (item.checked) values += voteid;
   obj.value = values;
}
function VotePopup(Url, Width, Height, Name, Msg){
   if (Msg != ""){
	  var obj = document.getElementsByName("VoteSelect");
      if ((obj.value == null)||(obj.value == "")){
         alert(Msg);
         return false;
      }
      Url += "&select=" + obj.value;
   }
   if (Name == null) Name = "DefaultWindow";
   var Options = "height=" + Height + ",width=" + Width + ",center=yes,menubar=no,resizable=no,status=no,toolbar=no,";
   window.open(Url,Name,Options,true);
   return false;
}

/***************************************************************/
/* POPUP OPEN IMAGE
/***************************************************************/
// www.lpts.org
function popupImage(srcURL,width,height){
   openImageNews(srcURL,height,width);
}
// VnExpress
function openImage(obj,h,w) {
	openImageNews(obj, h, w);
	return false;
}
//TuoiTre Online
function TuoiTreImage(srcURL){
	openImageNews(srcURL, 0, 0);
	return false;
}
function openImageNews(vLink, vHeight, vWidth){
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	var sc = (vHeight==0||vWidth==0)?('yes'):('no');
	if (vHeight==0) vHeight = 450; else vHeight+=50;
	if (vWidth==0) vWidth = 600; else vWidth+=50;

	winDef = 'status=no,resizable=yes,scrollbars='+sc+',toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>COIMEX - Cty Thuy Hai san va XNK Con dao</title><body onclick="window.close();" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="overflow: auto; cursor: hand">');
	newwin.document.writeln('<table border=0 height="100%" width="100%"><tr><td align="center">');
	newwin.document.writeln('<img border=2 src="', sLink, '" alt="', 'Click here to close...', '">');
	newwin.document.writeln('</tr></td></table>');
	newwin.document.writeln('</body>');
	return false;
}

/***************************************************************/
/* POP UP WINDOW
/***************************************************************/

function popup(url, w, h){
	//scrollbar = yes / no / auto
	var scrollbar = "yes";
	var popup, left, top, setting;
	

	left=screen.width?(screen.width-w)/2:0;
	top=screen.width?(screen.height-h)/2:0;
	
	setting="width=" + w + ",height=" + h + ", scrollbars=" + scrollbar + ", dependent=yes," + "top=" + top + ",left=" + left + "'";
	popup = window.open("","test",setting);
	popup.location.href=url;
	
	if (popup.opener == null) { 
   		popup.opener = self; 
	}
}
function popup1(url, w, h, scrollbar){
	//scrollbar = yes / no / auto
	var popup, left, top, setting;

	left=screen.width?(screen.width-w)/2:0;
	top=screen.width?(screen.height-h)/2:0;
	
	setting="width=" + w + ",height=" + h + ", scrollbars=" + scrollbar + ", dependent=yes," + "top=" + top + ",left=" + left + "'";
	popup = window.open("","test",setting);
	popup.location.href=url;
	
	if (popup.opener == null) { 
   		popup.opener = self; 
	}
}

/***************************************************************/
/* POPUP
/***************************************************************/
function OpenNormal(Url){
	var topPos  = 0;
	var leftPos = 0;
	if (screen.width > 800){
		topPos  = (screen.width - 800)/2
		leftPos = (screen.height - 600)/2
	}
	var options = "top="+topPos+",left="+leftPos+",center=yes,width=790px,menubar=yes,status=no,toolbar=no,resizable=yes";
	window.opener = window;
	window.open(Url,"",options,true);
}
function OpenDefine(Url,Width,Height){
	var soptions = 'dialogWidth:' + Width + 'px;dialogHeight:' + Height + 'px;scroll=yes;resizable=yes;center=yes;status=no;edge=raised;help=no;';
	var Result = window.showModalDialog(Url,'',soptions);
}
function OpenDefine2(Url,Width,Height){
	var topPos  = (screen.width - Width)/2;
	var leftPos = (screen.height - Height)/2;
	var options = "top="+topPos+",left="+leftPos+",width=" + Width + "px,height=" + Height + "px,center=yes,menubar=yes,status=no,toolbar=no,resizable=yes";
	return window.open(Url,"",options,false);
}
function OpenModal(Url,Width,Height){
	var ASPxPage = AppPath + "WebLibData/PopupContainer/PopupPage.aspx?Page=" + Url + "&WindowTitle=Control Panel&UserData=&PopupText=&PopupValue=";
	var soptions = "dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center=yes;status=no;edge=raised;help=no;";
	var Result   = window.showModalDialog(ASPxPage,"",soptions);
	return (Result != null);
}



/***************************************************************/
/* Confirm delete record
/***************************************************************/
function CFDel(msg){
	return window.confirm('Bạn muốn xóa mẩu tin này?');
}
