


//document.onload = prepareReadUserInformation() ;

//function prepareReadUserInformation() {

   // setTimeout('readUserInformation()',2000);

//}
function readUserInformation() {
    
    if (document.getElementById('loginDiv') == null) return;
    if (document.getElementById('showLoginInfoDiv') == null) return;
    if (document.getElementById('loginUserName') == null) return;

    var userNo = getCookieValue("userNo");


    if (userNo != '') {
        document.getElementById('loginDiv').style.display="none";
        document.getElementById('showLoginInfoDiv').style.display="block";
        document.getElementById('loginUserName').innerHTML=userNo;
    } else {
        document.getElementById('loginDiv').style.display="block";
        document.getElementById('showLoginInfoDiv').style.display="none";
        document.getElementById('loginUserName').innerHTML="";
    }

}


function getCookieValue(cookieName) {
    var strCookie=document.cookie;


    var arrCookie=strCookie.split(";");
    for(var i=0;i<arrCookie.length;i++){
        var cookieArray = arrCookie[i];

        var arr=cookieArray.split("=");

        if(arr[0]==cookieName || arr[0]==" " + cookieName) {

            return arr[1];
        }
    }
    return "";
}

function changeImage(imageTag, imageURL) {
    if (imageURL == '') return;
    var productImageObj = document.getElementById(imageTag);

    if (productImageObj != null) {
          if (productImageObj.src!=imageURL) {
            productImageObj.src=imageURL;
          }
    }
}
function changeLargeImageSize(imageTag, imageURL) {
    resizeProductImage(imageTag,800,800);
}
function changeSmallImageSize(imageTag, imageURL) {
    resizeProductImage(imageTag,150,150);
}
function changeSmallProductIconImageSize(imageTag, imageURL) {
    resizeProductImage(imageTag,220,220);
}
function changeAdImageSize(imageTag, imageURL) {
    resizeProductImage(imageTag,1000,1000);
}
function resizeProductImage(imageTag,maxWidth,maxHeight) {
    var productImageObj = document.getElementById(imageTag);

    if (productImageObj != null) {
        var sourceWidth = productImageObj.width;
        var sourceHeight = productImageObj.height;


        if ((sourceWidth > maxWidth) && (sourceHeight > maxHeight)) {

            var scale =  maxWidth /  sourceWidth >=  maxHeight / sourceHeight ? maxHeight / sourceHeight :  maxWidth /  sourceWidth;

            var targetWidth = sourceWidth * scale;
            var targetHeight = sourceHeight * scale;



            productImageObj.width = targetWidth;
            productImageObj.height = targetHeight;

        }
    }
}


    function resizeValueInput(objId) {
        var contentObj = document.getElementById(objId);
        contentObj.style.posHeight=contentObj.scrollHeight;
        contentObj.style.height=contentObj.scrollHeight;
    }



//------------------------------- function.js -------------------------------


function initAllBizTypeCatalogs() {

    if (catalogs.length == 0) return;

    var catalogIdListObj = document.getElementById('catalogIdList');

    var bizTypeCatalogId1Value = document.getElementsByName('userSO.bizTypeCatalogId1')[0].value;
    var bizTypeCatalogId2Value = document.getElementsByName('userSO.bizTypeCatalogId2')[0].value;
    var bizTypeCatalogId3Value = document.getElementsByName('userSO.bizTypeCatalogId3')[0].value;
    var bizTypeCatalogId4Value = document.getElementsByName('userSO.bizTypeCatalogId4')[0].value;


    for (var i = 0; i < catalogs.length; i++) {
        var boards = catalogs[i][2];

        for (var j = 0; j < boards.length; j++) {
            if (   (boards[j][0] == bizTypeCatalogId1Value)
                || (boards[j][0] == bizTypeCatalogId2Value)
                || (boards[j][0] == bizTypeCatalogId3Value)
                || (boards[j][0] == bizTypeCatalogId4Value)) {

                catalogIdListObj.options[catalogIdListObj.options.length] =
                    new Option(boards[j][1],boards[j][0], false, false);


            }
        }

    }
}

