function genTinyMCE(){
	tinyMCE.init({
		mode : "exact",
		theme : "simple",
		skin : "o2k7",
		elements: "cat_desc,meal_desc,res_address",
		content_css : "./clients/tiny_mce/content.css",
	});
	
	tinyMCE.init({
		// General options
		mode : "exact",
		theme : "advanced",
		skin : "o2k7",
		elements: "blo_content,tores_content,menu_content, event_content, news_content, ven_detail,email_content,verify_content,forgot_content,post_content, page_content",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		/*theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		setup : function(ed) {
			// Register example button
			ed.addButton("imgman", {
				title : "Images manager",
				image : "clients/tiny_mce/icons/pictures.png",
				onclick : function() {
					//tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent() + "<img src='packages/pkg.image/upload/10a.jpg' alt='image' />");
					tinyMCE.activeEditor.windowManager.open({file: "?fileman/control", width: "900", height: "500",  resizable : "yes", scrollbars : "yes", inline : "yes"},{});
					//ed.windowManager.alert(tinyMCE.activeEditor.getContent()); 
					//ed.selection.getContent({format : 'text'}));
					//helloWorld()
				}
			});
		},*/

		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "./clients/tiny_mce/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "K!D",
			staffid : "711985"
		},
		file_browser_callback : "myFileBrowser",
		convert_urls : false,
	});
}

function myFileBrowser (field_name, url, type, win) {
	//alert(location.pathname);

//alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

/* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
	the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
	These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */

//var cmsURL = window.location.toString();    // script URL - use an absolute path!
var cmsURL = "?fileman/control/"+type
/*if (cmsURL.indexOf("?") < 0) {
	//add the type as the only query parameter
	cmsURL = cmsURL + "?type=" + type;
}
else {
	//add the type as an additional query parameter
	// (PHP session ID is now included if there is one at all)
	cmsURL = cmsURL + "&type=" + type;
}*/

	tinyMCE.activeEditor.windowManager.open({
		file : cmsURL,
		title : 'File manager',
		width : 800,  // Your dimensions may differ - toy around with them!
		height : 480,
		resizable : "yes",
		inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
		close_previous : "no"
	}, {
		window : win,
		input : field_name
	});
	return false;
}


function hideDiv(id, seconds){
	setTimeout(function(){
		var objDiv = document.getElementById(id)
		if(objDiv){
			objDiv.style.display = "none"
			return true
		}
		else{
			return false
		}
	}, seconds*1000)
}

function showDiv(id){
	var objDiv = document.getElementById(id)
	if(objDiv){
		objDiv.style.display = "block"
		return true
	}
	else{
		return false
	}
}

function reverseDiv(id){
	var objDiv = document.getElementById(id)
	if(objDiv){
		if(objDiv.style.display == "none"){
			objDiv.style.display = "block"
		}
		else{
			objDiv.style.display = "none"
		}
		return true
	}
	else{
		return false
	}
}

function assignDiv(id, string){
	document.getElementById(id).innerHTML = string
}

function focusTag(id){
	document.getElementById(id).focus()
}

function editLang(oForm, oId, val, act){
	var objForm = document.getElementById(oForm)
	var objId = document.getElementById(oId)
	
	objForm.action = "?langs/control/"+act
	objId.value = val
	objForm.submit()
}

function gen_calendar(input, btn, useTime){
	if(useTime){
		Calendar.setup({
			trigger    : btn,
			inputField : input,
			dateFormat : "%d-%m-%Y %H:%M",
			showTime	: true,
			onSelect   : function() { this.hide(); }
		});
	}
	else{
		Calendar.setup({
			trigger    : btn,
			inputField : input,
			dateFormat : "%d-%m-%Y",
			onSelect   : function() { this.hide(); }
		});
	}
}

function valid_form(frm){
		var objForm = document.getElementById(frm);
		var i;
		var objEle;

		if(objForm){
			for(i=0; i<objForm.elements.length; i++){
				objEle = objForm.elements[i];
				if(objEle.className=="required" && (objEle.tagName=="INPUT" || objEle.tagName=="TEXTAREA") && !checkTextInput(objEle, txt_req)){
					return false;
				}
				if(objEle.className == "required" && objEle.tagName == "SELECT" && !checkSelectInput(objEle, txt_sel)){
					return false;
				}
				if(objEle.className == "int" && !checkIntInput(objEle, txt_int)){
					return false;
				}
				if(objEle.className == "required" && objEle.tagName=="INPUT" && objEle.type=="checkbox" && !checkCheckboxInput(objEle, txt_req)){
					return false;
				}
			}
		}
		else{
			return false;
		}
		return true;
	}

