var curEditor = 'EDIT';
var curSelect;

/**
* ¿¡µðÆ® Àû¿ë
* @param excute : Àû¿ë ¸í·É
* @param values : Å¸ÀÔ
*/
function htmledit(excute, values){
	if(values == null){
		document.all['EDIT'].focus();
		document.all['EDIT'].document.execCommand(excute);
	}else{
		if(excute == "BgColor"){
			document.all['EDIT'].style.backgroundColor = values;
			document.all['editbgColor'].value = values;
		}else{
			document.all['EDIT'].focus();
			document.all['EDIT'].document.execCommand(excute, false, values);
		}
	}
}



function editLink(val,lIndex){
	if(val == "http://"){
		alert("¸µÅ© ÁÖ¼Ò¸¦ ÀÔ·Â ÇÏ¼¼¿ä.");
		document.getElementById('linkText').focus();
		return false;
	}

	if(curSelect.text == ""){
		//curSelect.pasteHTML("<a href="+val+">"+val+"</a>");
		document.all['EDIT'].insertAdjacentHTML("beforeEnd","<a href="+val+">"+val+"</a>");
		curSelect.select();
		//document.all['EDIT'].focus();
	}else{
		curSelect.select();
		document.all['EDIT'].document.execCommand("createlink", false, val);
	}
	setShowView(lIndex,'hiddenId[]',1);
	document.getElementById('linkText').value;
}