function buildCatalogBoardMap(withEmptyOption, cleanCatalogData) {

    if (catalogs.length == 0) return;

    var parentCatalogObj = document.getElementById('parentCatalogId');
    var boardObj = document.getElementById('catalogId');

    var subCategoryValue = -1;
    var subCategoryOBJ = document.getElementById('subCategoryId');
    if (subCategoryOBJ != null) {
        subCategoryValue = subCategoryOBJ.value;
    }
    //var subCategoryValue = document.getElementById('catalogId').value;

    //if (parentCatalogObj.options.length == 0) {



    if (cleanCatalogData) {
        parentCatalogObj.options.length = 0;
        if (withEmptyOption == 'yes') {
            parentCatalogObj.options[parentCatalogObj.options.length] = new Option("","", false, false);
        }
        for (var i = 0; i < catalogs.length; i++) {
            if (i == 0 && withEmptyOption != 'yes') {
                parentCatalogObj.options[parentCatalogObj.options.length] = new Option(catalogs[i][1],catalogs[i][0], true, true);
            } else {
                parentCatalogObj.options[parentCatalogObj.options.length] = new Option(catalogs[i][1],catalogs[i][0], false, false);
            }
        }
        var found = false;
        for (var i = 0; i < catalogs.length; i++) {
            var boards = catalogs[i][2];
            boardObj.options.length = 0;
            for (var j = 0; j < boards.length; j++) {
                if (boards[j][0] == subCategoryValue) {
                    parentCatalogObj.options[i].selected=true;

                    found = true;
                    break;
                }
            }
            if (found) break;
        }

    }
    boardObj.options.length = 0;

    if (parentCatalogObj.selectedIndex > -1 ) {

        var boards = catalogs[parentCatalogObj.selectedIndex][2];
        boardObj.options.length = 0;
        if (withEmptyOption == 'yes') {
            boardObj.options[boardObj.options.length] = new Option("","", false, false);
        }
        for (var i = 0; i < boards.length; i++) {
            if (i == 0 && withEmptyOption != 'yes') {
                boardObj.options[boardObj.options.length] = new Option(boards[i][1],boards[i][0], true, true);
            } else {
                boardObj.options[boardObj.options.length] = new Option(boards[i][1],boards[i][0], false, false);
            }
            if (boards[i][0] == subCategoryValue) {
                boardObj.options[boardObj.options.length-1].selected=true;

            }
        }
    }

}