function checkTextInput(objEle, txt_req){
	if(objEle){
		if(objEle.value == ""){
			alert(objEle.title + " " + txt_req);
			objEle.style.border = "1px solid #FF0000";
			objEle.focus();
			return false;
		}
		else{
			objEle.style.border = "";
			return true;
		}
	}
	else{
		return false;
	}
}

function checkIntInput(objEle, txt_int){
	if(objEle){
		if(!checkTextInput(objEle)){
			return false;
		}
		if(objEle.value*1 == objEle.value){
			objEle.style.border = "";
			return true;
		}
		else{
			alert(objEle.title + " " + txt_int);
			objEle.style.border = "1px solid #FF0000";
			objEle.focus();
			return false;
		}
	}
	else{
		return false;
	}
}

function checkSelectInput(objEle, txt_sel){
	if(objEle){
		if(objEle.value == "$$$" || objEle.selectedIndex == 0){
			alert(objEle.title + " " + txt_sel);
			objEle.style.border = "1px solid #FF0000";
			objEle.focus();
			return false;
		}
		else{
			objEle.style.border = "";
			return true;
		}
	}
	else{
		return false;
	}
}

function checkCheckboxInput(objEle, txt_req){
	if(objEle){
		if(!objEle.checked){
			alert(objEle.title + " " + txt_req);
			objEle.style.border = "1px solid #FF0000";
			objEle.focus();
			return false;
		}
		else{
			objEle.style.border = "";
			return true;
		}
	}
	else{
		return false;
	}
}

function confirmAction(ques, url){
	var cfm = confirm(ques);
	
	if(cfm){
		window.location = url;
		return true;
	}
	else{
		return false;
	}
}

function show_by_page_js(pre, page, show, total, divPage){
	var i;
	var obj;
	var objDivPage;
	
	objDivPage = document.getElementById(divPage);
	
	for(i=0; i<total; i++){
		obj = document.getElementById(pre + "_" + i);
		if(obj){
			obj.style.display = "none";
		}
		
	}
	
	var start = (page-1)*show;
	for(i=start; i<start+show; i++){
		obj = document.getElementById(pre + "_" + i);
		if(obj){
			obj.style.display = "block";
		}
		
	}
	
	var totalPages;
	var objDePage = document.getElementById("dePage");
	var option;
	total = total*1;
	show = show*1;
	if(total > show){
		totalPages = Math.ceil(total/show);
		for(i=0; i<totalPages; i++){
			option = new Option((i+1), (i+1));
			if(objDePage){
				objDePage.options[i] = option;
			}
		}
		if(objDePage){
			objDePage.selectedIndex = page-1;
		}
	}
}

function show_by_calendar(ind, d, m, y){
	var arr_cal = new Array("cal-sun", "cal-mon", "cal-tue", "cal-wed", "cal-thur", "cal-fri", "cal-sat");
	var i;
	var objCalDiv;
	var objCalDate;
	
	for(i=0; i<7; i++){
		objCalDiv = document.getElementById("cal_"+i);
		objCalDate = document.getElementById("cal_date_"+i);
		if(objCalDiv){
			objCalDiv.className = "col-left-auto " + arr_cal[i] + " cal-mar ";
			objCalDate.style.color = "#595957";
		}
	}
	
	objCalDiv = document.getElementById("cal_"+ind);
	objCalDate = document.getElementById("cal_date_"+ind);
	objCalDiv.className = "col-left-auto " + arr_cal[ind] + " cal-mar cal-cur";
	objCalDate.style.color = "#FFFFFF";
	
	xajax_get_events_by_calendar(d, m, y);
}

function deleteOrderSelect(frm,act,lang1,lang2){
	var objForm = document.getElementById(frm);
	var checked = false;
	
	for(i=0; i<objForm.elements.length; i++){
		if(objForm.elements[i].type=="checkbox" && objForm.elements[i].checked==true){
			checked = true;
		}		
	}
	
	if(!checked){
		alert(lang1);
		return false;
	}
	else{
		alertConfirm = confirm(lang2);
		if(alertConfirm == true){
			objForm.action = act;
			objForm.submit();
		}
		else{
			return false;
		}
	}
	return true;
}

