String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
//ÆÄÀÏÀÇ È®ÀåÀÚ¸¦ °¡Á®¿È

function getFileExtension(filePath){
	var lastIndex = -1;
    lastIndex = filePath.lastIndexOf('.');
    var extension = "";

	if ( lastIndex != -1 ){
    extension = filePath.substring( lastIndex+1, filePath.len );
	} else {
		extension = "";
	}
	return extension;
}

//ÆÄÀÏÀ» ¼±ÅÃ ÈÄ Æ÷Ä¿½º ÀÌµ¿½Ã È£Ãâ
function uploadImg_Chk2(value,i){
	var fm=document.fm;
    var ext = getFileExtension(value);
    var file_div=document.getElementById("file_div_"+i);

    if (ext == "") {
        alert('¿Ã¹Ù¸¥ ÆÄÀÏÀ» ÀÔ·ÂÇÏ¼¼¿ä');
        
        file_div.innerHTML="";
			  file_div.innerHTML="<input type=\"file\" name=\"file\" class=\"bg_white01\" style=\"width:300px\" onkeydown=\"return false;\" onChange=\"imageChk(this.value,"+i+");\">";
		
        imgSrc = "";
			  imgFileSize = 0;
			  return false;
    }else if ( !((ext.toLowerCase() == "gif") || (ext.toLowerCase() == "jpg") || (ext.toLowerCase() == "jpeg")) ) {
        alert('jpg, jpeg, gif ÀÌ¹ÌÁö ÆÄÀÏ¸¸ ¿Ã¸± ¼ö ÀÖ½À´Ï´Ù.');

			  file_div.innerHTML="";
			  file_div.innerHTML="<input type=\"file\" name=\"file\" class=\"bg_white01\" style=\"width:300px\" onkeydown=\"return false;\" onChange=\"imageChk(this.value,"+i+");\">";
		
			  imgSrc = "";
			  imgFileSize = 0;
			  return false;
    }
}

function imageChk(value,i){
	var fm=document.photoFrm;
	var imgInfo = new Image();
	var ext = getFileExtension(value);
  uploadImg_Chk2(value,i);
	
	if(ext.toLowerCase() != "bmp") {
	fm.no.value = i;
	imgInfo.onload = setImage;
	imgInfo.src = value;
	}
}

function setImage(){
	var fm=document.photoFrm;
    var imgSrc, imgWidth, imgHeight, imgFileSize;
    var maxFileSize = 307200;
    imgSrc = this.src;
    imgWidth = this.width;
    imgHeight = this.height;
    imgFileSize = this.fileSize;

    if(imgWidth != 300 ){ alert("ÀÌ¹ÌÁö »çÀÌÁî°¡ »óÇÏ ¹è¿­ (°¡·Î 500), ÁÂ,¿ì ¹è¿­ (°¡·Î 300) °ú ´Ù¸¦°æ¿ì \n\n¿øº» ÀÌ¹ÌÁö¿Í´Â ´Ù¸£°Ô º¸ÀÏ ¼ö ÀÖ½À´Ï´Ù."); }
    var i = fm.no.value;

    if(i == 1){
      fm.imgW1.value = imgWidth;
      fm.imgH1.value = imgHeight;
    }else if(i == 2){
      fm.imgW2.value = imgWidth;
      fm.imgH2.value = imgHeight    
    }else if(i == 3){
      fm.imgW3.value = imgWidth;
      fm.imgH3.value = imgHeight    
    }else if(i == 4){
      fm.imgW4.value = imgWidth;
      fm.imgH4.value = imgHeight    
    }else if(i == 5){
      fm.imgW5.value = imgWidth;
      fm.imgH5.value = imgHeight    
    }else if(i == 6){
      fm.imgW6.value = imgWidth;
      fm.imgH6.value = imgHeight    
    }else if(i == 7){
      fm.imgW7.value = imgWidth;
      fm.imgH7.value = imgHeight    
    }else if(i == 8){
      fm.imgW8.value = imgWidth;
      fm.imgH8.value = imgHeight    
    }else if(i == 9){
      fm.imgW9.value = imgWidth;
      fm.imgH9.value = imgHeight    
    }else if(i == 10){
      fm.imgW10.value = imgWidth;
      fm.imgH10.value = imgHeight    
    }

	if(imgFileSize > maxFileSize){
		alert("ÀÌ¹ÌÁö Å©±â´Â 300K ±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù.");
		var file_div=document.getElementById("file_div_"+i);
    file_div.innerHTML="";
	  file_div.innerHTML="<input type=\"file\" name=\"file\" class=\"bg_white01\" style=\"width:300px\" onkeydown=\"return false;\" onChange=\"imageChk(this.value,"+i+");\">";

    imgSrc = "";
		imgFileSize = 0;
		return false;

	}
}
function writeChk(aT){

	var fm=document.photoFrm;

	if(fm.title.value.trim() == ""){
		alert("Á¦¸ñÀ» ÀÔ·ÂÇÏ¼¼¿ä.");
		fm.title.focus();
		return;
	}
	// ¿¡µðÅÍÀÇ ³»¿ëÀ» ¿¡µðÅÍ »ý¼º½Ã¿¡ »ç¿ëÇß´ø textarea¿¡ ³Ö¾î ÁÝ´Ï´Ù.
	oEditors.getById["ir1"].exec("UPDATE_IR_FIELD", []);
	fm.sub_content.value = fm.ir1.value.trim();	

	if(fm.content.value.trim() == ""){
		alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä.");
		return;
	}
	
	if(fm.file.value.trim() =='' && fm.oldImg.value.trim() ==''){
		alert('¸ÞÀÎÀÌ¹ÌÁö¸¦ ¼±ÅÃÇØ ÁÖ½Ê½Ã¿À.');
		return;
	}
	
	if(fm.main.checked){
		fm.mainYn.value = "Y";		
	}else{
		fm.mainYn.value = "N";
	}
	
    if(check() == true){ //ÀÔ·Â °¡´ÉÇÑ ¹®ÀÚ¸¸ ÀÔ·ÂµÇ¾ú´ÂÁö Ã¼Å©.
    	fm.aT.value = aT;
		fm.action = "http://165.243.187.81:8888/multi01/include/reg/tv_highlight_reg.jsp";	
//    	fm.action = "http://165.243.187.81:8888/multi01/include/reg/tv_highlight_reg_test.jsp";	
		fm.submit();
    }
}


