var keyDOWN = 0;
var keyUP = 0;
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function setCheckboxDisplay(el) {
    var objWrap;
    objWrap = document.getElementById(el.id + "Wrap");
    if (el) {
        if (el.checked) objWrap.className = "styledCheckboxWrap wrapChecked";
        else objWrap.className = "styledCheckboxWrap";
    }
}



	
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(c_name, value, exdays) {
    //		Y.Cookie.set(c_name,value,{path="/"});

    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) //+ "; expires=1/1/2100"; 
        + ((exdays == null) ? "" : ("; expires=" + exdate.toUTCString()))
    //document.cookie = ";domain=localhost";
    document.cookie = c_name + "=" + c_value + "; path=/";

    //alert("SiteMater----" + c_name);
    //alert("SiteMater----value---" + value);

    //alert(document.cookie);


}

function setCookieDocument(c_name, value) {
    var exdate = new Date();
    var exdays = 365;
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) //+ "; expires=1/1/2100"; 
        + ((exdays == null) ? "" : ("; expires=" + exdate.toUTCString()))
    document.cookie = c_name + "=" + c_value + ";";
}
/**
* Deletes the specified cookie.
*
* name      name of the cookie
* [path]    path of the cookie (must be same as path used to create cookie)
* [domain]  domain of the cookie (must be same as domain used to create cookie)
*/
function deleteCookie(name) {
    document.cookie = name + '=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;';

//    if (getCookie(name)) {
//        document.cookie = name + "=" +
//            "; path=/"  // + path : "") +
//        //((domain) ? "; domain=" + domain : "") +
//        "; expires=Thu, 01-Jan-70 00:00:01 GMT"; // "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 01-01-70
//        //alert(document.cookie);
//    }
}


function removeCookie(c_name) {
    //alert(c_name);
    deleteCookie(c_name);
}


/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name)
		{
		return unescape(y);
		}
	  }
}

/**
 * erase cookies
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * Check cookies
 */
function checkCookie()
{
	var username=getCookie("username");
	  if (username!=null && username!="")
	  {
	  alert("Welcome again " + username);
	  }
	else
	  {
	  username=prompt("Please enter your name:","");
	  if (username!=null && username!="")
		{
		setCookie("username",username,365);
		}
	  }
}

// apply for all form
function changeTotalRowPerPage(recordPerPage) {
    document.getElementById("totalRowPerPage").value = recordPerPage;
    document.getElementById("currentPage").value = 1;
    document.forms[0].submit();
}

function changeToNewPage(newPage) {
    document.getElementById("currentPage").value = newPage;
    document.forms[0].submit();
}

function doSort(orderBy) {
    document.getElementById("orderBy").value = orderBy;
    //alert(orderBy);
    document.forms[0].submit();
}

// uncheck all checkbox by name
function clearAll(chkName,numberOfControl){
//alert(chkName);
	
	for(var i=0; i<numberOfControl ;i++){
		var objCheckBox = document.getElementById(chkName + i);
		var objWrap = document.getElementById(chkName + i + "Wrap");
		objCheckBox.checked = false;			
		objWrap.className = "styledCheckboxWrap";
	}
}

// select checked all checkbox by name
function selectAll(chkName,numberOfControl){
	//alert(chkName);
		
		for(var i=0; i<numberOfControl ;i++){
			var objCheckBox = document.getElementById(chkName + i);
			var objWrap = document.getElementById(chkName + i + "Wrap");
			objCheckBox.checked = true;			
			objWrap.className = "styledCheckboxWrap wrapChecked";
		}
}

// hide any control by Id
function hideControl(controlId){
	var objControl = document.getElementById(controlId);	
	objControl.style.visibility = "hidden";
}

// 
function getCookieArray(cookieName) {
	var i = 1;
	var arr = new Array();
	//alert(getCookie(cookieName+1));
	while( getCookie(cookieName+i) != "undefined"){
		arr[i] = getCookie(cookieName+i);
		if(i<10) {alert(getCookie(cookieName+i)); break;}
		i++;
	}
	return arr;
}

