function display(id){
	switch(id){
		case "loginphp":
			$('joinphp').style.display = "none"

			if($(id).style.display == "none"){
				$(id).style.display = "";
			}else{
				$(id).style.display = "none";
			}
			if(document.login.uid.value){
				document.login.upw.focus();
			}else{
				document.login.uid.focus();
			}

			return false;
			break;
		case "joinphp":
			$('loginphp').style.display = "none"
			break;
	}

	if($(id).style.display == "none"){
		$(id).style.display = "";
	}else{
		$(id).style.display = "none";
	}
}

function display2(id){
	if($(id).style.display == "none"){
		$(id).style.display = "";
	}else{
		$(id).style.display = "none";
	}
}

function authmain(email){
	$("abckedf").href = 'http://www.'+email;
//	document.joinForm.reset();
	display("joinphp");
	display("joinokmsg");
	$('authemail').value = email;
}

//쿠기관련
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()+6); 
var cookieName = ""; 

if (document.cookie != "") { 
        cookieName = document.cookie.split("=")[1]; 
} 

function setCookie(cookieName,value){ 
        document.cookie = cookieName+"="+value+";expires=" + expireDate.toGMTString(); 
} 


// 쿠키 버리기 함수 
function deletecookie(){ 
	if (document.cookie != "") {
			var thisCookie = document.cookie.split("; ");
			expireDate = new Date();
			expireDate.setDate(expireDate.getDate()-1);
			for (i=0; i<thisCookie.length; i++) {
					document.cookie = thisCookie[i] + ";expires=" + expireDate.toGMTString();
			} 
	} 
} 

function winOpen(url){
	 var cw=700;
	 var ch=450;
	 
	 var sw=screen.availWidth;
	 var sh=screen.availHeight;

	 var px=(sw-cw)/2;
	 var py=(sh-ch)/2;

	window.open(url, "", "width="+cw+",height="+ch+",top="+py+",left="+px); 
}

function lib_process(args){
	$('ifmsubmit').src = "http://www.kushow.com/lib/process.php?type="+args;
}

function ajaxStart(args){
	var val = args.val;
	var URL = "../lib/process.php";

	new Ajax.Request(URL,{
		method:'get',
		asynchronous: true,
		contentType: 'application/x-www-form-urlencoded',
		encoding: 'UTF-8',
		parameters:	{'val':args.val,'type':args.type,'num':args.num},
		onSuccess:	function(xmlHttp, json){
			var Arr = xmlHttp.responseText.split("|||");
			//공백제거
			var type = Arr[0].gsub(/^\s+/,"");
			switch(type){
				case "imgchange":
					if(Arr[1]){
						if(Arr[3]){
							$("intesfdgdsagdsef"+Arr[2]).innerHTML = '<img src="../image/button_vote02_on.gif">'; 
						}else{
							$("intesfdgdsagdsef"+Arr[2]).innerHTML = '<img src="../image/button_vote01_on.gif">'; 
						}
					}else{
						if(Arr[3]){
							$("intesfdgdsagdsef"+Arr[2]).innerHTML = '<img src="../image/button_vote02.gif" style="cursor:hand;cursor:pointer;" onclick="voteplus('+Arr[2]+',1);">'; 
						}else{
							$("intesfdgdsagdsef"+Arr[2]).innerHTML = '<img src="../image/button_vote01.gif"  style="cursor:hand;cursor:pointer;" onclick="voteplus('+Arr[2]+',\'\');">'; 
						}
					}
					break;
				case "voteup":
					if(Arr[1] == 1){
						var k = parseInt($("voteupnum").innerHTML);
						$("voteupnum").innerHTML = k+1;
						$("voteupid").hide();
						$("voteupid2").show();
					}
					if(Arr[1] == 2){
						alert("이미 투표했음...");
					}
					if(Arr[1] == 3){
						$("voteupid").hide();
						$("voteupid2").show();
					}
					if(Arr[1] == 4){
						$("voteupid").show();
						$("voteupid2").hide();
					}
					break;
				case "metoMove":
					if(!Arr[1]) return;
					location.href='http://www.kushow.com/view/?idx='+Arr[1];
					break;
				case "checkUcc":
					if(Arr[1] != "ok"){
						$("nourl").show();
						$("nour2").hide();
						$("beforembed").hide();
					}else{
						$("nourl").hide();
						$("nour2").show();
						beforucc2($("ucccode"));
					}
					break;
			}
		}
	});	
}


function imgTurn(num){
	var obj = $("Timg"+num);
	var img = ($("Nimg"+num).style.display == "none")?$("Nimg"+num+"_"):$("Nimg"+num);

	var width = parseInt(img.style.width);
	var width2 = parseInt(obj.style.width);
	obj.time = setTimeout("imgTurn("+num+")", 30);	

	if(obj.temp){
		if(width2-10 < width){
			clearTimeout(obj.time);
			obj.time = null;
			obj.temp = '';
			img.style.width = obj.style.width;
		}else{
			img.style.width = (width+16)+"px";
		}
	}else{
		if(width <= 18){
			obj.temp = 1;
			img = viewImg(num);
		}else{
			img.style.width = (width-16)+"px";
		}
	}
}

