/* type of images can upload to server */
var LIST_TYPE_IMG_UPLOAD=new Array('GIF','JPG','SWF','BMP','PNG');

/****current position of mouse in box [x & y]******/
var curBox=null;
var curX=curY=0;

/****Msg constant of JavaScript*******/
var MsgCheckItem="Please check Items";

/*****Ajax Data commnon********************************************************/

/* function for my data */
function show_customer_data(m_url,m_id_des,m_obj){	if(document.getElementById(m_id_des)){		getDataReturnText(INDEX_PAGE+'?ispc=1&'+m_url,status_customer_data,m_id_des);
	}else window.alert("Can not found Object:"+m_id_des);
}//--end function--
function status_customer_data(m_txt,m_id){
	//alert(m_txt);
	if(obj=document.getElementById(m_id)){
		obj.innerHTML=m_txt;
	}
}//--end function--
function post_customer_data(m_url,m_data,m_id_des,my_var){
	if(document.getElementById(m_id_des)){
		postDataReturnText(INDEX_PAGE+'?ispc=1&'+m_url,m_data,status_pos_customer_data,m_id_des,my_var);
	}
}//--end function--
function status_pos_customer_data(m_txt,m_id,m_var){
	//alert(m_txt);
	if(obj=document.getElementById(m_id)){
		obj.innerHTML=m_txt;
	}
	if(m_var){
		window.location.href=m_var;
	}
}//--end function--

/*****Ajax Data commnon********************************************************/

/*****Begin: User upload file*****************/
/* change select images [ For user upload image ] */
function change_select_images(m_root,img_name){	if(m_root.value!=""){
	  var tmp,m_type;
	  if(tmp_img=document.getElementById(img_name)){	    if(m_type=check_upload_type(m_root.value)){	      if(m_type=='SWF'){
	      	window.alert('You can not preview file Flash(*.swf)');
	      }else{	      	tmp_img.src=convert_path_img(m_root.value);
	      }
	    }else{
	    	window.alert('You can not upload this file type');
	    }
	  }else{	  	//document.images[img_name].src=convert_path_img(m_root.value);
	  }
	}//end if
}//-----------------------------------------------------------------------------
function check_upload_type(m_path){
	var tmp=new String(),m_type;
	tmp=m_path;
	tmp=tmp.toUpperCase();
	for(var i=0;i<LIST_TYPE_IMG_UPLOAD.length;i++){
	  m_type=tmp.indexOf(LIST_TYPE_IMG_UPLOAD[i],0);
	  if(m_type!==-1) return LIST_TYPE_IMG_UPLOAD[i];
	}
	return false;
}//-----------------------------------------------------------------------------
function convert_path_img(m_path){
	var tmp=m_path.replace("\\","/");
	return "file://"+tmp;
}//-----------------------------------------------------------------------------
/*****End: User upload file*****************/

/****Show or Hide once block data*****************/
function show_block_data(obj,m_id_sub){	var id_sub=document.getElementById(m_id_sub);
	var m_value='none';
	if(id_sub.style.display=='' || id_sub.style.display=='undefined' || id_sub.style.display=='inline'){
		m_value='none';
	}else{
		m_value='inline';
	}
	id_sub.style.display=m_value;}//--end function--

/* function show sub menu left */
function sub_menu_left(obj,m_id_sub){
	var id_sub=document.getElementById(m_id_sub);
	var m_value='none';
	if(id_sub.style.display=='' || id_sub.style.display=='undefined' || id_sub.style.display=='none'){		m_value='block';	}else{		m_value='none';	}
	id_sub.style.display=m_value;
}//--end function--

/*** Begin: Function for advertisement */

function show_advertisement(m_id,m_pos){
	if(document.getElementById(m_id)){
		getDataReturnText(INDEX_PAGE+'?n=advertise&ispc=1&cid='+m_pos,status_get_advertise,m_id);
	}
}//--end function--
function status_get_advertise(m_txt, m_id){	//alert(m_txt);
	var obj=document.getElementById(m_id);
	if(obj) obj.innerHTML=m_txt;
}//--end function--

function post_advertisement(m_url,m_id_des,m_data){
	if(document.getElementById(m_id_des)){
		postDataReturnText(INDEX_PAGE+m_url,m_data,status_post_advertise,m_id_des);
	}
}//--end function--
function status_post_advertise(m_txt, m_id){
	//alert(m_txt);
	if( obj=document.getElementById(m_id) ){
		obj.innerHTML=m_txt;
	}
}//--end function--

/*** End: Function for advertisement ***/

/*****Begin: For Cookies*************/
function getCookie(c_name){
	if (document.cookie.length>0){
  	c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
	    c_start=c_start + c_name.length+1 ;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length
	    	return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }//--end if check cookies--
	return "";
}//--end function--
function setCookie(c_name,value,expiredays){	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}//--end function--
/*****End: For Cookies***************/