function addFavorites(name, value) {
    var i = 1;
    var temp;
    while (1 == 1) {
        temp = name + i;
        if (getCookie(temp) == 'undefine' || getCookie(temp) == null) {
            break;
        }
        i++;
    }
    alert(i);
    alert("value---" + value);
    i = temp.substring(name.length);
    var flag_new = name + 1;
    var j = 2;
    while (1 == 1) {
        var flag = name + i;
        var flag_old = name + (i - 1);
        alert("bien thu moi--" + j + "-----" + getCookie(flag));
        alert("bien thu cu--" + (i - 1) + "-----" + getCookie(flag_old));
        setCookie(flag, getCookie(flag_old), 7);
        if (i == 0) {
            break;
        }
        i--;
    }
    setCookie(flag_new, value, 7);
    //alert(document.cookie);
}
    /*
    * store cookie for goods_manage_id only
    */
	function setCookieArray(goods_manage_id) {
        // plus +1
	    var hrefCount = "BoatFavoriteCount";
	    var linkACount = $("a[id='" + hrefCount + "']");
	    var countText = "お気に入り(";
	    $.each(linkACount, function () {
	        if ($(this).html().indexOf(countText) >= 0) {
	            //alert(Number(getdigits($(this).html())) + 1);
	            var num = Number(getdigits($(this).html())) + 1;
	            if (num <= 50) {
	                $(this).html(countText + num + ")");
	                setFavouriteCookie(goods_manage_id);
	                changeImage(goods_manage_id);
	            }
	        }
	    });
	}

	function changeImage(goods_manage_id) {
	    //<a href="javascript:setCookieArray('GM23637');">
	    var href = "javascript:setCookieArray('" + goods_manage_id + "');";
	    var addedImage = '<img width="158" height="25" id="img1" alt="" src="/Content/images/V1000/VNewStarArrival.png"/>';
	    var linkA = $("a[href='" + href + "']");
	    $.each(linkA, function () {
	        addedImage = getReplaceHtml($(this).html());
	        $(this).replaceWith($(addedImage));
	    });
	}

	function getReplaceHtml(currentHtml) {
	    var replaceHtml = "sai";
	    if (currentHtml.indexOf('button-add-favorites') > 0) // thumbnail
	        replaceHtml = '<img width="158" height="25" id="img1" alt="" src="/Content/images/V1000/VNewStarArrival.png"/>';
	    else if (currentHtml.indexOf('url(/Content/images/Common/favorite-icon.png)') > 0) // list
	        replaceHtml = '<div style="background:url(/Content/images/Common/favorite-icon.png) no-repeat; background-position:0px -38px; width:35px; height:35px; margin:auto "></div>';
	    else if (currentHtml.indexOf('Content/images/V1000/AddNewArrival.png') > 0) // boat detail
	        replaceHtml = '<img width="153" height="25" id="img1" alt="" src="/content/images/V1000/VNewStarArrival.png" complete="complete"/>';
	    else if (currentHtml.indexOf('/Content/images/V1000/ButtonAddFavorites.png') > 0) // shop detail
	        replaceHtml = '<img width="158" height="25" style="margin-bottom: 5px;*margin-bottom: 0px;" src="/Content/images/V1000/VNewStarArrival.png" alt="" id="img1">';

	    return replaceHtml;
    }
//    function getNumberFromStr(str)
//    {
//      str = str.Trim();
//      Match m = Regex.Match(str, @"^[\+\-]?\d*\.?[Ee]?[\+\-]?\d*$");
//      return (m.Value);
	//    }

    // This returns a string with everything but the digits removed.
    function getdigits (s) {
       return s.replace (/[^\d]/g, '');
    }

function WaterMark(defaultText, txt, evt) {
    if (txt.value.length == 0 && evt.type == "blur") {
        txt.value = defaultText;
        txt.style.color = "#999999";
    }
    if(evt.type == "focus") {
    	txt.style.color = "black";
    }
    if (txt.value == defaultText && evt.type == "focus") {
        txt.value = "";
        txt.style.color = "#000000";
    }
    
}
/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

// ham xu ly combobox 
function onselectchange() {
   $(this).attr('style', 'width:200px;color:#000000;border: 1px solid #aaa;');
}
// ham xu ly combobox 
function onChange() {
    if ($(this).val() == "") {
        $(this).attr('style', 'width:200px;color:#000000;border: 1px solid #aaa;');
    } else {
        $(this).attr('style', 'width:200px;color:#000000;border: 1px solid #aaa;');
    }
}


// chi insert so onkeypress="return inNumberKey(evnt) ";
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) )
        return false;
    return true;
}

