/* gnb */
function gnbOn(value) {
	document.getElementById("category"+value).style.display="";
}
function gnbOut(value) {
	document.getElementById("category"+value).style.display="none";
}

function bgOn(This) {
	This.className="on";
}
function bgOut(This, last) {
	if (last=="last") {
		This.className="last";
	}
	else {
		This.className="";
	}
}

/* right tab */
function righttab(value) {
	for (var i=1; i<=3; i++) {
		if (i==value) {
			document.getElementById("rttab"+i).className="on";
			document.getElementById("tab"+i).style.display="";
		}
		else {
			document.getElementById("rttab"+i).className="";
			document.getElementById("tab"+i).style.display="none";
		}
	}
	var heightleft=document.getElementById("wrapleft").scrollHeight;
	var heightright=document.getElementById("wrapright").scrollHeight;
	if (heightleft>heightright) {
		document.getElementById("wrapright").style.height=heightleft-70+"px";
	}
	else {
		document.getElementById("wrapleft").style.height=heightright-95+"px";
	}
}

/* 높이값 설정 */
function heights() {
	var heightleft=document.getElementById("wrapleft").scrollHeight;
	var heightright=document.getElementById("wrapright").scrollHeight;
	if (heightleft>heightright) {
		document.getElementById("wrapright").style.height=heightleft-70+"px";
	}
	else {
		document.getElementById("wrapleft").style.height=heightright-90+"px";
	}
}

/* png */
function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+obj.src+"',sizeMethod='image');"
	objsrc='';
	return '';
}

//comment
function commentOn (value, This) {
	if (value=="1") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm01_on.gif') no-repeat 11px 6px";
		This.style.backgroundColor="#fdfdf2";
	}
	else if (value=="2") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm02_on.gif') no-repeat 11px 7px";
		This.style.backgroundColor="#fdfdf2";
	}
	else if (value=="3") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm03_on.gif') no-repeat 11px 7px";
		This.style.backgroundColor="#fdfdf2";
	}
	else if (value=="4") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm04_on.gif') no-repeat 10px 11px";
		This.style.backgroundColor="#fdfdf2";
		This.style.width="94%";
	}
}

function commentOut (value, This) {
	if (value=="1") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm01.gif') no-repeat 11px 6px";
		This.style.backgroundColor="#ffffff";
	}
	else if (value=="2") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm02.gif') no-repeat 11px 7px";
		This.style.backgroundColor="#ffffff";
	}
	else if (value=="3") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm03.gif') no-repeat 11px 7px";
		This.style.backgroundColor="#ffffff";
	}
	else if (value=="4") {
		This.style.background="url('/wp-content/themes/workshop/images/img_cm04.gif') no-repeat 10px 11px";
		This.style.backgroundColor="#ffffff";
	}
}

function chk_contact(theForm) {
	var reason = "";
  reason += validatePhone(theForm.contact4);
  reason += validateEmail(theForm.contact3);
  reason += validateCname(theForm.contact2);
  reason += validateName(theForm.contact1);
  
        
if (reason != "") {
	alert("아래의 필수 입력 항목을 확인해주세요.\n-----------------------------------\n" + reason);
	return false;
  }
  return true;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateName(fld) {
    var error = "";
	var illegalChars = /[\W_]/;

   if (fld.value == "") {
		fld.focus();
		error = "이름\n";
    } else if (fld.value.length < 2) {
		fld.focus();
       error = "이름\n";
    } else if (illegalChars.test(fld.value)) {
		fld.focus(); 
        error = "이름\n";
    } else {
    }
   return error;
}

function validateCname(fld) {
    var error = "";
	var illegalChars = /[\W_]/;

   if (fld.value == "") {
		fld.focus();
        error = "회사이름\n";
    } else if (fld.value.length < 2) {
		fld.focus();
       error = "회사이름\n";
    } else if (illegalChars.test(fld.value)) {
		fld.focus(); 
        error = "회사이름\n";
    } else {
    }
   return error;
}

function validatePhone(fld) {
    var error = "";
	var illegalChars = /[\W_]/;

   if (fld.value == "") {
		fld.focus();
        error = "전화번호\n";
    } else if (fld.value.length < 2) {
		fld.focus();
       error = "전화번호\n";
    } else if (illegalChars.test(fld.value)) {
		fld.focus(); 
        error = "전화번호\n";
    } else {
    }
   return error;
}

function validateEmail(fld) {
	var error="";
	var tfld = trim(fld.value);
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
 
	if (fld.value == "") {
		fld.focus();
		error = "이메일\n";
	} else if (!emailFilter.test(tfld)) {
		fld.focus();
		error = "이메일\n";
	} else if (fld.value.match(illegalChars)) {
		fld.focus();
		error = "이메일\n";
	} else {
	}
	return error;
}