/******BEGIN: FUNCTION SELECT PARENT->CHILD*****************/
function init_permission(id_parent,id_child){
	var obj_pa=document.getElementById(id_parent);
	var obj_child=document.getElementById(id_child);
	if(obj_pa && obj_child && dobject.length){
		empty_options(id_child);
		dobject[obj_pa.value].get_options(obj_child);
	}else window.alert('Can not find id_object : '+ id_parent + ' or '+id_child + ' or Not data');
}//--end function--

function change_module_permission(m_id_module,id_obj){
	var obj=document.getElementById(id_obj);
	if(obj){
		empty_options(id_obj);
		dobject[m_id_module].get_options(obj);
	}else window.alert('Can not find id_object : '+ id_obj);
}//--end function--

/*****all object*******/
function D_MODULE_PERMISSION(id_parent){
	this.count=0;
	this.list_permission=new Array();
	this.add_child=AddChild;
	this.get_options=GetOptions;
}//--end object--
function AddChild(obj_child){
	this.list_permission[this.count++]=obj_child;
}//--end function--
function GetOptions(obj){
	for(var i=0;i<this.count;i++){
		//alert(this.list_permission[i].id);
		add_options(obj,this.list_permission[i].id,this.list_permission[i].name);
	}//--end for--
}//--end function--

function empty_options(id_obj){
  var obj=document.getElementById(id_obj);
  if(obj){
		for(var i=obj.length-1;i>0;i--){
			obj.remove(i);
		}//End For
	}else window.alert('Can not find id_object : '+id_obj);
}//---end function--
function add_options(obj,m_key,m_value){
	obj.options[obj.length]=new Option(m_value,m_key);
}//---end function--

/******END: FUNCTION SELECT PARENT->CHILD*****************/

/******BEGIN: SEARCH BOX FUNCTION*************************/

/******END: FUNCTION SEARCH BOX***************************/

/******BEGIN: COMMON FUNCTION*****************************/

function change_row_color(m_id,m_color){
	if( m_obj=document.getElementById(m_id) ){
		m_obj.style.backgroundColor=m_color;
	}
}//--change background of first column------------------------------------------

function checked_all_items(mParent){
	if(pid=document.getElementsByName('fields_checkitems[]')){
		var m_type=mParent.checked==true?1:0;
  	for(i=0;i<pid.length;i++){pid[i].checked=m_type}
  	return true;
  }else return false;
}//-----------------------------------------------------------------------------

function check_status_items(){	if(pid=document.getElementsByName('fields_checkitems[]')){
  	for(i=0;i<pid.length;i++){ if(pid[i].checked==1) return true; }
  } return false;}//--return False: not all item checked | True: aleast once item checked--------

function send_checked_delete(idForm,idCheckBox){	var idCheckBox=idCheckBox?idCheckBox:"fields_checkitems[]";	if(check_status_items()){		var value=window.confirm('Are you sure Remove checked ?');
		if(value){
			window.document.forms[idForm].submit();
		}	}else window.alert(MsgCheckItem);}//--end function---------------------------------------------------------------

function openWin(m_href,m_width,m_height){	if(!m_width){	m_width=400; m_height=400; }
	var myWin=window.open(m_href,"DTOOL_V4","width="+m_width+"px,height="+m_height+"px,resizable=1");
	//var myWin=window.open(m_href,"DTOOL_V4");
			myWin.focus();}//---end function--

function openWinHelp(m_href,m_width,m_height){
	if(!m_width){	m_width=800; m_height=700; }
	var myHelp=window.open(INDEX_PAGE+'?'+m_href,"DTOOL_V4","scrollbars=yes,resizable=yes,width="+m_width+"px,height="+m_height+"px");
			myHelp.focus();
			myHelp.moveTo(60,0);
}//---end function--

function dshowDiv(m_id,m_type,e){	e = e || window.event;	if(id=document.getElementById(m_id)){		m_x=e.pageX?e.pageX:e.clientX;
		m_y=e.pageY?e.pageY:e.clientY;		id.style.display=m_type;
		id.style.left=m_x+20; id.style.top =m_y;	}else window.alert("Can not find ID: "+m_id);}//--end function--

