
function cls_ajax(){}

cls_ajax.prototype = {

	exec : function(url , pars , fn_oncomplete , fn_onfailure, strMethod){
		fn_onfailure = fn_onfailure || "cf_ajax_onfailure";
		strMethod = strMethod || "get";
		var ajax = new Ajax.Request(
			url, 
			{
				method: strMethod, 
				parameters: pars, 
				onComplete: fn_oncomplete,
				onFailure : fn_onfailure
			});
	}
}

function cls_xml_util(){}

cls_xml_util.prototype = {
	getxmltext : function(xmltextnode){

		if(xmltextnode==null) return "";
		return window.isIE?xmltextnode.text:xmltextnode.textContent;
	},
	
	getxmlroot : function(originalRequest){
	
		var xmlroot = originalRequest.responseXML.documentElement;
	
		if(xmlroot==null){
			alert("Åë½ÅÀå¾Ö");
		}
	
		return xmlroot;
	},
	
	getelement : function(xmlroot , nodename){
		return xmlroot.getElementsByTagName(nodename);
	},
	
	gettextelement : function(originalRequest , nodename , num){
		num = num || 0;
		var xmlroot = this.getxmlroot(originalRequest);
		var objresult = this.getelement(xmlroot ,nodename);
		var textelement = this.getxmltext(objresult[num].firstChild);

		return textelement;
	}
}


function cf_ajax_onfailure(){
	alert("Åë½ÅÀå¾Ö");
}

function $dummy_string(){
	
	var retVal = "";
	var dummydate = new Date();
	retVal = dummydate.getMilliseconds();
	
	return retVal;
}
	
function $obj(obj,count){

	var index=0;
	var props = "";
	for(var prop in obj){

		index++;
		props+= prop +"\n";
		if(index>(count || 20)){
			alert(props);
			props = "";
			index = 0;
		}

	}
	alert(props)
}

/**
 * title¿¡ °ø¹é¹®ÀÚ Æ÷ÇÔ½Ã IE¿¡¼­ ¿À·ù
 */
function fn_popup_open(url, title, sub) {
	try {
		if(url == null) {
			return;
		}
		title = title || "";
		sub = sub || "";
		return window.open(url, title, sub);
	} catch(ex) {
		alert(ex.message);
	}
}

var $ceobj = function(target_dom,tag,id,name,allowtransparency){

	target_dom = target_dom || document;
	
	allowtransparency = allowtransparency || false;
	var obj = null;
	tag = tag || "div";
	id = id || "";
	name = name || id;
	
	var objtag = tag;
	
	if(typeof(window.event)!="undefined"){
	
	if(allowtransparency && tag=="iframe"){
		objtag = id.trim()=="<iframe allowtransparency='true'>"? tag :'<{0} id="{1}" name="{2}" allowtransparency="true">';
	}else{
		objtag = id.trim()==""? tag :'<{0} id="{1}" name="{2}">';
	}
	
	objtag = objtag.format(tag,id,name);
	}
	
	obj = target_dom.createElement(objtag);
	
	if(id.trim()!="") obj.setAttribute("id",id);
	if(name.trim()!="") obj.setAttribute("name",name);
	
	return obj;
}



var $ce = function(tag,id,name,allowtransparency){

	var is_child_window = !(self==parent);

	return $ceobj((is_child_window?parent.document:document),tag,id,name,allowtransparency);
}

function cf_isEmpty(form, obj) {
	for(var i=0; i<obj.length; i++) {
		var objTemp = document.getElementsByName(obj[i][0])[0];
		if(objTemp){
	        if(cf_trim(objTemp.value).length <= 0) {
	            alert(obj[i][1]+"À»(¸¦) ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.");
	            objTemp.focus();
	            return true;
	        }
        }
    }
    return false;
}

function cf_trim(str) {
    return cf_rightTrim(cf_leftTrim(str));
}

function cf_leftTrim(str) {
    return str.replace(/^\s+/, "");
}
function cf_rightTrim(str) {
    return str.replace(/\s+$/, "");
}

//============================================================
// ÀÌ¸ÞÀÏ Çü½Ä Ã¼Å©
//============================================================
function cf_validate_email(email_value){
	var obj_exp = new RegExp("\\w+@\\w+(.\\w+){1,2}");
	return obj_exp.test(email_value);
}
//============================================================
// 
//============================================================
function cf_validate(obj, flag, message, pattern){
	
	flag = flag || "number";
	pattern = pattern || "0123456789";
	message = message || "ÀÔ·ÂÇÏ½Å Á¤º¸°¡ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.";
	
	var obj_value = obj.value;
	var obj_value_length = obj_value.length;
	var ret_val = obj_value_length == 0 ? false : true;
	
	if(flag == "email"){
		ret_val = cf_validate_email(obj_value);
	}else{
		for(var idx=0;idx<obj_value_length;idx++){
			if(pattern.indexOf(obj_value.charAt(idx)) < 0 ){
				ret_val = false;
			}
		}
	}
	
	if(!ret_val) {
		alert(message);
		obj.focus();
	}
	return ret_val;			
}


function cf_image_resize(content_id){
	var obj_content = document.getElementById(content_id);
	
	if(obj_content){
		var objs_img = obj_content.getElementsByTagName("img");
		for(var idx = 0 ; idx < objs_img.length ; idx++){
			alert(objs_img[idx].width)	
		
		
		}
	}
}

function cf_regist_image_event(parentnode , objs, limit_width){
	limit_width = limit_width || 600;
	var obj_image = null;
	
	for(var i=0;i<objs.length;i++){
		obj_image = new Image();
		obj_image.src = objs[i].src;
		
		if(obj_image.width > limit_width){
			objs[i].width = limit_width;
		}
		objs[i].style.display = "block";
	}
}

function cf_image_resize(obj_id){
	
	var limit_width = 600;
	var obj = document.getElementById(obj_id);
	var obj_images = null;
	if(obj){
		obj_images = obj.getElementsByTagName("img");
		cf_regist_image_event(obj , obj_images, limit_width);
	}
}


function cf_file_search(fileId, textId){
	var obj_file = $(fileId);
	var obj_text = $(textId);
	obj_file.click();
	obj_text.value = obj_file.value;
	
}

//°ø¹é  null°ª Ã¼Å© ÇÔ¼ö
function check_space(str,msg)
{
   var ascii=0;
   var space_length=0;
   var enter_length=0;
   var tab_length=0;
   var total_length=0;

   for (var i=0; i<str.value.length; i++)   {
      ascii = str.value.charCodeAt(i);
      if ( ' ' == str.value.charAt(i) )
         space_length++;
      if ( ascii == 13)
         enter_length++;
      if ( ascii == 9)
         tab_length++;
   }
   total_length = space_length + 2 * enter_length + tab_length;
   if( total_length == str.value.length ){
      alert(msg);
      return;
   }
   return true;
}


// ºó°ª Ã¼Å© ÇÔ¼ö
function checkParam(param,alert_val){
	var value = param.value;
	
	if(value == null || value.length < 1){
		alert(alert_val+'À»(¸¦) ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À.');
		param.focus(); 
		return false; 
	}
	return true;
}

function trim( text ) {
	return (text || "").replace( /^\s+|\s+$/g, "" );
}