function vangImg(num,file,url,tt){

	var obj = $("Nimg"+num);
	var obj_ = $("Nimg"+num+"_");
	var img = new Image();
	img.src = "../drama/timg/"+file;
	if(obj_.style.display == "none"){
		obj_.title = tt;
		Event.observe(obj_.id,'click',function(event){location.href=url;},false);
		obj_.src = img.src;
		obj_.style.width = img.width;
		obj_.www = parseInt(img.width);
	}else{
		obj.title = tt;
		Event.observe(obj.id,'click',function(event){location.href=url;},false);
		obj.src = img.src;		
		obj.style.width = img.width;
		obj.www = parseInt(img.width);
	}
	imgTurn(num);
}

function viewImg(num){
	var obj = $("Nimg"+num);
	var obj_ = $("Nimg"+num+"_");

	if(obj_.style.display == "none"){
		obj_.style.display = "";
		obj.style.display = "none";
		obj_.style.width = obj.style.width

		return obj_;
	}else{
		obj.style.display = "";
		obj_.style.display = "none";
		obj.style.width = obj_.style.width

		return obj;
	}
}

//ajax 통신
function ajaxStart2(args){
	var URL = "../lib/ajaxProcess.php";
	var type = args.type;
	var val = args.val;
	new Ajax.Request(URL,{
		method:'GET',
		asynchronous: true,
		contentType: 'application/x-www-form-urlencoded',
		encoding: 'UTF-8',
		parameters:	{'val':args.val,'type':args.type,'num':args.num},
		onSuccess:	function(xmlHttp, json){

			var sResponseVal = xmlHttp.responseText;
			var json = eval("(" + sResponseVal + ")");	
			var tp = json.REQUEST.REQ_DATA1;

			switch(tp){
				case "toplol":
						
					var last = 0;

					if(!$("Timg1").temp && !$("Timg2").temp && !$("Timg3").temp && !$("Timg4").temp && !$("Timg5").temp){
						$("hidess").value = json.REQUEST2.REQ_DATA1;

						$("toptitle").innerHTML = json.REQUEST.REQ_DATA2;
//						$("Ltitle").innerHTML = json.REQUEST.REQ_DATA3;
//						$("Rtitle").innerHTML = json.REQUEST.REQ_DATA4;

						var num = parseInt(json.RESULT_LIST.length);

						for(i=0;i < num;i++){
							last = i * 200;
							setTimeout("vangImg("+(i+1)+",'"+json.RESULT_LIST[i]["RESULT"]["DATA1"]+"','"+json.RESULT_LIST[i]["RESULT"]["DATA2"]+"','"+json.RESULT_LIST[i]["RESULT"]["DATA3"]+"')", last);
						}

					}

					 



				break;
				case "subcategory":
					var num = parseInt(json.RESULT_LIST.length);
					var html = "";
					var i=0;
					for(i=0;i < num;i++){
						html += '<table width="270px" height="110px" cellspacing="0" cellpadding="0" border="0" style="margin-top:6px;">';
						html += '<tr>';
						html += '	<td width="130px"  align="left">';
						html += '		<A HREF="http://www.kushow.com/main/sub.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'"><img src="'+json.RESULT_LIST[i]["RESULT"]["DATA0"]+'" style="border:3px solid #D2D2D2;"/></A>';
						html += '	</td>';
						html += '	<td width="140px" align="left" valign="top">';
						if(json.RESULT_LIST[i]["RESULT"]["DATA6"] == 1 || json.RESULT_LIST[i]["RESULT"]["DATA6"] == 6){
						html += '		<div style="font-weight:bold;margin-top:6px;"><A HREF="http://www.kushow.com/main/sub.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'">'+json.RESULT_LIST[i]["RESULT"]["DATA2"]+'</a></div>';
						}else{
						html += '		<div style="font-weight:bold;margin-top:6px;"><A HREF="http://www.kushow.com/view/?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'">'+json.RESULT_LIST[i]["RESULT"]["DATA2"]+'</a></div>';
						}
						html += '		<div>'+json.RESULT_LIST[i]["RESULT"]["DATA3"]+'</div>';
						html += '		<div>by <A HREF="http://www.kushow.com/main/profile.php?uid='+json.RESULT_LIST[i]["RESULT"]["DATA5"]+'">'+json.RESULT_LIST[i]["RESULT"]["DATA4"]+'</A></div>';
						html += '		<div style="margin-top:5px;"><A HREF="http://www.kushow.com/main/sub.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'"><img src="../image/button_more.gif" style="cursor:hand;"/></A></div>';
						html += '	</td>';
						html += '</tr>';
						html += '</table>';
					}
					$("data114").innerHTML = html;
					$("page115").innerHTML = json.REQUEST2.REQ_DATA1;
				break;
				case "topajax":
					var num = parseInt(json.RESULT_LIST.length);
					var html = "";
					var i=0;

					for(i=0;i < num;i++){
						html += '<div style=" background-image:url(http://www.kushow.com/image/bg_bestbox.gif);width:287px;height:43px;margin-top:5px;">';
						html += '	<table height="30px" cellspacing="0" cellpadding="0" border="0" style="margin-top:6px;margin-left:5px;" align="left">';
						html += '		<tr>';
						if(json.REQUEST.REQ_DATA3){
						//드라마
							html += '			<td width="35px;"><img src="http://www.kushow.com/image/bestnum'+json.RESULT_LIST[i]["RESULT"]["DATA3"]+'.gif" /></td>';
							html += '			<td width="60px;" align="center"><A HREF="/drama/dramaDetail.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'"><img src="'+json.RESULT_LIST[i]["RESULT"]["DATA0"]+'" style="border:3px solid #6F6F6F;width:35px;height:25px;"/></a></td>';
							html += '			<td align="left">';
							html += '				<div style="font-weight:bold;"><A HREF="/drama/dramaDetail.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'">'+json.RESULT_LIST[i]["RESULT"]["DATA2"]+'</A></div>';
							html += '				<div>by '+json.RESULT_LIST[i]["RESULT"]["DATA4"]+'</div>';
						}else{
						//UCC
							html += '			<td width="35px;"><img  onerror="errorimg(this,'+json.RESULT_LIST[i]["RESULT"]["DATA7"]+','+json.RESULT_LIST[i]["RESULT"]["DATA1"]+');" src="http://www.kushow.com/image/bestnum'+json.RESULT_LIST[i]["RESULT"]["DATA3"]+'.gif" /></td>';
							html += '			<td width="60px;" align="center"><A HREF="http://www.kushow.com/main/sub.php?idx='+json.RESULT_LIST[i]["RESULT"]["DATA1"]+'"><img src="'+json.RESULT_LIST[i]["RESULT"]["DATA0"]+'" style="border:3px solid #6F6F6F;width:35px;height:25px;"/></a></td>';
							html += '			<td align="left">';
							html += '				<div style="font-weight:bold;">'+json.RESULT_LIST[i]["RESULT"]["DATA6"]+json.RESULT_LIST[i]["RESULT"]["DATA2"]+'</A></div>';
							html += '				<div>by <A HREF="http://www.kushow.com/main/profile.php?uid='+json.RESULT_LIST[i]["RESULT"]["DATA5"]+'">'+json.RESULT_LIST[i]["RESULT"]["DATA4"]+'</A></div>';
						}
						html += '			</td>';
						html += '		</tr>';
						html += '	</table>';
						html += '</div>';
					}
					$("bestten").innerHTML = html;
				break;
			}

		}
	});	
}