function goto_links(mURL){	//alert(mURL);	window.location.href=mURL;}//--end function--

function HightLight(m_obj,m_type,m_value){	m_value=m_value?m_value:0.2;
	m_light=(m_type==0)?1:m_value;
	if (m_obj.style.MozOpacity)
		m_obj.style.MozOpacity=m_light;
	else if (m_obj.filters){
		m_obj.filters.alpha.opacity=m_light*100;
	}
}//--end function--

function UpdateOptions(){	var mObj=document.getElementsByName("fields_options[]");
	if(mObj){
		var objOptions=null;
		for(var i=0;i<mObj.length;i++){
			objOptions=document.getElementById('id_key_options_'+mObj[i].id);
			objOptions.value=mObj[i].options[mObj[i].selectedIndex].text;
		}//--end for--
		ChangeTotalPrice();
	}else alert("Can not found Object");}//--end function--

function ChangeTotalPrice(m_price,name_obj){	//var price=parseInt(m_price);
	var mObj=document.getElementsByName("fields_options[]");
	if(mObj){		var OBJ_ROOTPRICE=document.getElementById('root_total_price');		var m_total=parseInt(OBJ_ROOTPRICE.value);
		var objOptions=null;
		for(var i=0;i<mObj.length;i++){			m_total+=parseInt(mObj[i].options[mObj[i].selectedIndex].title);
			objOptions=document.getElementById('id_key_options_'+mObj[i].id);
			objOptions.value=mObj[i].options[mObj[i].selectedIndex].text;
		}//--end for--
		var objTotalPrice=document.getElementById("id_total_price");
		objTotalPrice.value=m_total;
		var objPrice=document.getElementById("id_price_show");
		objPrice.innerHTML=show_price(m_total);
	}else alert("Can not found Object");}//--end function--

function show_price(m_price){	var t_price=m_price.toString();
	var tmp_price=t_price.split("");
	var m_num=tmp_price.length-1;
	var s_price='';
	var j=0;
	for(var i=m_num;i>=0;i--){		j++;
		if(j%3==0){			s_price="."+tmp_price[i]+s_price;
			j=0;		}else{			s_price=tmp_price[i]+s_price;		}
	}//--end for--
	return s_price;}//--end function--

function get_price(m_price){	return m_price.replace(".","");}//--end function--

function change_bg_tab(m_pos,m_color_1,m_color_2,tabName,m_bg){
	var name_tab=(tabName)?tabName:'nhd_tab';
	var all_tab=document.getElementsByName(name_tab);
	for(var i=0;i<all_tab.length;i++){
		if(m_bg){
			all_tab[i].style.backgroundImage="url('"+m_color_1+"')";
		}else{
			all_tab[i].style.backgroundColor=m_color_1;
		}
	}//--end for--
	if(m_pos<0 || m_pos>=all_tab.length) m_pos=0;
	//alert(m_pos);
	if(all_tab){
		if(m_bg){
			all_tab[m_pos].style.backgroundImage="url("+m_color_2+")";
		}else{
			all_tab[m_pos].style.backgroundColor=m_color_2;
		}
	}else alert("Can not found tab");
}//--end function--

function change_tab_class(idTab,tabName,mClass1,mClass2){	var all_tab=document.getElementsByName(tabName);
	for(var i=0;i<all_tab.length;i++){
		all_tab[i].className=mClass1;
	}//--end for--
	all_tab[idTab].className=mClass2;}//--end function--

function show_tab_content(m_pos,tabName){	var name_tab=(tabName)?tabName:'nhd_tab';
	var all_tab=document.getElementsByName(name_tab);
	for(var i=0;i<all_tab.length;i++){
		all_tab[i].style.display="none";
	}//--end for--
	if(m_pos<0 || m_pos>=all_tab.length) m_pos=0;
	if(all_tab){
		all_tab[m_pos].style.display="block";
	}else alert("Can not found tab");}//--end function--

function show_editor_ajax(m_url,m_id_des,m_obj){
	if(document.getElementById(m_id_des)){
		getDataReturnText(INDEX_PAGE+'?ispc=1&'+m_url,status_show_editor_ajax,m_id_des,m_obj);
	}else window.alert("Can not found Object:"+m_id_des);
}//--end function--
function status_show_editor_ajax(m_txt,m_id,m_obj){
	//alert(m_txt);
	//alert(m_obj);
	if(obj=document.getElementById(m_id)){
		obj.innerHTML=m_txt;
		//var myEditor = document.getElementById('id_content');
		var oFCKeditor = new FCKeditor('id_content') ;
		oFCKeditor.ReplaceTextarea() ;
		//window.alert(oFCKeditor.CreateHtml());
		//myEditor.innerHTML = oFCKeditor.CreateHtml();
		//obj.innerHTML=oFCKeditor.CreateHtml();
	}
}//--end function--

function show_test(m_key,idDes){	var mURL="n=showdom&cmy="+m_key;	show_customer_data(mURL,idDes);}//--end function--
/******END: COMMON FUNCTION*******************************/
function change_img_tab(idTab){
	var all_img_tab=document.getElementsByName('img_sub_tab');
	for(var i=0;i<all_img_tab.length;i++){
		all_img_tab[i].src=pathLayout+"spacing.gif";
	}
	switch(idTab){
		case 0:
			all_img_tab[0].src=pathLayout+"spacing01.gif";
		break;
		case 6:
			all_img_tab[idTab-1].src=pathLayout+"spacing01.gif";
		break;
		default:
			all_img_tab[idTab-1].src=pathLayout+"spacing01.gif";
			all_img_tab[idTab].src=pathLayout+"spacing01.gif";
		break;
	}
}//--end function--

