/********************************
 * project common script
 ********************************/
 
/* ?????? ????
 * pupup window open
 */ 
function popUp(URL, width, height, resize, scroll)
{
    var path = URL;
    var popup = null;
    var w = width;
    var h = height;
    var s = scroll;
    if(scroll == null)
        s = 'yes';
    var _top = (screen.availHeight-h)/2;
    var _left = (screen.availWidth-w)/2;
    popup = window.open( path , w + h , 'width=' + w + ',height=' + h +',scrollbars=' + s + ',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable='+resize+', top='+_top+', left='+_left );
    popup.focus();
}

function popUp(URL, width, height, resize, scroll, status)
{
    var path = URL;
    var popup = null;
    var w = width;
    var h = height;
    var s = scroll;
    var st = status;
    if(scroll == null)
        s = 'yes';
    if(status = null)
    	st = 'no'
    	
    var _top = (screen.availHeight-h)/2;
    var _left = (screen.availWidth-w)/2;
    popup = window.open( path , w + h , 'width=' + w + ',height=' + h +',scrollbars=' + s + ',toolbar=no,location=no,directories=no,status='+st+',menubar=no,resizable='+resize+', top='+_top+', left='+_left );
    popup.focus();
}

/*	???? ???? or ???? ????????
 *	toggle checkbox( all or 0)
 */
var toggleStat = 0;
function allCheck(checkBoxName) {
	var checkObj = document.getElementsByName(checkBoxName);
	try{
		if(typeof(checkObj) == "undefined"){
		}else if(typeof(checkObj.length) == "undefined"){
			alert(checkObj.checked);
			if(checkObj.checked)  checkObj.checked = false;
			else checkObj.checked = true;
		}else{
			for(i = 0; i < checkObj.length; i++){
				if(toggleStat == 0) checkObj[i].checked = true;
				else checkObj[i].checked = false;
			}
			toggleStat = (toggleStat == 0)?1:0;
		}
	}catch(e){}
}

/*	???? ???? or ???? ????????
 *	toggle checkbox by object parameter
 */

function allCheckByObj(checkObj) {
	try{
		if(typeof(checkObj) == "undefined"){
		}else if(typeof(checkObj.length) == "undefined"){
			if(checkObj.checked)  checkObj.checked = false;
			else checkObj.checked = true;
		}else{
			for(i = 0; i < checkObj.length; i++){
				if(toggleStat == 0) checkObj[i].checked = true;
				else checkObj[i].checked = false;
			}
			toggleStat = (toggleStat == 0)?1:0;
		}
	}catch(e){}
}

/**
 * ?????????????? ???? (by puheol)
 * mode = null or ????????(: popCateTree(contextName)): ????????(?????? ?????????? ????????)
 * 1: ????????
 * ???????? cateSeq, cateName, fullName, cateDepth ?? ???????? ???? ????
 * opener ????  function setCategory(cateList) ?????? ??????????
 * preCateSeq.value = cateList[0].cateSeq;
 * preCateName.value = cateList[0].cateName; ???? ???? ???? ??.
 */
function popCateTree(contextName, mode) {
	if(mode == 'undefined' || mode==null)
		mode = '';
	var url = contextName + "/bo/category/treeCate.do?cmd=popCategoryTree&mode=" + mode;
	
	open(url, "cate_tree", "width=400 height=600 scrollbars=yes resizable=yes");
}
/*
 * ???????? ??????
 * mode = null ?????? ?????? ????, package ?????? ?????? ???????? ????(?????? ?????? ???????? ????)
 * opener ???? function returnOption(optionList) ?????? ??????????
 * optionList ?? ?????????? ????
 * option ?????? ????
function option(prodId, prodName, optSeq, optName, saleCost, saleVat, taxGb, dispGb, buyCost, buyVat, stockCnt, dispOrd, dispName,prodName){
	this.prodId = prodId;
	this.prodName = prodName;
	this.optSeq = optSeq;
	this.optName = optName;
	this.saleCost = saleCost;
	this.saleVat = saleVat;
	this.taxGb = taxGb;
	this.dispGb = dispGb;
	this.buyCost = buyCost;
	this.buyVat = buyVat;
	this.stockCnt = stockCnt;
	this.dispOrd = dispOrd;
	this.dispName = dispName;
	this.prodName = prodName;
}
 */
function popProdSearch(contextName, mode) {
	if(mode == "undefined" || mode==null)
		mode = "";
	popUp(contextName+"/bo/product/popupList.do?cmd=listProdPopup&mode="+mode, 700, 600, "yes", "yes");
}

function popGiftSearch(contextName) {
	popUp(contextName+"/bo/gift/list.do?cmd=listGift&mode=popup", 700, 600, "no", "no");
}

// ?????  ??? ?? ????. 
function getCookie(name) {
	var Found = false 
	var start, end 
	var i = 0 
	
	while(i <= document.cookie.length) { 
		start = i 
		end = start + name.length 
		
		if(document.cookie.substring(start, end) == name) { 
			Found = true 
			break 
		} 
		i++ 
	} 
	
	if(Found == true) { 
		start = end + 1 
		end = document.cookie.indexOf(";", start) 
		if(end < start) 
		end = document.cookie.length 
		return document.cookie.substring(start, end) 
	} 
	return "" 
} 
// ??? ??? ??? ?? ????. 

