/********************************************************************************************************
*
*    REVIEW
*
********************************************************************************************************/
//TAB
var val = location.href.split("/");
var fn = val[val.length-1].replace(".asp","");
var fn2 = fn.split("_")[0];

function initTab() {
	
	var tab = document.getElementById("reviewTab");
	if (!tab)
		return;

	var a = tab.getElementsByTagName("A")

	initTab.onTab = tab.getElementsByTagName("li")[0];

	for (var i = 0; i < a.length; i++) {	
		if (a[i].parentNode.name == fn2){
			a[i].parentNode.className = "on";
		}
		a[i].onclick = function () {

			if (this.parentNode.className != "on" || this.parentNode.name != fn)
			{
				location.href="/review/"+this.parentNode.name +".asp";
			}
			return false;
		};
	}
};
initTab();

//REVIWE
function initReview () {

	if(document.getElementById("review_paging")){

		a = document.getElementById("review_paging").getElementsByTagName("A");

		for (i = 0; i < a.length; i++) {
			a[i].onclick = function () {
				var href = this.href,
					id = "review_list";			

				var val = href.split("/");
				var fn = val[val.length-1].replace(".asp","");		
				fn = fn.split("?");
				var fn2 = fn[0].split("_")[0];

				loading(id);
				Async.send("/common/async/inc_"+ fn2 +".asp", function ( send_ ) {
					setTimeout( function () {
						insertNodes(id, send_.responseText, initReview);
					}, random(400, 600));
				}, getQueryString(href));
				return false;
			};
		};
	}

	var table = document.getElementById("reviewClick");

	if (table){
		var a = table.getElementsByTagName("A");

		for (var i = 0; i < a.length; i++) {
			a[i].idx = i/3;
			a[i].onclick = function () {
				if (location.href+"#" == this.href){
					var tr = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
					while ((tr = tr.nextSibling.nextSibling) && tr.nodeType != 1) {}
					if (initReview.onTr && initReview.onTr != tr) {
						addClass(initReview.onTr, "dsp_none");
						initReview.onImg.src = "/images/etc/img_plus.jpg";
					}
					initReview.onImg = document.getElementsByName("plusMinus")[this.idx];
					if (toggleClass(tr, "dsp_none").indexOf("dsp_none") > -1)
						initReview.onImg.src = "/images/etc/img_plus.jpg";
					else
						initReview.onImg.src = "/images/etc/img_minus.jpg";
					initReview.onTr = tr;
				}
				else{
					location.href = this.href;
				}
				return false;
			};
		};
	};
	
	var textSearchForm = document.forms["textSearchForm"];

	if(!textSearchForm)
		return;

	var id = "review_list",
		locationName = fn2.split("review")[1].split("?")[0];

	textSearchForm.onsubmit = function () {
		
		if (textSearchForm.isSubmit)
			return false;
		if (this.searchString.value.length < 2) {
			alert("°Ë»ö¾î¸¦ 2ÀÚÀÌ»ó ÀÔ·Â ÇØÁÖ¼¼¿ä!     ");
			this.searchString.focus();
			return false;
		}

		loading(id);
			Async.send("/common/async/inc_review"+ locationName +".asp", function ( send_ ) {
				setTimeout( function () {
					insertNodes(id, send_.responseText, initReview);
				}, random(300, 500));
			}, formQueryString(this));
		return false;
	};
	
	if (textSearchForm.prdSelect){
		textSearchForm.prdSelect.onchange = function (){
			loading(id);
				Async.send("/common/async/inc_review"+ locationName +".asp", function ( send_ ) {
					setTimeout( function () {
						insertNodes(id, send_.responseText, initReview);
					}, random(300, 500));
				}, formQueryString(this.form));
			return false;
		};
	};
	
	if (textSearchForm.photoChoice){

		textSearchForm.photoChoice.onchange = function (){
			loading(id);
				Async.send("/common/async/inc_reviewPhoto.asp", function ( send_ ) {
					setTimeout( function () {
						insertNodes(id, send_.responseText, initReview);
					}, random(300, 500));
				}, formQueryString(this.form));
			return false;
		};
	};
	
};
initReview();

	if (document.reviewWriteForm){

		var theForm = document.reviewWriteForm;
	
		function openReviewWrite() {
			if (theForm.VC_id.value == "")	{
				my_ret = confirm("·Î±×ÀÎÀÌ ÇÊ¿äÇÕ´Ï´Ù. ·Î±×ÀÎÇÏ½Ã°Ú½À´Ï±î?");
				if (my_ret == true){
					addClass(document.getElementById("fixedBox"), "open");
				}
				else{
					return;
				}
			}
			else {
				if (document.getElementById("beautyChk")){
					if (document.getElementById("beautyChk").className == "0"){
						alert("ºäÆ¼Å×½ºÅÍ ´çÃ·³»¿ªÀÌ ¾ø½À´Ï´Ù.       ");
						return;
					}
					else{
						removeClass(document.getElementById("reviewWriteBox"), "dsp_none");
						theForm.list01.focus();

						if (document.reviewWriteForm.showEditer.value != 1)
						{
							nhn.husky.EZCreator.createInIFrame({
								oAppRef: oEditors,
								elPlaceHolder: "ir1",
								sSkinURI: "/smarteditor/SEditorSkin.html",
								fCreator: "createSEditorInIFrame"
							});
						}
					}

						
				}
				else{
					removeClass(document.getElementById("reviewWriteBox"), "dsp_none");
					theForm.list01.focus();

					if (document.reviewWriteForm.showEditer.value != 1)
					{
						nhn.husky.EZCreator.createInIFrame({
							oAppRef: oEditors,
							elPlaceHolder: "ir1",
							sSkinURI: "/smarteditor/SEditorSkin.html",
							fCreator: "createSEditorInIFrame"
						});
					}
				}
				document.reviewWriteForm.showEditer.value = 1;
			}
			
			return false;
		};

		function closeReviewWrite() {
			//document.getElementById('reviewWriteBox').style.display = 'none';
			addClass(document.getElementById("reviewWriteBox"), "dsp_none");
			return false;
		};

		function imgOpen(Num){
			window.open("/common/uploadImg.asp", "uploadfile", "scrollbars=no,resizable=no,width=420, height=247");
		};


		function insertImg(ImgObj){

			var objChk
			//ImgObj = ImgObj.substr(1);
			//objChk = ImgObj.split("|");
			
			//for ( i=0; i < objChk.length; i++)
			//{
				//var frameInsert = document.getElementById('ir1');
				//var frameInsertImg = frameInsert.createElement("IMG");
				//frameInsertImg.src = ImgObj;
				
				var sHTML = "<img src='" + ImgObj + "' border='0'>"; 
				oEditors.getById["ir1"].exec("PASTE_HTML", [sHTML]);
				//frameInsert.body.appendChild(frameInsertImg);
				
				theForm.VC_imgPath.value = ImgObj;

				
				//document.getElementById("imgPriview").innerHTML = "<img src='"+ objChk[i] +"' width='50' height='50'>";
			//}		
			
			//setTimeout("hidden_content('content_layer')", 300); 
		}		

		function averageStar(){
			var starAverage = (theForm.list01.value * 1) + (theForm.list02.value * 1) + (theForm.list03.value * 1)+ (theForm.list04.value * 1);
			starAverage = starAverage / 4;
			starAverage = parseInt((starAverage+0.05)*10)/10;
			starAverage += "";

			if (starAverage.length == 1){
				document.getElementById("imgStar").innerHTML = "<img src=/images/etc/img_star"+ starAverage +"_l.jpg>";
			}
			else{
				document.getElementById("imgStar").innerHTML = "<img src=/images/etc/img_star"+ parseInt(starAverage) +"5_l.jpg>";
			}
		}

		addEvent(theForm.VC_title, "focus", function (e_) {
			var event = e_ || window.event;
				event = event.target || event.srcElement;
			if (event && event.value == event.defaultValue)
				event.value = "";

		});

		addEvent(theForm.VC_title, "blur", function (e_) {
			var event = e_ || window.event;
				event = event.target || event.srcElement;
			if (event && !event.value)
				event.value = event.defaultValue;
		});
		
		document.reviewWriteForm.onsubmit = function () {
			
			if (theForm.C_type.value == "beautyTesterReview")
			{
				if(theForm.C_prdNo.value == ""){
					alert('Å×½ºÅÍ Á¾·ù¸¦ ¼±ÅÃÇÏ¿© ÁÖ¼¼¿ä.');
					theForm.testerCate.focus();
					return false;
				}
			}
			else{
				if(theForm.C_prdNo.value == ""){
					alert('¸®ºä »óÇ°À» ¼±ÅÃÇÏ¿© ÁÖ¼¼¿ä.');
					theForm.cate01.focus();
					return false;
				}
			}

			if (theForm.VC_imgPath.value != ""){
					if(theForm.VC_title.value == "" || theForm.VC_title.value == " Á¦¸ñÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä."){
					alert('Á¦¸ñÀ» ÀÔ·ÂÇÏ¿© ÁÖ¼¼¿ä.');
					theForm.VC_title.focus();
					return false;
				}
			};			

			//theForm.fContents.value = document.getElementById('ContentsFrame').contentWindow.document.body.innerHTML;

			var href = location.href;
			var val = href.split("/");
			var fn = val[val.length-1].replace(".asp","");		
			fn = fn.split("?");
			var fn2 = fn[0].split("_")[0];			

			if (fn2 == "reviewView"){
				var id = "reviewViewLoading";
				if (theForm.C_type.value == "review"){
					theForm.resultHref.value = "/common/async/inc_reviewPhoto.asp?reviewType=photoReview";
				}
				else{
					theForm.resultHref.value = "/common/async/inc_reviewCommunity.asp?reviewType=communityReview";
				}
			}
			else{
				var id = "review_list";
				theForm.resultHref.value = "/common/async/inc_"+ fn2 +".asp";
			}

			oEditors.getById["ir1"].exec("UPDATE_IR_FIELD", []);
			theForm.fContents.value = document.getElementById("ir1").value;

			if(theForm.fContents.value == ""){
				alert("\'³»¿ë\'À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä");
				return false;
			}
			
			Async.send("./review_write_reg.asp", function (send_) {
				setTimeout( function () {
					closeReviewWrite();
					theForm.reset();
					//document.getElementById('ContentsFrame').contentWindow.document.body.innerHTML = ""
				
					loading(id);
					insertNodes(id, send_.responseText, initReview);
					if (theForm.C_type.value == "review"){
						alert('        Á¤»óÀûÀ¸·Î µî·ÏµÇ¾ú½À´Ï´Ù.      \n°í°´´ÔÀÇ ¼ÒÁßÇÑ ¸®ºä´Â È®ÀÎ ÈÄ »çÀÌÆ®¿¡ ¹Ý¿µµË´Ï´Ù.');
					}
					else{
						alert('Á¤»óÀûÀ¸·Î µî·ÏµÇ¾ú½À´Ï´Ù.');
					}
					
					return false;
				}, random(100, 400));
			}, formQueryString(this));

			return false;
		};

	}