function multLink(val,lIndex){
	if(val == "http://"){
		alert("¸µÅ© ÁÖ¼Ò¸¦ ÀÔ·Â ÇÏ¼¼¿ä.");
		document.getElementById('imgLinkText').focus();
		return false;
	}
	var ext = val.substr(val.lastIndexOf(".")+1, val.length).toLowerCase();

	if( ext == "gif" || ext=="jpg" || ext=="png" ){
		var hStr = "<DIV><img id='editImgFile[]' src='" + val + "' align='absmiddle' ></DIV>"
	}else if(ext == "swf"){
		hStr = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\">";
		hStr += "<PARAM NAME=\"movie\" VALUE=\""+val+"\">";
		hStr += "<EMBED src=\""+val+"\" quality=high TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>";
		hStr += "</OBJECT>";
	}else{
		val = val.replace(/'/g, "\'");
		var hStr = "<embed width='280' heigth='200' src='" + val + "' >"
	}

	if(ie){

		if(curSelect.text == ""){
			document.all['EDIT'].innerHTML = document.all['EDIT'].innerHTML + hStr;
		}else{
			curSelect.pasteHTML(hStr);
		}
	}else{
		document.all['EDIT'].innerHTML = document.all['EDIT'].innerHTML + hStr;
	}

	setShowView(lIndex,'hiddenId[]',1);
	document.getElementById('imgLinkText').value=="";
}


function setTable(param,lIndex){
	var doc = document;
	var table = doc.createElement("table");

	for (var field in param) {
		var value = param[field];
		if (!value) {
			continue;
		}
		switch (field) {
			case "tWidth"   :
				table.style.width = value + param["tWType"];
				break;
			case "tAlign"   :
				table.align	 = value;
				break;
			case "tBoard"  :
				table.border	 = parseInt(value);
				break;
			case "tCSpacing" :
				table.cellspacing = parseInt(value);
				break;
			case "tCPadding" :
				table.cellpadding = parseInt(value);
				break;
		}
	}

	var tbody = doc.createElement("tbody");
	table.appendChild(tbody);
	for (var i = 0; i < param["tCols"]; ++i) {
		var tr = doc.createElement("tr");
		tbody.appendChild(tr);
		for (var j = 0; j < param["tRows"]; ++j) {
			var td = doc.createElement("td");
			tr.appendChild(td);
			// Mozilla likes to see something inside the cell.
			if (!ie) {
				var br = doc.createElement("br");
				td.appendChild(br);
			}
		}
	}

	if(ie){

		if(curSelect.text == ""){
			//curSelect.pasteHTML(table.outerHTML);
			document.all['EDIT'].innerHTML = document.all['EDIT'].innerHTML + table.outerHTML;
		}else{
			curSelect.pasteHTML(table.outerHTML);
		}
	}else{
		document.all['EDIT'].innerHTML = document.all['EDIT'].innerHTML + table.outerHTML;
	}

	setShowView(lIndex,'hiddenId[]',1);
}


function chOk(lIndex){
	var fArray = ["tRows","tCols","tWidth","tWType","tAlign","tBoard","tCSpacing","tCPadding"];

	var param = new Object();

	for(var i in fArray){
		var id = fArray[i];
		var el = document.getElementById(id);
		param[id] = el.value;
	}

	setTable(param,lIndex);
}
/**
* ¿¡µðÅÍ¿¡¼­ ¼±ÅÃµÈ ¹®ÀÚ¿­ÀÇ ¿ÀºêÁ§Æ®
* $reutrn curSelect : ¼±ÅÃµÈ ¿ÀºêÁ§Æ®
*/
function getSelect(){
	//alert(document.all['EDIT'].selection.createRange());
	if(ie){
		curSelect = document.selection.createRange();
		//curSelect = eval(curEditor + ".document.selection.createRange()");
	}else{
		//curSelect = document.getElementById('EDIT').contentWindow);
		curSelect = (document.getElementById(curEditor).contentWindow) ? document.getElementById(curEditor).contentWindow.getSelection() : e_H_body.getSelection();
	}
}

/**
* ÀÌ¹ÌÁö ¿¡µðÅÍ¿¡ Ãß°¡
* $reutrn curSelect : ¼±ÅÃµÈ ¿ÀºêÁ§Æ®
*/
function setImgTag(url, docW, docH , maxW){
	try{
		
		maxW = maxW - 100;
		//alert(docW +" < "+ maxW);
		var hStr = "";        
		if(docW < maxW){
			//hStr = "<DIV><img id='editImgFile[]' src='" + url + "' width='"+docW+"' height='"+docH+"' align='absmiddle' style='cursor:hand;' onClick=\"clubLocation2('/K_config/includeFile/webEdit/include/imageView.php','', 'imgView', 'imgView', '300', '300','img|"+url+"');\"></DIV>"
			hStr = "<DIV><a href='" + url + "' rel='lightbox'><img id='editImgFile[]' src='" + url + "' width='"+docW+"' height='"+docH+"' align='absmiddle' border='0'></a></DIV>"
		}else{
			maxW = maxW - 30;
			//hStr = "<DIV><img id='editImgFile[]' src='" + url + "' width='"+maxW+"' align='absmiddle' style='cursor:hand;' onClick=\"clubLocation2('/K_config/includeFile/webEdit/include/imageView.php','', 'imgView', 'imgView', '300', '300','img|"+url+"');\"></DIV>"
			hStr = "<DIV><a href='" + url + "' rel='lightbox'><img id='editImgFile[]' src='" + url + "' width='"+maxW+"' align='absmiddle' border='0'></a></DIV>"
		}
		document.all['EDIT'].insertAdjacentHTML("beforeEnd",hStr);
		curSelect.select();
	}catch(E){
		//alert('ÀÌ¹ÌÁö ¼±ÅÃÀÌ µÇ¾î ÀÖ½À´Ï´Ù.\nÀÌ¹ÌÁö »ðÀÔÀ» ÇÒ ¼ö ¾ø½À´Ï´Ù.');
	}
}

/**
* ¿¡µðÅÍ Å¸ÀÔ º¯°æ
* @param $type : ¿¡µðÅÍ Å¸ÀÔ  (E:¿¡µðÅÍ, H:HTML, T:TEXT)
*/
function setEditType(type, tWidth, tHeight){
	if(type == "E"){
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01_1.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03.gif";
		document.all['editType'].value = "E";
		document.all['toolBar'].style.display = "";
		document.all['editTr'].style.display = "";
		document.all['htmlTr'].style.display = "none";
		document.all['EDIT'].innerHTML = document.all['webContent'].value;
	}else if(type == "H"){
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02_1.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03.gif";
		document.all['editType'].value = "H";
		document.all['toolBar'].style.display = "none";
		document.all['editTr'].style.display = "none";
		document.all['htmlTr'].style.display = "";
		document.all['webContent'].style.height = parseInt(tHeight)+40;
		document.all['webContent'].value = document.all['EDIT'].innerHTML;
	}else{
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03_1.gif";
		document.all['editType'].value = "T";
		document.all['toolBar'].style.display = "none";
		document.all['editTr'].style.display = "none";
		document.all['htmlTr'].style.display = "";
		document.all['webContent'].style.height = parseInt(tHeight)+40;
		document.all['webContent'].value = document.all['EDIT'].innerHTML;
	}
}


/**
* ¿¡µðÅÍ ÃÊ±âÈ­
* @param $type : ¿¡µðÅÍ Å¸ÀÔ  (E:¿¡µðÅÍ, H:HTML, T:TEXT)
*/
function editLoadHandler(type, tWidth, tHeight){
	if(type == "E"){
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01_1.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03.gif";
		document.all['editType'].value = "E";
		document.all['toolBar'].style.display = "";
		document.all['editTr'].style.display = "";
		document.all['htmlTr'].style.display = "none";
	}else if(type == "H"){
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02_1.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03.gif";
		document.all['editType'].value = "H";
		document.all['toolBar'].style.display = "none";
		document.all['editTr'].style.display = "none";
		document.all['htmlTr'].style.display = "";
		document.all['webContent'].style.height = parseInt(tHeight)+40;
	}else{
		document.all['typeE'].src = "/K_config/includeFile/webEdit/images/menu01.gif";
		document.all['typeH'].src = "/K_config/includeFile/webEdit/images/menu02.gif";
		document.all['typeT'].src = "/K_config/includeFile/webEdit/images/menu03_1.gif";
		document.all['editType'].value = "T";
		document.all['toolBar'].style.display = "none";
		document.all['editTr'].style.display = "none";
		document.all['htmlTr'].style.display = "";
		document.all['webContent'].style.height = parseInt(tHeight)+40;
	}
}


/**
* °Ô½ÃÆÇ ¿¡µðÅÍ»ç¿ë
* param -> action : formÀÇ action
* param -> frm : Æû ¸íÄª
* param -> target : Àü¼Û target
* param -> aStr
*/
function editInputCheck(action, frm, target){
	var select = false;
	for(i=0; i<document.forms[frm].length; i++){
		if(document.forms[frm][i].itemTitle != null){
			switch(document.forms[frm][i].itemType){
				case "EDIT":
					if(inputEdit(frm, i) == false){
						return;
					}
					break;
				case "EMAIL":
					if(inputMail(frm, i) == false){
						return;
					}
					break;
				case "TEL":
					if(inputCheckHP(frm, i,"F") == false){
						return;
					}
					break;
				case "NUM":
					if(inputCheckNum(frm, i) == false){
						return;
					}
					break;
				case "DUMP":
					if(inputDefault(frm, i,"F") == false){
						return;
					}
					break;
				default:
					if(inputDefault(frm, i,"T") == false){
						return;
					}
					break;
			}
		}
	}

	if(document.forms[frm].formTitle != null){
		if(document.forms[frm].itemURI != null){
			if(document.forms[frm].itemURI == "URI"){
				select = confirm(decodeURI(document.forms[frm].formTitle));
			}else{
				select = confirm(document.forms[frm].formTitle);
			}
		}else{
			select = confirm(document.forms[frm].formTitle);
		}
	}else{
		select = true;
	}

	if(select == true){
		document.forms[frm].target = target;
		document.forms[frm].action = action;
		document.forms[frm].submit();
		return;
	}else{
		return;
	}
}


/**
* SMS ÁÖ¼Ò ÀÔ·Â
* param -> action : formÀÇ action
* param -> frm : Æû ¸íÄª
* param -> target : Àü¼Û target
* param -> aStr
*/
function smsInputCheck(action, frm, target){
	var select = false;
	//alert(document.forms[frm]['hp[]'][0].value);

	for(i=0; i<document.forms[frm].length; i++){

		if(document.forms[frm][i].itemTitle != null){
			switch(document.forms[frm][i].itemType){
				case "HP":
					//alert("DDD");

					var str = "F";
					if(inputCheckHP(frm, i, str) == false){
						return;
					}
					//alert("ccc");
					break;
				case "EMAIL":
					if(inputMail(frm, i) == false){
						return;
					}
					break;
				case "NAME":
					if(inputCheckName(frm, i) == false){
						return;
					}
					break;
				default:
					alert("default");
					if(inputDefault(frm, i) == false){
						return;
					}
					break;
			}
		}
	}

	if(document.forms[frm].formTitle != null){
		if(document.forms[frm].itemURI != null){
			if(document.forms[frm].itemURI == "URI"){
				select = confirm(decodeURI(document.forms[frm].formTitle));
			}else{
				select = confirm(document.forms[frm].formTitle);
			}
		}else{
			select = confirm(document.forms[frm].formTitle);
		}
	}else{
		select = true;
	}

	if(select == true){
		document.forms[frm].target = target;
		document.forms[frm].action = action;
		document.forms[frm].submit();
		return;
	}else{
		return;
	}
}

/**
* ÀÔ·Â Ã¼Å©
* param -> action : formÀÇ action
* param -> frm : Æû ¸íÄª
* param -> target : Àü¼Û target
* param -> aStr
*/
var CHECKINPUT = "T";
function kInputCheck(action, frm, target){
	try{
		var select = false;		
		for(i=0; i<document.forms[frm].length; i++){
			if(document.forms[frm][i].itemTitle != null){
				
				var thisType = document.forms[frm][i].itemValue;
				switch(document.forms[frm][i].itemType){					
					case "EDIT":
						if(inputEdit(frm, i) == false){
							return;
						}
						break;
					case "EMAIL":
						if(inputMail(frm, i) == false){
							return;
						}
						break;
					case "USERID":
						if(inputCheckUserId(frm, i) == false){
							return;
						}
						break;
					case "JUMINCHECK":
						if(inputCheckUserId(frm, i) == false){
							return;
						}
						break;
					case "PASSWORD":
						if(inputCheckPassword(frm, i, thisType) == false){
							return;
						}
						break;
					case "TEL":
						if(inputCheckTel(frm, i) == false){
							return;
						}
						break;
					case "NUM":
						if(inputCheckNum(frm, i) == false){
							return;
						}
						break;
					case "HP":
						if(inputCheckHP(frm, i, "F") == false){
							return;
						}
						break;
					case "CHOICE":
						if(inputCheckChoice(frm, i) == false){
							return;
						}
						break;
					case "IMAGE":						
						if(inputCheckImage(frm, i) == false){
							return;
						}
						break;
					case "FILE":
						if(inputCheckFile(frm, i) == false){
							return;
						}
						break;
					default:
						if(inputDefault(frm, i,"T") == false){
							return;
						}
						break;
				}
			}
		}

		if(document.forms[frm].formTitle != null){
			if(document.forms[frm].itemURI != null){
				if(document.forms[frm].itemURI == "URI"){
					select = confirm(decodeURI(document.forms[frm].formTitle));
				}else{
					select = confirm(document.forms[frm].formTitle);
				}
			}else{
				select = confirm(document.forms[frm].formTitle);
			}
		}else{
			select = true;
		}

		if(select == true){
			document.forms[frm].target = target;
			document.forms[frm].action = action;
			document.forms[frm].submit();
			return;
		}else{
			return;
		}
	}catch(E){ }
}

/**
* ÀÔ·Â Ã¼Å©
* param -> action : formÀÇ action
* param -> frm : Æû ¸íÄª
* param -> target : Àü¼Û target
* param -> aStr
*/
var CHECKINPUT = "T";
function popInputCheck(action, frm, target){
	try{
		var select = false;
		for(i=0; i<document.forms[frm].length; i++){
			if(document.forms[frm][i].itemTitle != null){
				switch(document.forms[frm][i].itemType){
					case "EDIT":
						if(tempType != "D" && tempType !="E"){
							if(inputEdit(frm, i) == false){
								return;
							}
						}
						break;
					case "EMAIL":
						if(inputMail(frm, i) == false){
							return;
						}
						break;
					case "NUM":
						if(inputCheckNum(frm, i) == false){
							return;
						}
						break;
					case "CHOICE":
						if(inputCheckChoice(frm, i) == false){
							return;
						}
						break;
					default:
						if(inputDefault(frm, i,"T") == false){
							return;
						}
						break;
				}
			}
		}

		if(document.forms[frm].formTitle != null){
			if(document.forms[frm].itemURI != null){
				if(document.forms[frm].itemURI == "URI"){
					select = confirm(decodeURI(document.forms[frm].formTitle));
				}else{
					select = confirm(document.forms[frm].formTitle);
				}
			}else{
				select = confirm(document.forms[frm].formTitle);
			}
		}else{
			select = true;
		}

		if(select == true){
			document.forms[frm].target = target;
			document.forms[frm].action = action;
			document.forms[frm].submit();
			return;
		}else{
			return;
		}
	}catch(E){}
}

/**
* °Ô½ÃÆÇ ¼öÁ¤ (´ÜÀÏ ÆÄÀÏÃ·ºÎ)
*/
function pMod(){
	if(document.all['pMod1'].style.display == ""){
		document.all['pMod'].style.display = "";
		document.all['pMod1'].style.display = "none";
	}
}