function reportOpen(rId){
	if($("report0129").style.display == ""){
		$("report0129").style.display = "none";
	}else{
		$("sa1").style.display = "";
		$("sa2").style.display = "none";
		$("sa3").style.display = "";
		document.newReport.reset();
		document.newReport.uIdx.value = rId;
		$("report0129").style.display = "";
	}

}

function reportEnd(){
	$("sa1").style.display = "none";
	$("sa2").style.display = "";
	$("sa3").style.display = "none";
	if($("savereport") == null){
		$("savereport2").innerHTML = "<div style='color:#999999'>举报</div>";
	}else{
		$("savereport").innerHTML = "<img src='../image/button_report2.gif' style='cursor:hand;'>";
	}
}

function checksavereport(val){
	lib_process("checksavereport&idx="+val);
}

function changeImge(){
	if($("savereport") == null){
		$("savereport2").innerHTML = "<div style='color:#999999'>举报</div>";
	}else{
		$("savereport").innerHTML = "<img src='../image/button_report2.gif' style='cursor:hand;'>";
	}
}

function windowsize(){
	var size = new Array();
	if (self.innerHeight) { // IE 외 모든 브라우저
		size[0] = self.innerWidth;
		size[1] = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict 모드
		size[0] = document.documentElement.clientWidth;
		size[1] = document.documentElement.clientHeight;
	}else if (document.body) { // 다른 IE 브라우저
		size[0] = document.body.clientWidth;
		size[1] = document.body.clientHeight;
	}	
	return size;
}

//빽 알파....
function alphadivFun(opacity){
	var obj = $("DivShim");
	var size = windowsize();

	obj.style.display = "";
	obj.style.width = size[0]+"px";
	obj.style.height =  size[1]+"px";

	var imsis = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
	var imsi = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	obj.style.top = imsi+"px";
	obj.style.left = imsis+"px";

	if(!(window.attachEvent && !window.opera)){
		obj.style.opacity = (opacity / 100);			
	}else{
		obj.style.filter = 'alpha(opacity=' + opacity + ')';
	}
	
}

function favorite032(f){
	$("favorite"+f).hide();
	$("favorite"+f+"_").show();
}

function favorite033(f){
	$("favorite"+f).show();
	$("favorite"+f+"_").hide();
}

function errorimg(obj,img,num){
	obj.src = "../image/img_category0"+img+".gif";
	if(!num) return;
	lib_process("hideucc&idx="+num);	
}