function deleteChk(){

	var fm=document.fm;
	var cf=confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?");

	if(cf){

		fm.aT.value = "delete";		   
		fm.action = "http://165.243.187.81:8888/multi01/include/reg/tv_highlight_reg.jsp";
//		fm.action = "http://165.243.187.81:8888/multi01/include/reg/tv_highlight_reg_test.jsp";	
		fm.submit();
	}

}

function setChk(i){

  var fm = document.fm;
	var cnt= fm.delYnCnt.value;

	if(cnt == 1){
		if(fm.delYn.checked)  	fm.mainUse[i-1].checked = false;
	}else{
	  if(fm.delYn[i-1].checked)  	fm.mainUse[i-1].checked = false;
  }

}

function setChk2(i){

  var fm = document.fm;
	var cnt= fm.delYnCnt.value;
	
	if(cnt == 0){
    return;
  }

	if(cnt == 1){
		if(fm.mainUse[i-1].checked)  	fm.delYn.checked = false;
	}else{
	  if(fm.mainUse[i-1].checked)  	fm.delYn[i-1].checked = false;
  }
  
}

var mainImgCnt = 0;

function mainImgChk(i){
	var fm = document.fm;
  
	if(fm.mainUse[i-1].checked){
		mainCnt(i);
		if(mainImgCnt == 1){
			alert("¸ÞÀÎÀ¸·Î µî·ÏµÇ´Â ÀÌ¹ÌÁö´Â 463 * 245 (°¡·Î * ¼¼·Î)·Î ÃÖÀûÈ­ µÇ¾î ÀÖ½À´Ï´Ù.");
			return;
		}
	}
	 
	if(fm.mainUse[i-1].checked == false){
		mainCnt2();
	}
}

function mainCnt(i){
  
  mainImgCnt++;
  
  if(mainImgCnt > 1){
  	alert("¸ÞÀÎÀÌ¹ÌÁö´Â ÇÑ°³¸¸ Ã¼Å© ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.");
  	fm.mainUse[i-1].checked = false;
  	return;
  }
}

function mainCnt2(){
	mainImgCnt--;
}


