// JavaScript Document
function set_obj_val(obj, val){
	document.getElementById(obj).value = val;
}
function get_obj_val(obj){
	return document.getElementById(obj).value;
}
function set_obj_html(obj, val){
	document.getElementById(obj).innerHTML = val;
}
function get_obj_html(obj){
	return document.getElementById(obj).innerHTML;
}
function set_obj_disabled(obj, val){
	document.getElementById(obj).disabled = val;
}
function set_obj_checked(obj, val){
	document.getElementById(obj).checked = val;
}
function get_obj_class(obj){
	return document.getElementById(obj).className;
}
function set_obj_class(obj, val){
	document.getElementById(obj).className	= val;
}	
function set_display(obj, val){
	document.getElementById(obj).style.display	= val;
}
function set_focus(obj){
	document.getElementById(obj).focus();
}
function window_location(url){
	window.location = url;
}
function window_reload(){
	window.location.reload();	
}	
function disable_button(obj){
	document.getElementById(obj).className	= 'button_disable';
	set_obj_disabled(obj,true);
}
function enable_button(obj){
	document.getElementById(obj).className	= 'button';
	set_obj_disabled(obj,false);
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function checkAllselected(elm,formName,st,eId){
	var el_collection	= eval("document.forms."+formName+"."+elm);
	var idTR			= "tr_0" + eId;

	if(el_collection.length>0){
		for (c=0;c<el_collection.length;c++){
			idTR	= 'tr_'+ c  + eId;
			el_collection[c].checked	= st;
			if(st){
				document.getElementById(idTR).bgColor='#ffe8cb';
			}else{
				document.getElementById(idTR).bgColor='#fbfaf7';
			}
		}
	}else{
		document.getElementById(elm).checked	= st;
		if(st){
			document.getElementById(idTR).bgColor='#ffe8cb';
		}else{
			document.getElementById(idTR).bgColor='#fbfaf7';
		}
	}
	set_obj_disabled('deleteAll' + eId, !st);
}
function swapCheckBox(elm,formName,eId){
	var chkstatus		= 0;
	var chktmp			= false;
	var idTR			= "tr_0" + eId;
	var el_collection	= eval("document.forms."+formName+"."+elm);
	set_obj_disabled('deleteAll' + eId, true);

	if(el_collection.length>1){
		for (c=0;c<el_collection.length;c++){
			idTR	= 'tr_' + c  + eId;
			if(el_collection[c].checked){
				document.getElementById(idTR).bgColor='#ffe8cb';
				set_obj_disabled('deleteAll' + eId, false);
				chkstatus++;
			}else{
				document.getElementById(idTR).bgColor='#fbfaf7';
			}
		}
		if(chkstatus == el_collection.length)
			chktmp	= true;
		else
			chktmp	= false;
	}else{
		chktmp	= el_collection.checked;
		set_obj_disabled('deleteAll' + eId, !chktmp);

		if(chktmp){
			document.getElementById(idTR).bgColor='#ffe8cb';
		}else{
			document.getElementById(idTR).bgColor='#fbfaf7';
		}
	}
	document.getElementById('checkAll' + eId).checked = chktmp;
}
function swapCheckTR(elm,formName,id,eId){
	var el_collection	= eval("document.forms."+formName+"."+elm);
	if(el_collection.length>1){
		var st	= el_collection[id].checked;
		el_collection[id].checked	= !st;
	}else{
		var st	= el_collection.checked;
		el_collection.checked	= !st;
	}
	swapCheckBox(elm,formName,eId);
}
function row_color_orver(ths_ojb){
	now_color=ths_ojb.bgColor;
	if(now_color!="#ffe8cb"){
		ths_ojb.bgColor	= "#ddeeff";
	}
}
function row_color_out(ths_ojb,color_new){
	now_color=ths_ojb.bgColor;
	if(now_color!="#ffe8cb"){
		ths_ojb.bgColor	= color_new;
	}
}
function check_editviewbt(obj,row){
	if(obj.checked==true){
		count_editviewbt=count_editviewbt+1;
		document.getElementById('order_id'+row).bgColor='#ffe8cb';
	}else{
		count_editviewbt=count_editviewbt-1;
		document.getElementById('order_id'+row).bgColor="#"+document.getElementById('order_id'+row).lang;
	}
}
function showAlert(txt, header, call){
	Ext.MessageBox.alert(header, txt, call);
}
function showConfirm(txt, header, call){
	Ext.MessageBox.confirm(header, txt, call);
}	
function callCalendar(elm, formatCalendar){			
	var date = new Ext.form.DateField({
		allowBlank:false,
		format: formatCalendar
	});
	date.applyTo(elm);
}	
function colorPalette(elm, inputElm, inputColor){			
	var cp = new Ext.ColorPalette({value:inputColor});  // initial selected color
	cp.render(elm);		
	cp.on('select', function(palette, selColor){
		document.getElementById(inputElm).value = selColor;// do something with selColor
	});		
}	
function replaceAll(OldString,FindString,ReplaceString) {  
	var SearchIndex = 0;  
	var NewString = "";   
	while (OldString.indexOf(FindString,SearchIndex) != -1) {  
		NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));  
		NewString += ReplaceString;  
		SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);   
	}  
	NewString += OldString.substring(SearchIndex,OldString.length);  
	return NewString;  
}
function getWindowWidthHigh() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth,myHeight];
}
function autoResize (tagId, pos) { // pos = '115'
	var aWH = getWindowWidthHigh();
	if(typeof( window.innerWidth )=='number'){
		document.getElementById(tagId).style.height =  (parseInt(aWH[1]) - pos + 5) +"px";	
	}else{
		document.getElementById(tagId).style.height =  (parseInt(aWH[1]) - pos) +"px";	
	}
} 
function popup_window(title_popup, url_popup, width_popup, height_popup){
	if(!width_popup){
		width_popup = 450;
	}
	if(!height_popup){
		height_popup = 350;
	}
	var genID	= 'my-dlg' + Math.random();
	myDialog = new Ext.BasicDialog(genID, {
				autoCreate:{
					tag:'div',
					cls:'x-dlg',
					children:[ {
						tag:'div',
						id: 'my-dlg-hd',
						cls:'x-dlg-hd',
						html:title_popup
					},{
						tag:'iframe',
						cls:'x-dlg-bd',
						src:url_popup,
						frameborder: 0,
						id: 'my-dlg-iframe'
					}]
				},
				width:width_popup,
				height:height_popup,
				shadow: true,
				modal: true,
				draggable:true,
				fixedcenter:true
			});
	myDialog.show();
}
function setTr (obj , param) {
	$$('tr.' + obj).each(
		function (s) {
			s.style.display = param;
		}
	)
}
function selectPackage(val, elm1, elm2) {
	var val1 = null;
	var val2 = null;
	if(val != ""){
		var mySplitResult = val.split("-");
		val1 = mySplitResult[0];
		val2 = mySplitResult[1];
	}
	document.getElementById(elm1).value = val1;
	document.getElementById(elm2).value = val2;
}
function checkPackage(elm, elm1, elm2) {	
	var val1 = null;
	var val2 = null;
	if(document.getElementById(elm).checked) {
		val1 = '1';
		val2 = document.getElementById(elm).value;
	}
	document.getElementById(elm1).value = val1;
	document.getElementById(elm2).value = val2;
}
function clearContent() {
	var content = document.getElementsByTagName('td');
	for (var i=0;i < content.length;i++) {
		if (content[i].className == 'detail-area') {
			content[i].innerHTML = '';
		}
	}
}

