/*======================================================================*\
|| #################################################################### ||
|| # > H-Php v1.0 final                                               # ||
|| # ---------------------------------------------------------------- # ||
|| # > Author: Kid08												  # ||
|| # > Date started: 8th September 2005								  # ||
|| # > http://www.h-php.net                                           # ||
|| #################################################################### ||
\*======================================================================*/

var SID = null;
var CurStyleID = 0;

// Other Browser
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac    = (userAgent.indexOf('mac') != -1);

// Get IE
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";
var is_ie = ((iePos!=-1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5 = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") !=-1));
var is_ie5_5up =(is_ie && is_minor >= 5.5);
var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);
var is_ie7 = (is_ie && is_major == 7)
// End Get IE

var MainFile = "";
var ListModule = new Array();
var CurMenu = '';
var CurSelectItem = new Array();
var CurSelectInput = new Array();
var checkMouse = 1;
var BlockMenu = 0;
var docOnclick = 'if (getObjId(\'tab_list_icon\')) { if (getObjId(\'tab_list_icon\').style.display!=\'none\' && checkMouse==0) { getObjId(\'tab_list_icon\').style.display=\'none\';checkMouse=1 } }';
var ListDocOnclick = new Array();
var MouseX = 0;
var MouseY = 0;

// JS Image Path
var imagePathR = rootDomain+'/images/';
var imagePathT = rootDomain+'/templates/'+userStyle+'/images/';

var viewportwidth;
var viewportheight;
function getPageSize() {
	if (typeof window.innerWidth != 'undefined') {// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	} else {// older versions of IE
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}	
}
getPageSize();

function getObjId(idname) {
	if (document.getElementById) {
		return document.getElementById(idname);
	} else if (document.all) {
		return document.all[idname];
	} else if (document.layers) {
		return document.layers[idname];
	} else {
		return null;
	}
}

// Catch OnClick Event on Page
document.onclick = function() {
	eval(docOnclick);
};
function setMiddlePage(obj) {
	getObjId(obj).style.left = parseInt(viewportwidth/2 - $("#"+obj).width()/2) + "px";
	getObjId(obj).style.top = parseInt(viewportheight/2 - $("#"+obj).height()/2) + "px";
}
function setDocOnclick(Name, Content) {
	if (ListDocOnclick[Name]!=true) docOnclick += Content;
	
	ListDocOnclick[Name] = true;
}

function onSelect(val) {
	checkMouse = val;
}

// Delete a Obj
function RemoveObj(obj) {
	var DelObj = getObjId(obj);
	DelObj.parentNode.removeChild(DelObj);
}

// Hide an Element
function closeEle(obj) {
	getObjId(obj).style.display = 'none';
}

// Change Opacity Slowly
function initFade(obj) {
	for (var i=0;i<((is_ie) ? 5 : 11);i++)
		setTimeout('changeOpac("'+i+'","'+obj+'")',100*i);
	return false;
}

// Change Opacity of Obj
function changeOpac(opacity, obj) {
	if (getObjId(obj)) {
		getObjId(obj).style.opacity = (opacity / 15);
		getObjId(obj).style.filter = "alpha(opacity=" + opacity*15 + ")";
	}
}

// Cut String
function cutStr(str, len) {
	if (str.length<=len) {
		return str;
	} else {
		str = str.substr(0,len)+' ..';
		
		return str;
	}
}

function ShowHideMenu(obj,imgObj) {
	if (getObjId(obj).style.display=='none') {
		getObjId(obj).style.display = 'block';
		if (imgObj) imgObj.src = rootDomain+"/images/subtract.gif";
	} else {
		getObjId(obj).style.display = 'none';
		if (imgObj) imgObj.src = rootDomain+"/images/addition.gif";
	}
}

// Drop Down Menu for Admin CP
var lastDropMenu = null;
function DropDownMenu(obj) {
	if (lastDropMenu && lastDropMenu!=obj) {
		getObjId(lastDropMenu).style.display='none';
	}
	
	 getObjId(obj).style.display = 'block';
	 
	 if (lastDropMenu!=obj) lastDropMenu=obj;
}

// Reset Form by using JS
function resetForm(formname) {
	if (document.forms[formname]) document.forms[formname].reset();
}

// Get Current Value in Select Box
function getObjOfList(list) {
	return list.options[list.selectedIndex].value;
}

// Switch Menu
function SwitchMenu(obj) {
	if(getObjId(obj).style.display != "block") { 
		getObjId(obj).style.display = "block";
	} else {
		getObjId(obj).style.display = "none";
	}
}

// Submit Form by using JS
function submitForm(formname, actionPath) {
	if (document.forms[formname]) {
		if (actionPath) document.forms[formname].action = actionPath;
		document.forms[formname].submit();
	} else {
		alert('Sai Form.');	
	}
}

// Convert to Vietnamese string
var nomarkKeyAs=new RegExp('[&#258;,&#194;,&#193;,&#192;,&#7842;,&#195;,&#7840;,&#7854;,&#7854;,&#7858;,&#7860;,&#7862;,&#7844;,&#7846;,&#7848;,&#7850;,&#7852;]','g');
var nomarkKeyas=new RegExp('[&#259;,&#226;,&#225;,&#224;,&#7843;,&#227;,&#7841;,&#7855;,&#7857;,&#7859;,&#7861;,&#7863;,&#7845;,&#7847;,&#7849;,&#7851;,&#7853;]','g');
var nomarkKeyEs=new RegExp('[&#202;,&#201;,&#200;,&#7866;,&#7868;,&#7864;,&#7870;,&#7872;,&#7874;,&#7876;,&#7878;]','g');
var nomarkKeyes=new RegExp('[&#234;,&#233;,&#232;,&#7867;,&#7869;,&#7865;,&#7871;,&#7873;,&#7875;,&#7877;,&#7879;]','g');
var nomarkKeyOs=new RegExp('[&#212;,&#416;,&#211;,&#210;,&#7886;,&#213;,&#7884;,&#7888;,&#7890;,&#7892;,&#7894;,&#7896;,&#7898;,&#7900;,&#7902;,&#7904;,&#7906;]','g');
var nomarkKeyos=new RegExp('[&#244;,&#417;,&#243;,&#242;,&#7887;,&#245;,&#7885;,&#7889;,&#7891;,&#7893;,&#7895;,&#7897;,&#7899;,&#7901;,&#7903;,&#7905;,&#7907;]','g');
var nomarkKeyUs=new RegExp('[&#431;,&#218;,&#217;,&#7910;,&#360;,&#7908;,&#7912;,&#7914;,&#7916;,&#7918;,&#7920;]','g');
var nomarkKeyus=new RegExp('[&#432;,&#250;,&#249;,&#7911;,&#361;,&#7909;,&#7913;,&#7915;,&#7917;,&#7919;,&#7921;]','g');
var nomarkKeyIs=new RegExp('[&#205;,&#204;,&#7880;,&#296;,&#7882;]','g');
var nomarkKeyis=new RegExp('[&#237;,&#236;,&#7881;,&#297;,&#7883;]','g');
var nomarkKeyYs=new RegExp('[&#221;,&#7922;,&#7926;,&#7928;,&#7924;]','g');
var nomarkKeyys=new RegExp('[&#253;,&#7923;,&#7927;,&#7929;,&#7925;]','g');
var nomarkKeyDs=new RegExp('[&#272;]','g');
var nomarkKeyds=new RegExp('[&#273;]','g');

var nomarkKeyA=new RegExp('[Ă,Â,Á,À,Ả,Ã,Ạ,Ắ,Ằ,Ẳ,Ẵ,Ặ,Ấ,Ầ,Ẩ,Ẫ,Ậ]','g');
var nomarkKeya=new RegExp('[ă,â,á,à,ả,ã,ạ,ắ,ằ,ẳ,ẵ,ặ,ấ,ầ,ẩ,ẫ,ậ]','g');
var nomarkKeyE=new RegExp('[Ê,É,È,Ẻ,Ẽ,Ẹ,Ế,Ề,Ể,Ễ,Ệ]','g');
var nomarkKeye=new RegExp('[ê,é,è,ẻ,ẽ,ẹ,ế,ề,ể,ễ,ệ]','g');
var nomarkKeyO=new RegExp('[Ô,Ơ,Ó,Ò,Ỏ,Õ,Ọ,Ố,Ồ,Ổ,Ỗ,Ộ,Ớ,Ờ,Ở,Ỡ,Ợ]','g');
var nomarkKeyo=new RegExp('[ô,ơ,ó,ò,ỏ,õ,ọ,ố,ồ,ổ,ỗ,ộ,ớ,ờ,ở,ỡ,ợ]','g');
var nomarkKeyU=new RegExp('[Ư,Ú,Ù,Ủ,Ũ,Ụ,Ứ,Ừ,Ử,Ữ,Ự]','g');
var nomarkKeyu=new RegExp('[ư,ú,ù,ủ,ũ,ụ,ứ,ừ,ử,ữ,ự]','g');
var nomarkKeyI=new RegExp('[Í,Ì,Ỉ,Ĩ,Ị]','g');
var nomarkKeyi=new RegExp('[í,ì,ỉ,ĩ,ị]','g');
var nomarkKeyY=new RegExp('[Ý,Ỳ,Ỷ,Ỹ,Ỵ]','g');
var nomarkKeyy=new RegExp('[ý,ỳ,ỷ,ỹ,ỵ]','g');
var nomarkKeyD=new RegExp('[Đ]','g');
var nomarkKeyd=new RegExp('[đ]','g');

var nomarkKeyUniCom=new RegExp('[(&#769;,&#803;,&#777;,&#803;,&#768;,&#771;,â€™,â€˜,’,‘]','g');
var nomarkKeyOther=new RegExp('[!-/,:,\[-^,`,{-~]','g');

function convertVN(_string) {
	_string=_string.replace(nomarkKeyUniCom,'');
	
	_string=_string.replace(nomarkKeyAs,'A');
	_string=_string.replace(nomarkKeyas,'a');
	_string=_string.replace(nomarkKeyEs,'E');
	_string=_string.replace(nomarkKeyes,'e');
	_string=_string.replace(nomarkKeyOs,'O');
	_string=_string.replace(nomarkKeyos,'o');
	_string=_string.replace(nomarkKeyUs,'U');
	_string=_string.replace(nomarkKeyus,'u');
	_string=_string.replace(nomarkKeyIs,'I');
	_string=_string.replace(nomarkKeyis,'i');
	_string=_string.replace(nomarkKeyYs,'Y');
	_string=_string.replace(nomarkKeyys,'y');
	_string=_string.replace(nomarkKeyDs,'D');
	_string=_string.replace(nomarkKeyds,'d');
	
	
	_string=_string.replace(nomarkKeyA,'A');
	_string=_string.replace(nomarkKeya,'a');
	_string=_string.replace(nomarkKeyE,'E');
	_string=_string.replace(nomarkKeye,'e');
	_string=_string.replace(nomarkKeyO,'O');
	_string=_string.replace(nomarkKeyo,'o');
	_string=_string.replace(nomarkKeyU,'U');
	_string=_string.replace(nomarkKeyu,'u');
	_string=_string.replace(nomarkKeyI,'I');
	_string=_string.replace(nomarkKeyi,'i');
	_string=_string.replace(nomarkKeyY,'Y');
	_string=_string.replace(nomarkKeyy,'y');
	_string=_string.replace(nomarkKeyD,'D');
	_string=_string.replace(nomarkKeyd,'d');
	_string=_string.replace(nomarkKeyOther,'');
	_string=_string.replace(new RegExp('[.]','g'),'');
	return _string;
}


// Slide
function slide(id, innerObj, height, width, objName) {
	this.leftTimeOut = null;
	this.rightTimeOut = null;
	this.startPos = 0;
	this.slideID = id;
	this.innerObj = innerObj;
	this.height = height;
	this.width = width;
	this.slideObjName = objName;
	
	this.slidePos = function (type, obj) {
		var posLeft = (getObjId(this.slideID+'_slide').style.left) ? parseInt(getObjId(this.slideID+'_slide').style.left) : 0;
		if (type=='left') {
			if (parseInt(getObjId(this.slideID+'_slide').style.left)<this.startPos) getObjId(this.slideID+'_slide').style.left = (posLeft+1)+'px';
			if (this.rightTimeOut) clearTimeout(this.rightTimeOut);
			this.leftTimeOut = setTimeout(this.slideObjName+'.slidePos("left","'+obj+'")',20);
		} else {
			var p = $("#"+this.slideID+'_check_last');
			var offset = p.offset();

			minXPos = offset.left - parseInt(getObjId(this.slideID+'_root_slide').style.width);
			if (posLeft+minXPos>0) getObjId(this.slideID+'_slide').style.left = (posLeft-1)+'px';
			if (this.leftTimeOut) clearTimeout(this.leftTimeOut);
			this.rightTimeOut = setTimeout(this.slideObjName+'.slidePos("right","'+obj+'")',20);
		}
	};
	
	this.clearSlide = function () {
		if (this.leftTimeOut) clearTimeout(this.leftTimeOut);
		if (this.rightTimeOut) clearTimeout(this.rightTimeOut);
	};
	
	this.insertContent = function (content) {
		getObjId(this.slideID+'_content').innerHTML += content;
	};
	
	this.buildHTML = function () {
		var html = '';
		html += '<div class="clearfix" style="width:'+this.width+'px; height:'+this.height+'px">';
		html += '	<div style="float:left; width:15px; height:15px; background-image:url('+imagePathT+'tool-sprites.gif); background-position: 0px -105px; margin-top:'+parseInt((this.height-17)/2)+'px" onmouseover="'+this.slideObjName+'.slidePos(\'left\',this.id);statusBlockDropMouse(this, 2);" id="'+this.slideID+'_left" onmouseout="'+this.slideObjName+'.clearSlide();statusBlockDropMouse(this, 1)"><img src="'+imagePathR+'space.gif" /></div>';
		html += '	<div style="float:left; width:'+(this.width-34)+'px; height:'+(this.height)+'px; text-align:left; position:relative; overflow:hidden; padding-left: 2px; padding-right: 2px" id="'+this.slideID+'_root_slide">';
		html += '		<div style="position:absolute; width:30000px" id="'+this.slideID+'_slide" class="clearfix">';
		html += '			<div style="float:left" id="'+this.slideID+'_content"></div>';
		html += '			<div style="float:left" id="'+this.slideID+'_check_last"></div>';
		html += '		</div>';
		html += '	</div>';
		html += '	<div style="float:left; width:15px; height:15px; background-image:url('+imagePathT+'tool-sprites.gif); background-position: 0px -120px; margin-top:'+parseInt((this.height-17)/2)+'px" onmouseover="'+this.slideObjName+'.slidePos(\'right\',this.id);statusBlockDropMouse(this, 2)" id="'+this.slideID+'_right" onmouseout="'+this.slideObjName+'.clearSlide();statusBlockDropMouse(this, 1)"><img src="'+imagePathR+'space.gif" /></div>';
		html += '</div>';
		
		return html;
	};
	
	this.initSlide = function () {
		getObjId(this.innerObj).innerHTML = this.buildHTML();
	};
}

// Change Obj Style When Click in Multi Obj
var changeObjList = new Array();
function changeObj (obj) {
	this.lastObj = obj;
	this.styleVar = new Array();
	this.styleClass = new Array();
	
	this.change = function (obj) {
		if (obj!=this.lastObj) {
			if (this.styleClass.length>0) {
				getObjId(this.lastObj).className = this.styleClass[0];
				getObjId(obj).className = this.styleClass[1];
			} else {
				for (vars in this.styleVar) {
					getObjId(this.lastObj).style[vars] = this.styleVar[vars][0];
					getObjId(obj).style[vars] = this.styleVar[vars][1];
				}
			}
			
			this.lastObj = obj;
		}
	};
}

// Reset Original Style When Click Radio Button
function getOriStyle() {
	getObjId('header').style.backgroundImage = "";
	getObjId('header').style.backgroundPosition = "";
	getObjId('header').style.backgroundColor = "";
	
	getObjId('body_content').style.backgroundImage = "";
	getObjId('body_content').style.backgroundPosition = "";
	getObjId('body_content').style.backgroundColor = "";
	
	himAJAX('get','index.php?module=setting&act=try_style&id='+getObjId('edit_style_id').value,'nr');
}