// checkMaxlength
// maxlength='150' onKeyUp='return ismaxlength(this)'
function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    var oldValue = obj.value;
    if (obj.getAttribute && obj.value.length > mlength) {
        if (jQuery.browser.msie) { //fix for ie
            if (keyDOWN == 229 && keyUP == 13) /*kanji input enter*/{
                obj.value = oldValue.substr(0, mlength);
            }
            if (keyDOWN != 229) /*no kanji input is ok*/{
                obj.value = oldValue.substr(0, mlength);
            }
        }
        else {
            obj.value = obj.value.substring(0, mlength)
        }
    }
}

function kCode(e) {
    if (e.KeyCode != 0) {
        return e.keyCode;
    } else {
        return e.charCode;
    }
}

// nut Cancel --> Top
function doCancelTop() {
    document.forms[0].action = "/";
    document.forms[0].submit();

}

// confirm dialog
// history.go(-1)
function conFirmCancel(url) {
    var str = "編集中の内容があります \n"
+ "キャンセルすると編集内容は保存されません \n"
+ "キャンセルしてもよろしいですか？ \n";
    if (confirm(str)) {
        document.forms[0].action = url;
        document.forms[0].submit();
    }

}
///
function optionCancel(pathname,isPost) {
    var str = "編集中の内容があります \n"
+ "キャンセルすると編集内容は保存されません \n"
+ "キャンセルしてもよろしいですか？ \n";
    if (confirm(str)) {
        var no_sslurl = "http://" + document.location.host + "/"+ltrim(pathname,"/");
    	if (isPost) {
	        document.forms[0].action = no_sslurl;
	        document.forms[0].submit();
	    } else {
    	    history.back();
	    	//window.location = no_sslurl;
	    }
    }
}


// chi insert so onchane="return inNumberKey(evnt) ";
function isNumberKey(evt) {
    var val = evt.value;
    var re = "[0-9]";
    if (!val.match(re)) {
        document.getElementById(evt.id).value = "";
    }
    return false;
}
//Ham thiet lap maxlength cho textarea
function imposeMaxLength(Object, MaxLen) {
    return (Object.value.length <= MaxLen);
}
// check chu kana
function isKana(str) {
    var name1 = /^[\u3040-\u3096|\u30A1-\u30FA|\uFF66-\uFF9D|\u31F0-\u31FF]+$/; // kana    
    if (str.match(name1)) {
        return true;
    } else {
        return false;
    }
}

// check chu katakana
function isKatakana(str) {
    var name2 = /^[\u30A1-\u30FA]+$/; // katakana
    if (str.match(name2)) {
        return true;
    } else {
        return false;
    }
}
// check chu kanji
function isKanji(str) {
    var name3 = /^[\u4E00-\u9FAF]+$/; // kanji
    if (str.match(name3)) {
        return true;
    } else {
        return false;
    }
}

function initBoatSearch() {
    var radioJapanChecked = document.getElementById('RadioJapan');
    if (radioJapanChecked == null) return;

    var radioOutJapanChecked = document.getElementById('RadioRegion');
    if (radioJapanChecked.checked == true) {
        document.getElementById('japan').disabled = false;
        document.getElementById('outJapan').disabled = true;
    }
    if (radioOutJapanChecked.checked == true) {
        document.getElementById('outJapan').disabled = false;
        document.getElementById('japan').disabled = true;
    }

}
//item is: id->#id, class->.className, type->typeName, name->[name=name_value]
function setWarterMarkByItem(theItem) {
    var obj = $(theItem);
    $.each(obj, function () {
        if (this.getAttributeNode('onfocus') != null) {
            var onfocus_string = this.getAttributeNode('onfocus').value;
            //alert(onfocus_string);
            if (onfocus_string.indexOf("'" + $(this).val() + "'") > 0) {
                $(this).css("color", "#999");
            }
            else {
                $(this).css("color", "#000");
            }
        }
    });
}

function scanAllWarterMark() {
    var textarea = $("textarea");
    $.each(textarea, function () {
        if (this.getAttributeNode('onfocus') != null) {
            var onfocus_string = this.getAttributeNode('onfocus').value;
            //alert(onfocus_string);
            if (onfocus_string.indexOf("'" + $(this).val() + "'") > 0) {
                $(this).css("color", "#999");
            }
            else {
                $(this).css("color", "#000");
            }
        }
    });

    var text = $("input[type=text]");
    $.each(text, function () {
        //alert(this.getAttributeNode('onfocus') );
        if (this.getAttributeNode('onfocus') != null) {
            var onfocus_string = this.getAttributeNode('onfocus').value;
            //alert(onfocus_string.indexOf("'" + $(this).val() + "'"));
            if (onfocus_string.indexOf("'" + $(this).val() + "'") > 0) {
                $(this).css("color", "#999");
                //alert(onfocus_string.indexOf("'" + $(this).val() + "'"));
            }
            else {
                $(this).css("color", "#000");
            }
        }
    });
}