//ÀÌ¹ÌÁö Å©±â¿¡ µû¶ó ÆË¾÷Ã¢¿¡ Ç¥½Ã
function showImg(fileName,tcd){
	var rootVirtual;
	var url="http://images.fcseoul.com:8888";
	//ÀÓ½Ã ·ÎÄÃ °æ·Î

    if(tcd == "tvhigh"){                                   //ÆÒ°¶·¯¸®
      rootVirtual = url + "/multi01/FCSTV/HighLight/";              
    }

    var wo=window.open("","show"," scrollbars=yes resizable=yes");
    wo.document.write("<html><head><title>ÀÌ¹ÌÁöº¸±â</title></head>\n");
    wo.document.write("<body>\n");
    wo.document.write("<script language='javascript'>{\n ");
    wo.document.write(" function resi(what){ \n");
    wo.document.write(" var im=document.img; \n");
    wo.document.write(" w=eval(im).width+50; \n h=eval(im).height+65; \n");
    wo.document.write(" window.resizeTo(w,h); \n");
    wo.document.write("}}<\/script> \n");
    wo.document.write(" <a href='javascript:window.close(); '> \n");
    wo.document.write("<img name='img' ");
    wo.document.write(" src='"+rootVirtual+fileName+"' border=0 onLoad=resi('"+rootVirtual+fileName+"');></a>");
    wo.document.write("</body></html> \n");
}

function check() //³»¿ë ½ºÅ©¸³Æ® º¸¾È Ã³¸®
{
	var srcText = document.photoFrm.content.value;
  
  if(check3() == true) { //Á¦¸ñ¿¡ »ç¿ëÇÒ¼ö ÀÖ´Â ÅÂ±×°¡ µé¾î¿À¸é true ¸®ÅÏÇÏ°í ³»¿ë °Ë»ç.
  
		if(existDisallowedTags(srcText))
		{
			alert('Çã¿ëµÇÁö ¾Ê´Â ÅÂ±×¸¦ »ç¿ëÇÏ¼Ì½À´Ï´Ù.');
			return false;
		}
		else
		{
			//alert('ÀÔ·Â°¡´ÉÇÑ ¹®ÀÚ¿­ÀÔ´Ï´Ù.');
			return true;
		}
	}else { //Á¦¸ñ¿¡ Çã¿ëÇÒ ¼ö ¾ø´Â ÅÂ±×¸¦ »ç¿ëÇÏ¸é  false ¸®ÅÏÇØ¼­ ÀÔ·Â ¸·À½.
		alert('Çã¿ëµÇÁö ¾Ê´Â ÅÂ±×¸¦ »ç¿ëÇÏ¼Ì½À´Ï´Ù.');
		return false;
	}
}

function check3() //Á¦¸ñ ½ºÅ©¸³Æ® º¸¾È Ã³¸®
{
	var srcText = document.photoFrm.title.value;

	if(existDisallowedTags(srcText))
	{
		//alert('Çã¿ëµÇÁö ¾Ê´Â ÅÂ±×¸¦ »ç¿ëÇÏ¼Ì½À´Ï´Ù.');
		return false;
	}
	else
	{
		//alert('ÀÔ·Â°¡´ÉÇÑ ¹®ÀÚ¿­ÀÔ´Ï´Ù.');
		return true;
	}
}

/**
 * ÀÔ·ÂÇÑ ¹®ÀÚ¿­¿¡¼­ Çã¿ëÇÏÁö¾ÊÀ» ÅÂ±×ÀÌ¸§À» µî·ÏÇÑ´Ù.
 */
var disallowedTags = new Array('SCRIPT');

/**
 * disallowedTags¿¡ µî·ÏµÈ ÅÂ±×°¡ »ç¿ëµÇ¾ú´ÂÁö È®ÀÎÇÑ´Ù.
 * testDisallowTagÇÔ¼ö´Â ¿©´Â ÅÂ±×¿Í ´Ý´Â ÅÂ±×¸¦ µ¿½Ã¿¡ °Ë»çÇÏÁö ¾Ê±â ¶§¹®¿¡ 
 * Á÷Á¢ È£ÃâÇØ¼­ »ç¿ëÇÒ °æ¿ì´Â ÁÖÀÇÇØ¾ß ÇÑ´Ù.
 * @parameter srcText Ã³¸®´ë»ó¹®ÀÚ¿­
 * @parameter flag Ã³¸®´ë»ó ÅÂ±×
 *					- openTag : ½ÃÀÛÅÂ±× Ã³¸®(±âº»°ª)
 *					- closeTag : Á¾·áÅÂ±× Ã³¸®
 * @return isDisallowed Çã¿ëÇÏÁö¾Ê´Â ÅÂ±×ÀÇ »ç¿ë¿©ºÎ
 * @see disallowedTags
 */
