function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}
function Win_open(URL,Width,Height){
	var status="width="+Width+",height="+Height+"toolbar=0,resizable=1,scrollbars=no";
	window.open(URL,"NewPopUp1",status);
}
function Win_Sopen(URL,Width,Height){
	var status="width="+Width+",height="+Height+"toolbar=0,resizable=1,scrollbars=no";
	window.open(URL,"NewPopUp2",status);
}
function Win_Copen(URL,Width,Height){
	var status="width="+Width+",height="+Height+"toolbar=0,resizable=1,scrollbars=yes";
	window.open(URL,"NewPopUp3",status);
}
function Win_Dopen(URL,Width,Height)
{
	var status="width="+Width+",height="+Height+"toolbar=0,resizable=1,scrollbars=yes";
	window.open(URL,"NewPopUp4",status);
}


//주문취소,반품,교환
function Win_Ropen(form, checkBoxName, URL, Width, Height, objState, mode){ 

	var objChBox = form[checkBoxName];
	var objExcept = form["except_order[]"];
	var tmp = "";
	var canDo = true;
	var isAllCancel = "true";
	var modeTxt = "";


	if(mode=="cancel"){
		modeTxt = "취소";
	} else if(mode=="return"){
		modeTxt = "반품";
	} else if(mode=="exchange") {
		modeTxt = "교환";
	} else {
		modeTxt = "[오류발생]";
	}
	

	if(objChBox != undefined){
		
		if(objChBox.length == undefined) { //상품이 하나일 경우
			if(objChBox.checked){ //선택된 상품일 경우
				
				canDo = checkCanDo(mode, objState.value); //진행상태를 체크해서 실행하려는 기능이 적절한지 판단(true/false)
				tmp = objChBox.value;
			}
		} else { //상품이 하나 이상일 경우
			for(i=0 ; i < objChBox.length ; i++){

				

				if(objChBox[i].checked){
					if(tmp!="") tmp += ",";
					canDo = checkCanDo(mode, objState[i].value); //진행상태를 체크해서 실행하려는 기능이 적절한지 판단(true/false)
					if(!canDo){ //실행하려는 기능(버튼)이 적절하지 않으면 break 종료
						tmp = "none";
						break;
					}

					tmp += objChBox[i].value;
				} else {
					//order_spec의 진행상태가 비어 있는 것만(비어있는 것은 주문(order_product)을 따르므로
					if(objExcept[i].value==""){
						isAllCancel = "false"; //남은 수량이 0이 아닌 하나라도 선택이 안된 상품이 있다면 주문취소가 아니라 개별 취소루틴을 탄다.(내부에서 또 분기한다,수량으로)
					}
					//if(checkCanDo(mode, objState[i].value)) //진행상태가 달라서 기능에 해당하지 않는 것들은 무시한다.
				}
			} 
		}


		if(tmp != ""){
			if(canDo){
				Width = parseInt(Width) + 17;
				Win_Copen(URL + '&pOrderSpecNo=' + tmp + '&mode=' + mode + '&isAll=' + isAllCancel,Width,Height );
			} else {
				window.alert("선택하신 상품 중에 "+ modeTxt + "신청할 수 없는 상품이 선택되었습니다.");
			}
			
			//window.alert(tmp);
		} else {
			window.alert( modeTxt + "신청할 주문(상품)을 선택하세요");
		}

	} else {
		window.alert(modeTxt + "신청할 주문(상품)이 없습니다");
	}
} 

function checkCanDo(modeVal,stateVal){
	
	//취소는 입금확인중이나 배송준비중일 경우
	//교환 반품은 배송중이나 배송완료, 재배송중이나, 재배송완료의 경우만 가능
	if((modeVal=="cancel" && (stateVal=="aw_income" || stateVal=="bw_delivery")) 
	|| ((modeVal=="return" || modeVal=="exchange") && (stateVal=="cn_delivery" || stateVal=="cc_delivery" || stateVal=="cn_redelivery"|| stateVal=="cc_redelivery")) ){ 
		return true;
	} else {
		return false;
	}
}

//opener
function setCookie( name, value, expiredays, domain )
{
	var expires = "";

	if (expiredays) {
		var date = new Date();
		date.setTime(date.getTime() + (expiredays * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	}

    document.cookie = name + "=" + escape( value ) + "; path=/" + expires + "; domain=" + domain + ";";
}
            
function closewin(cookieName,domain,expire)
{
    if ( $('popupClose').checked ) {
		setCookie( cookieName, "checked" ,expire ,domain);
    }

	if(typeof(window.opener) == "undefined")	//layer일때
	{
		var iframeName = cookieName;
		iframeName = iframeName.split("_");

		var divId = "popupDiv_"+ iframeName[1];
		parent.document.body.removeChild(parent.$(divId));
	}
	else										//팝업일때
	{
		self.close();
	}
}

function closeredirect(url)
{
    opener.top.location=url;
    self.close();
}

function maskScreen(mDiv) 
{
	try
	{
		with(document.getElementById(mDiv).style)
		{
			if(width == 0 || height == 0)
			{
				height = document.body.scrollHeight;
				width = document.body.scrollWidth;		
			}

		}
			
		document.body.firstChild.style.backgroundColor = "white";
		document.body.firstChild.zIndex =1;


	}
	catch(ee)
	{
		return false;
	}
}

//윈도우창의 크기를 조정한다.
function resizeWindow(width,height)
{
	if(width == -1 ) var rWidth = document.body.scrollWidth + 10;
	else			 var rWidth = width; 

	window.resizeTo(document.body.clientWidth - 50,document.body.clientHeight - 50);
	var wid = rWidth;
	var hei = document.body.scrollHeight + 80;
	window.resizeTo(wid,hei);
	
}