function switchToSubmit(url, shopID) {
    //alert(url);
    var boatDetail = '/Detail/Boat/';
    var index = url.indexOf(boatDetail);
    var boatID = '';
    if (index >= 0) {
        boatID = url.substr(boatDetail.length);
        url = '/Detail/Boat';
    }
    //alert(boatID);
    $('body').append("<div style=\"display:none;\"><form id='newForm' action='" + url + "' method='post'><input type=hidden name='boatID' value='" + boatID + "'> <input type=hidden name='currentShopID' value='" + shopID + "'><input type=submit></form></div>");
    //alert(url);
    $('#newForm').submit();
}


//var undefined = 'undefined';
//save cookie for only that document (not path)
function scanAllSaveCookie(isInPath) {
    //hopeboat: txtFirtNameKana,txtLastNameKana,txtFirtNameKata,txtLastNameKata,zip1,zip2,prepecture,txtCity,txtTower,txtHome,txtTel1,txtTel2,txtTel3,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,txtFax1,txtFax2,txtFax3,txtEmail,txtEmailConfirm
    // contact: ho_kana,ten_kana,ho_katakana,ten_katakana,zip1,zip2,prefecture,pho_quan,so_hieu,so_nha,tel_fax_email,telFirst,telSecond,telThree,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,faxFirst,faxSecond,faxThree,email,validate_email
    // hopesale: parent_name_kana,private_name_kana,parent_name_kata,private_name_kata,postcode_one,postcode_two,country_name,district_city,address_name,house_no,phone_no1,phone_no2,phone_no3,phone_no1_hand,phone_no2_hand,phone_no3_hand,fax_no1,fax_no2,fax_no3,email,reemail
    //defaut:is hopeboat
    var list = "txtFirtNameKana,txtLastNameKana,txtFirtNameKata,txtLastNameKata,zip1,zip2,prepecture,txtCity,txtTower,txtHome,txtTel1,txtTel2,txtTel3,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,txtFax1,txtFax2,txtFax3,txtEmail,txtEmailConfirm";
    if (document.location.pathname.toLowerCase().indexOf("contact") > 0)
        list = "ho_kana,ten_kana,ho_katakana,ten_katakana,zip1,zip2,prefecture,pho_quan,so_hieu,so_nha,tel_fax_email,telFirst,telSecond,telThree,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,faxFirst,faxSecond,faxThree,email,reemail";
    else if (document.location.pathname.toLowerCase().indexOf("hopesales") > 0)
        list = "parent_name_kana,private_name_kana,parent_name_kata,private_name_kata,postcode_one,postcode_two,country_name,district_city,address_name,house_no,tel_fax_email,phone_no1,phone_no2,phone_no3,phone_no1_hand,phone_no2_hand,phone_no3_hand,fax_no1,fax_no2,fax_no3,email,validate_email";
    //alert(list);
    //cookie3FormContact(list);
    setObjectFor3FormContact(list);
    return;

    /*
    isInPath = true; //apply all
    var radio_checked = $(":radio:checked");
    $.each(radio_checked, function () {
        //alert($(this).val());
        if (isInPath == true) {
            var current = getCookie($(this).attr("name"));
            setCookie($(this).attr("name"), $(this).val(), 365);
        } else {
            var current = getCookie($(this).attr("name"));
            setCookieDocument($(this).attr("name"), $(this).val());
        }
    });

    var checkbox_checked = $(":checkbox:checked");
    $.each(checkbox_checked, function () {
        if (isInPath == true) {
            var current = getCookie($(this).attr("name"));
            if (current == undefined) {
                setCookie($(this).attr("name"), $(this).val(), 365);
            }
            else {
                var arr = current.split(",");
                if (jQuery.inArray($(this).val(), arr) < 0) {
                    setCookie($(this).attr("name"), current + "," + $(this).val(), 365);
                }
            }
        } else {
            var current = getCookie($(this).attr("name"));
            if (current == undefined) {
                setCookieDocument($(this).attr("name"), $(this).val());
            }
            else {
                var arr = current.split(",");
                if (jQuery.inArray($(this).val(), arr) < 0) {
                    setCookieDocument($(this).attr("name"), current + "," + $(this).val());
                }
            }
        }
        
    });

    var select = $("select");
    $.each(select, function () {
        if (isInPath == true) {
            setCookie($(this).attr("name"), $(this).val(),365);
        } else {
            setCookieDocument($(this).attr("name"), $(this).val());
        }
    });

    var textarea = $("textarea");
    $.each(textarea, function () {
        if (isInPath == true) {
            setCookie($(this).attr("name"), $(this).val(), 365);
        } else {
            setCookieDocument($(this).attr("name"), $(this).val());
        }
    });

    var text = $("input[type=text]");
    $.each(text, function () {
        //alert($(this).attr("name"));
        if (isInPath == true) {
            setCookie($(this).attr("name"), $(this).val(), 365);
        } else {
            setCookieDocument($(this).attr("name"), $(this).val());
        }
    });

    */

}