function sendMailAll(frm,act,lang){
	var objForm = document.getElementById(frm);
	var checked = false;
	
	for(i=0; i<objForm.elements.length; i++){
		if(objForm.elements[i].type == "checkbox" && objForm.elements[i].checked==true){
			checked = true;
		}
	}
	
	if(!checked){
		alert(lang);
		return false;
	}
	else{
		objForm.action = act;
		objForm.submit();
	}
	
	return true;
}

function selectNoselect(frmId, pre,checkall){
	var obj = document.getElementById(frmId)
	var objCheckall = document.getElementById(checkall);
	var i
	if(objCheckall.checked == true){
		for(i=0; i< obj.elements.length; i++){
			if(obj.elements[i].type == "checkbox" && obj.elements[i].id.toString().indexOf(pre)==0){
				obj.elements[i].checked = true
			}	
		}
	}
	else{
		for(i=0; i< obj.elements.length; i++){
			if(obj.elements[i].type == "checkbox" && obj.elements[i].id.toString().indexOf(pre)==0){
				obj.elements[i].checked = false
			}	
		}

	}
}

function check_same(obj, frm, preCheckbox){
	var i
	var objCheckbox
	var objForm
	
	objForm = document.getElementById(frm)
	
	for(i=0; i<objForm.elements.length; i++){
		objCheckbox = document.getElementById(preCheckbox + '_' + i)
		if(objCheckbox){
			objCheckbox.checked = obj.checked
		}
	}
}

function show_tab(preTab, preContent, tabClass, curClass, ind, total){
	var objTab, objContent;
	
	for(var i=0; i<total; i++){
		objTab = document.getElementById(preTab + "_" + i);
		if(objTab){
			objTab.className = "col-left-auto "+tabClass;
		}
		objContent = document.getElementById(preContent + "_" + i);
		if(objContent){
			objContent.style.display = "none";
		}
	}
	
	objTab = document.getElementById(preTab + "_" + ind);
	objTab.className = "col-left-auto " + curClass;
	objContent = document.getElementById(preContent + "_" + ind)
	objContent.style.display = "block";
}

function div_loading(id, tpl_dir){
	var objDiv = document.getElementById(id);
	
	objDiv.innerHTML = "<img src='"+tpl_dir+"images/loading.gif' width='48' height='48' alt='Loading ...' />";
}

function show_quick_apps(total){
	var objTxt = document.getElementById("app_name");
	var ele;
	
	for(var i=0; i<total; i++){
		ele = document.getElementById("qa_"+i);
		if(ele){
			if(ele.title.toLowerCase().indexOf(objTxt.value.toLowerCase()) >= 0){
				ele.style.display = "block";
			}
			else{
				ele.style.display = "none";
			}
		}
		else{
		}
	}
	return true;
}

function get_key(e){
	var keynum;
	var keychar;

	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	
	if(keychar == "w"){
		reverseDiv("quick_apps");
		document.getElementById("app_name").focus();
	}

	return false;
}

function valid_xhtml(){
	document.body.setAttribute("marginheight", 0);
}

function show_en_tab(ind, total, cat_id){
	var obj;
	
	for(var i=0; i<total; i++){
		obj = document.getElementById("en_"+i);
		if(obj){
			obj.className = "col-left-auto need-tab";
			document.getElementById("en_seemore_"+i).style.display = "none";
		}
		else{
		}
	}
	
	obj = document.getElementById("en_"+ind);
	obj.className = "col-left-auto need-tab-cur";
	document.getElementById("en_seemore_"+ind).style.display = "block";
	xajax_get_advnews(cat_id);
}

function show_ibox(tit, id, code){
	iBox.fade_in_speed = 1000;
	iBox.show(document.getElementById("inner_content_"+id).innerHTML, code, tit);
}

function kid_slider(prefix, total){
	var ele;
	var next;
	
	if(total < 1){
		return false;
	}
	
	for(var i=0; i<total; i++){
		ele = document.getElementById(prefix + "_" + i);
		if(ele && ele.style.display == "block"){
			if(i == (total-1)){
				next = 0;
			}
			else{
				next = i+1;
			}
			break;
		}
	}
	
	for(var i=0; i<total; i++){
		ele = document.getElementById(prefix + "_" + i);
		if(ele){
			ele.style.display = "none";
		}
	}
	
	ele = document.getElementById(prefix + "_" + next);
	if(ele){
		ele.style.display = "block";
	}
}