function testDisallowTag(srcText, flag)
{
	if(flag == null || flag == '')
	{
		flag = 'openTag';
	}

	var disallowTagCnt = disallowedTags.length;
	var isDisallowed = false;
	var closedMark = '';

	if(flag == 'openTag')
	{
		var re = /<([A-Za-z]+)[\s]*[^>]*>/i;
		closedMark = '';
	}
	else
	{
		var re = /<\/[\W]*([A-Za-z]+)[\W]*>/i;
		closedMark = '/';
	}

	var tmpText = srcText;
	var txtLen = tmpText.length;

	while(tmpText.length > 0)
	{
		var matchInfo = tmpText.match(re);

		if(matchInfo != null)
		{
			var item1 = matchInfo[1];
			var item2 = matchInfo[2];

			var origitItem1 = item1;

			item1 = (item1 == null ? '' : item1).toUpperCase();
			item2 = (item2 == null ? '' : item2);

			if(flag == 'closeTag')
			{
				item1 = item1.trim();
			}

			for(var i = 0; i < disallowTagCnt; i++)
			{
				if(item1 == disallowedTags[i])
				{
					isDisallowed = true;
					break;
				}
			}

			if(isDisallowed)
			{
				break;
			}

			tmpText = tmpText.substring(matchInfo.lastIndex, tmpText.length);
		}
		else
		{
			tmpText = '';
		}
	}
	
	return isDisallowed;
}

/**
 * ¹®ÀÚ¿­¿¡¼­ Çã¿ëÇÏÁö ¾Ê´Â ÅÂ±×¸¦ »ç¿ëÇÏ´ÂÁö È®ÀÎÇÑ´Ù.
 */
function existDisallowedTags(srcText)
{
	var existDisallowedTag = false;

	if(testDisallowTag(srcText, 'openTag') || testDisallowTag(srcText, 'closeTag'))
	{
		existDisallowedTag = true;
	}

	return existDisallowedTag
}

function makeFile(site)
{
	var fm = document.makeFile ;
	
	if(site == "nate")	fm.action = "/fcstv/news_file_nate.jsp" ;
	if(site == "yahoo")	fm.action = "/fcstv/news_file_yahoo.jsp" ;
	if(site == "msn")	fm.action = "/fcstv/news_file_msn.jsp" ;
	fm.submit();
}

/**
 * Áö³­½ÃÁð ÇÏÀÌ¶óÀÌÆ® vod º¸±â
 */
function view(cd,match_ymd,team_part,grade){
	  var fm =document.popform;
	  fm.match_ymd.value = match_ymd;
    fm.team_part.value = team_part;
     
    if(cd == "vod"){

        window.open("","vodhigh","width=394, height=414, scrolling=yes");
        fm.target="vodhigh";
	      fm.action="/match/result/highlight_view.jsp";
	      fm.submit();
	      
    }else if(cd == "relay"){
        conf();
        var url=popform.conf.value;

        window.open("","text","width=610, height=600, scrollbars=yes");
        fm.target="text";
	      fm.action=url+"/multi01/sum_text.jsp";
	      fm.submit();
    }
}

/**
 * Áö³­½ÃÁð ³¯Â¥º° °Ë»ö
 */
function searchHt(){ /// ³¯Â¥º° °Ë»ö
   var fm=document.fm; 
   fm.aT.value = "search";
   fm.action = "tv_plight_list.jsp";
   fm.submit();
  }
  
  
/**
 * Next Match·Î ÀÌµ¿
 */
function move_next_match() {
	var fm = document.matchFm;

	fm.target = '_self';
	fm.action = '/match/match/nextMenu_list.jsp';
	fm.submit();	
}

/**
 * Last Match·Î ÀÌµ¿
 */
function move_last_match() {
	var fm = document.matchFm;

	fm.target = '_self';
	fm.action = '/match/match/lastMenu_list.jsp';
	fm.submit();	
}

/**
 * Á¤·Ä 2¿¡ µ¿¿µ»ó µî·Ï
 */
function insMovie(){
	var fm = document.matchFm;
	window.showModalDialog("movUpload.jsp",window,"dialogWidth:546px; dialogHeight:70px; scroll:0; help:0; status:0;");
}
function insMovie_mobile(){
	var fm = document.matchFm;

	
	window.showModalDialog("movUpload_mobile.jsp",window,"dialogWidth:546px; dialogHeight:70px; scroll:0; help:0; status:0;");
}


/**
 * »ó¼¼
 */

function viewClick(seq){
	var frm = document.listFrm;
	frm.seq.value = seq;
	frm.action = 'tv_highlight_view.jsp';
	frm.submit();
}

/**
 * Áö³­½ÃÁð ÇÏÀÌ¶óÀÌÆ®
 */
function listP(yy){
	if(yy != ""){
		location.href="tv_plight_list.jsp?yy="+yy;
	}
} 