//save cookie for only that document (not path)
function loadAllCookie() {
    //hopeboat: txtFirtNameKana,txtLastNameKana,txtFirtNameKata,txtLastNameKata,zip1,zip2,prepecture,txtCity,txtTower,txtHome,txtTel1,txtTel2,txtTel3,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,txtFax1,txtFax2,txtFax3,txtEmail,txtEmailConfirm
    // contact: ho_kana,ten_kana,ho_katakana,ten_katakana,zip1,zip2,prefecture,pho_quan,so_hieu,so_nha,tel_fax_email,telFirst,telSecond,telThree,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,faxFirst,faxSecond,faxThree,email,validate_email
    // hopesale: parent_name_kana,private_name_kana,parent_name_kata,private_name_kata,postcode_one,postcode_two,country_name,district_city,address_name,house_no,phone_no1,phone_no2,phone_no3,phone_no1_hand,phone_no2_hand,phone_no3_hand,fax_no1,fax_no2,fax_no3,email,reemail
    //defaut:is hopeboat
    var list = "txtFirtNameKana,txtLastNameKana,txtFirtNameKata,txtLastNameKata,zip1,zip2,prepecture,txtCity,txtTower,txtHome,txtTel1,txtTel2,txtTel3,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,txtFax1,txtFax2,txtFax3,txtEmail,txtEmailConfirm";
    if (document.location.pathname.toLowerCase().indexOf("contact") > 0)
        list = "ho_kana,ten_kana,ho_katakana,ten_katakana,zip1,zip2,prefecture,pho_quan,so_hieu,so_nha,tel_fax_email,telFirst,telSecond,telThree,txtTel1HandPhone,txtTel2HandPhone,txtTel3HandPhone,faxFirst,faxSecond,faxThree,email,reemail";
    else if (document.location.pathname.toLowerCase().indexOf("hopesales") > 0)
        list = "parent_name_kana,private_name_kana,parent_name_kata,private_name_kata,postcode_one,postcode_two,country_name,district_city,address_name,house_no,tel_fax_email,phone_no1,phone_no2,phone_no3,phone_no1_hand,phone_no2_hand,phone_no3_hand,fax_no1,fax_no2,fax_no3,email,validate_email";

    getObjectFor3FormContact(list);

    return;
    /*
    var radio = $(":radio");
    $.each(radio, function () {
        var current = getCookie($(this).attr("name")); //get value group checkbox by name
        //alert(current);
        if (current != undefined) {
            var arr = current.split(",");
            if (jQuery.inArray($(this).val(), arr) >= 0) {
                this.checked = true;
            }
        }

    });
    
    
    var checkbox = $(":checkbox");
    $.each(checkbox, function () {

        var current = getCookie($(this).attr("name")); //get value group checkbox by name
        //alert(current);
        if (current != undefined) {
            var arr = current.split(",");
            //jQuery.inArray( value, array ) is -1 if not found, is pos if found
            //alert($(this).val() + "->" + jQuery.inArray($(this).val(), arr));
            if (jQuery.inArray($(this).val(), arr) >= 0) {
                this.checked = true;
                setCheckboxDisplay(this);  //display checked setCheckboxDisplay(this)
            }
        }

    });

    var select = $("select");
    $.each(select, function () {
        //alert($(this).attr("name"));
        c_value = getCookie($(this).attr("name"));
        if (c_value != undefined) {
            $(this).val(c_value);
            //$('#' + $(this).attr("id") + ' option').eq(c_value).attr('selected', 'selected');
        }    
    });

    var textarea = $("textarea");
    $.each(textarea, function () {
        //alert($(this).attr("name"));
        c_value = getCookie($(this).attr("name"));
        if (c_value != undefined) {
            $(this).val(c_value);
        }   
    });

    var text = $("input[type=text]");
    $.each(text, function () {
        //alert($(this).attr("name"));
        c_value = getCookie($(this).attr("name"));
        //alert($(this).attr("name") + ":" + c_value);
        if (c_value != undefined) {
            $(this).val(c_value);
        }   
    });
    */
}