function chooseCatalogsInOpenWindow(catalogInputIdArray, xPosition, yPosition) {

    var chooseAmount = catalogInputIdArray.length;
    var index = 0;
    var catalogId1 = document.getElementById(catalogInputIdArray[index++]).value;
    var catalogId2 = 0;
    var catalogId3 = 0;
    var catalogId4 = 0;
    if (chooseAmount == 4) {
        catalogId2 = document.getElementById(catalogInputIdArray[index++]).value;
        catalogId3 = document.getElementById(catalogInputIdArray[index++]).value;
        catalogId4 = document.getElementById(catalogInputIdArray[index++]).value;
    }
    var chooseCatalogFrame = document.getElementById('CatalogChooserFrame');
    if ((chooseCatalogFrame.src).indexOf("catalog_chooser.htm") <= 0) {
        chooseCatalogFrame.src = "/helper/catalog_chooser.htm?chooseAmount=" + chooseAmount + "&catalogNameList[0].id=" + catalogId1 + "&catalogNameList[1].id=" + catalogId2 + "&catalogNameList[2].id=" + catalogId3 + "&catalogNameList[3].id=" + catalogId4;
    }
    document.getElementById('CatalogChooserDiv').style.visibility = 'visible';
}

   function addBizTypeCatalog(chooseAmount) {
        var catalogIdObj = document.getElementById('catalogId');
        var catalogIdListObj = document.getElementById('catalogIdList');

        if (catalogIdObj.selectedIndex > -1) {
            if (catalogIdListObj.options.length < chooseAmount) {
                  var choosedText = catalogIdObj.options[catalogIdObj.selectedIndex].text;
                  var choosedValue = catalogIdObj.options[catalogIdObj.selectedIndex].value;

                  var canAdd = true;
                  for (var i = 0; i < catalogIdListObj.options.length; i++) {
                        if (catalogIdListObj.options[i].value == choosedValue) {
                                canAdd = false;
                                break;
                        }
                }
                if (canAdd) {
                        catalogIdListObj.options[catalogIdListObj.options.length] = new Option(choosedText, choosedValue,  false, false);
                }
            }

        }

    }
    function deleteBizTypeCatalog() {
        var catalogIdObj = document.getElementById('catalogId');
        var catalogIdListObj = document.getElementById('catalogIdList');
        if (catalogIdListObj.selectedIndex > -1) {
                catalogIdListObj.options[catalogIdListObj.selectedIndex] = null;
        }
    }
    function saveBizTypeCatalog(catalogIdArray,catalogNameArray) {
        //document.getElementById('choosedCatalogsNames').innerHTML = "";


        for (var i = 0; i < catalogIdArray.length; i++) {
            
            document.getElementById('catalogId' + (i+1)).value = catalogIdArray[i];
            document.getElementById('catalogName' + (i+1)).value = catalogNameArray[i];
            
        }


        document.getElementById('CatalogChooserDiv').style.visibility = 'hidden';
    }
    function closeBizTypeCatalog() {
        document.getElementById('CatalogChooserDiv').style.visibility = 'hidden';
    }
    /*
    function handleProvince(withEmptyOption) {


    }*/



    function initPublishLanguage() {

        var checkValue = document.getElementsByName('url')[0].value;

        document.getElementById('publishLang_' + checkValue).checked = true;

    }

    function submitForm() {

        if (!checkAgreement()) return false;
            return true;
    }


    function addToBasket(checkboxName, inquiryType) {
        var objectIds = '';
        var checkboxObjs = document.getElementsByName(checkboxName);
        for (var i = 0; i < checkboxObjs.length; i++) {
            var checkboxObj = checkboxObjs[i];
            if (checkboxObj.checked) {
                if (objectIds != '') objectIds += ",";
                objectIds += checkboxObj.value;

                checkboxObj.checked = true;
                checkboxObj.disabled = true;
            }
        }

        addObjectToInquiryBasket(objectIds, inquiryType);

    }

    var xmlHttp = null;

    function addObjectToInquiryBasket(objectIds, inquiryType) {

        var servleturl = websiteURL + "/inquiry/add.htm?inquiryType=" + inquiryType + "&objectId=" + objectIds;
        window.open(servleturl);

/*
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }else if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        //we can do the job only the XMLHttpRequest is supported

        if( xmlHttp ){
            xmlHttp.open("GET", servleturl, false);
            xmlHttp.onreadystatechange = addObjectToInquiryBasketReply;
            xmlHttp.send(null);
        } else {
            alert('user agent dont support the ajax');
        }
*/

    }
    function addObjectToInquiryBasketReply() {

        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {

                var baksetSize = (xmlHttp.responseText);

                var baksetSizeObj = document.getElementById('BaksetSize');

                baksetSizeObj.innerHTML = baksetSize;

                changeColorObj = baksetSizeObj;
                colorNum = 0;
                colorChangeOver();
            }
        }

    }

    var col = new Array();
    col[col.length] = 'yellow';
    col[col.length] = 'orange';
    col[col.length] = 'red';
    col[col.length] = 'white';

    var colorNum = 0;
    var changeColorObj = null;

    function colorChangeOver() {
        if (colorNum >= 0 && colorNum < col.length) {
            changeColorObj.style.backgroundColor = col[colorNum];
            colorNum++;
            setTimeout('colorChangeOver()',1000)
        }
    }


// search function

function doSearch() {
    var searchTypeObj = document.getElementById('searchType');
    var searchTypeValue = searchTypeObj.options[searchTypeObj.selectedIndex].value;

    var searchKeyValue = document.getElementById('searchKey').value;
    searchKeyValue = searchKeyValue.replace(/[\uFF00-\uFFFF]/g,'');
    searchKeyValue = searchKeyValue.replace(/[#%\?]/g,'');

    if (searchKeyValue != '' && searchKeyValue.length > 1) {
        searchKeyValue = encodeURI(searchKeyValue);
        searchKeyValue = encodeURI(searchKeyValue);

        window.location.href="/search/" + searchTypeValue + "/" + searchKeyValue + ".html";
    } else if (searchKeyValue == '') {
        document.getElementById('searchKey').value = '';
    }
}

function eventOnDataBar(dataId) {

}