function doSubmitHttps(pathname) {
    var host = document.location.host;
    var hostname = document.location.hostname;
    //host = (hostname == "localhost" ? hostname + ":12704" : hostname)
    document.forms[0].action = "https://" + host + "/" + ltrim(pathname, '/');
    if (hostname == "localhost")
        document.forms[0].action = "http://" + host + "/" + ltrim(pathname, '/'); //testing local
    document.forms[0].submit();
}

function cancelAlert(pathname) {
    var answer = confirm("編集中の内容があります \n" +
                            "キャンセルすると編集内容は保存されません\n" +
                            "キャンセルしてもよろしいですか？");

    if (answer == true) {
        window.location = "http://" + document.location.host + "/" + ltrim(pathname,'/'); // pathname like this -> "/Option/HopeBoatAlertPolicy";
        //history.back();
    }
}

function deleteCookieByList(list) {
    if (list == null || list == "") return;
    var arr = list.split(",");
    var cname;
    var cvalue;
    for (var i = 0; i < arr.length; i++) {
        cname = arr[i];
        //cvalue = getCookie(cname);
        deleteCookie(cname);
    }
}

function setCookieByList(list, fromCookie) {
    if (list == null || list == "") return;
    var arr = list.split(",");
    var cname;
    var cvalue = getCookie(fromCookie);
    if (cvalue != undefined) {
        for (var k = 0; k < arr.length; k++) {
            cname = trim(arr[k], ' ');
            if (cname != fromCookie) {
                //alert(cname + "=" + cvalue);
                setCookie(cname, cvalue, 365);
            }
        }
    }
}

//image over, down motion
function addImgMotion(img, srcHover, srcPressed) {
    img.srcRest = img.src;
    img.srcHover = srcHover;
    img.srcPressed = srcPressed;
    img.onmouseover = onImageMouseOver;
    img.onmouseout = onImageMouseOut;
    img.onmousedown = onImageMouseDown;
    img.onmouseup = onImageMouseUp;
}

function onImageMouseOver() {
    this.src = this.srcHover;
}

function onImageMouseOut() {
    this.src = this.srcRest;
}

function onImageMouseDown() {
    this.src = this.srcPressed;
}

function onImageMouseUp() {
    this.src = this.srcHover;
}

$(document).ready(function() {
		MM_preloadImages('/content/images/V22xx/ButtonBoatSearch_N.png',
					 '/content/images/V22xx/ButtonBoatSearch_O.png',
					 '/content/images/V22xx/ButtonBoatSearch_D.png',
			         '/content/images/V22xx/ButtonConditionClear_N.png',
			         '/content/images/V22xx/ButtonConditionClear_O.png',
			         '/content/images/V22xx/ButtonConditionClear_D.png',
			         '/content/images/V1000/ButtonBoatSearch_N.png',
					 '/content/images/V1000/ButtonBoatSearch_O.png',
					 '/content/images/V1000/ButtonBoatSearch_D.png',
			         '/content/images/V1000/ButtonConditionClear_N.png',
			         '/content/images/V1000/ButtonConditionClear_O.png',
			         '/content/images/V1000/ButtonConditionClear_D.png',
			         '/content/images/V1000/ButtonSearch_N.png',
			         '/content/images/V1000/ButtonSearch_O.png',
			         '/content/images/V1000/ButtonSearch_D.png');

		scanAllWarterMark();
		setAllCheckboxDisplay();
});


function setAllCheckboxDisplay() {
    var checkbox = $(':checkbox:checked');
    $.each(checkbox, function () {
        setCheckboxDisplay(this);
    });
}

function goToTopOfPage(){
    $('html, body').animate({ scrollTop: 0 }, 'slow');
}
