function openDetailWindow(URL){
	window.open(URL, "NETLINK", "width=500,height=550,resizable=no,menubar=no,scrollbars=yes,status=no,toolbar=no,titlebar=no");
}

// ページアクション
function submitPage(form, action, pageAction){

	form.action = action;

	if (pageAction != ""){
		form.pageAction.value = pageAction;
	}
	form.submit();

	return false;
}

function OpenWin(strHtml){
    win=window.open(strHtml,"new","width=538,height=500,scrollbars=yes,toolbar=yes");
}


function show_win(offfset_x,offset_y,w,msg,event){
	if (navigator.userAgent.match(/Mac/i) && navigator.userAgent.match(/MSIE\s+(\d+)\.?(\d+)?/i) ) {
		return;
	}
	
	
	if(document.getElementById){
		pop_obj=document.getElementById("pop");
	}else if(document.all){
		pop_obj=document.all("pop");
	}else if(document.layers){
		pop_obj = document.layers[obj];
	}
	if(event.x != null){
		x = event.x;
	}else{
		x = event.pageX;
	}
	if(event.y != null){
		y = event.y;
	}else{
		y = event.pageY;
	}

	pop_obj.innerHTML = msg;
	pop_obj.style.position = 'absolute';
	
	if (!navigator.userAgent.match(/Mac/i) || !navigator.userAgent.match(/MSIE\s+(\d+)\.?(\d+)?/i) ) {
		pop_obj.style.width = w + "px";
	}
	
	
	if(document.all){
		if (!navigator.userAgent.match(/Mac/i) || !navigator.userAgent.match(/MSIE\s+(\d+)\.?(\d+)?/i) ) {
			x+=document.documentElement.scrollLeft;
			y+=document.documentElement.scrollTop;
		}else{
			x+=document.body.scrollLeft;
			y+=document.body.scrollTop;
		}
	}
	x += offfset_x;
	y += offset_y;
	
    if(document.getElementById){        //Moz,NN6,IE5用
      pop_obj.style.left=x+ "px";
      pop_obj.style.top=y+ "px";
    }else if(document.all){
      pop_obj.style.pixelLeft=x; //IE4用
      pop_obj.style.pixelTop=y;
    }else if(document.layers){
     pop_obj.moveTo(x,y)    //NN4用
	}
	/*
	for(i=0;i<document.forms[0].elements.length;i++){
		if(document.forms[0].elements[i].type=='select-one'){
			document.forms[0].elements[i].style.display='none';
		}
	}*/
	pop_obj.style.display='';
}

function hide_win(){
	if(document.getElementById){
		pop_obj=document.getElementById("pop");
	}else if(document.all){
		pop_obj=document.all("pop");
	}else if(document.layers){
		pop_obj = document.layers[obj];
	}
	/*
	for(i=0;i<document.forms[0].elements.length;i++){
		if(document.forms[0].elements[i].type=='select-one'){
			document.forms[0].elements[i].style.display='';
		}
	}*/
	pop_obj.style.display='none';
}


function checkCoupon(){

	URL = "http://netlink.bz/coupon/issueConfirm.php?i=";
	clickID = document.forms[0].elements["clickID"].value;

	joinLinkID = "";
	linkID = "";

	if (document.forms[0].elements["issueCoupon1"]){
		u1=document.forms[0].elements["issueCoupon1"].checked;

		if (u1){
			linkID1 = document.forms[0].elements["issueLinkID1"].value;

			linkID = linkID + linkID1.length + linkID1;
		}
	}
	if (document.forms[0].elements["issueCoupon2"]){
		u2=document.forms[0].elements["issueCoupon2"].checked;

		if (u2){
			linkID2 = document.forms[0].elements["issueLinkID2"].value;

			linkID = linkID + linkID2.length + linkID2;
		}
	}
	if (u3=document.forms[0].elements["issueCoupon3"]){
		u3=document.forms[0].elements["issueCoupon3"].checked;

		if (u3){
			linkID3 = document.forms[0].elements["issueLinkID3"].value;

			linkID = linkID + linkID3.length + linkID3;
		}
	}

	if (linkID != ""){

		joinLinkID = clickID.length + clickID + linkID;

		document.getElementById("qr_img").src="../webapp/qr_img/php/qr_img.php?d=" + URL + joinLinkID;
		document.getElementById("subject").innerHTML = joinLinkID;
	} else {

		document.getElementById("qr_img").src="";
		document.getElementById("subject").innerHTML = "&nbsp;";
	}


}

function showhide(id){
	if(document.getElementById){
		if(document.getElementById(id).style.display == "none")
			document.getElementById(id).style.display = "block";
		else
			document.getElementById(id).style.display = "none";
	}
}

function showColorPalette(text){

	Form1.hidColorPalette_text.value=text;
	Form1.hidColorPalette_td.value='td_' + text;

	document.getElementById('colorPalette').style.display = "block";
}

function hideColorPalette(){

	Form1.hidColorPalette_text.value='';
	Form1.hidColorPalette_td.value='';

	document.getElementById('colorPalette').style.display = "none";
}

function drawcolor(colorcode){

	var text = Form1.hidColorPalette_text.value;
	var td = Form1.hidColorPalette_td.value;

	document.getElementsByName(text).item(0).value = colorcode;
	document.getElementById(td).style.background = colorcode;

	if (text == "partsBackgroundColor"){

		document.getElementById("imageTable").style.background = colorcode;
	} else if (text == "partsTextColor"){

		document.getElementById("imageTable").style.color = colorcode;

		document.getElementById("imageBlogger").style.color = colorcode;
		document.getElementById("imageMember").style.color = colorcode;
		document.getElementById("imageNetlink").style.color = colorcode;
	} else if (text == "couponBackgroundColor"){

		document.getElementById("imageCoupon1").style.background = colorcode;
		document.getElementById("imageCoupon2").style.background = colorcode;
		document.getElementById("imageCoupon3").style.background = colorcode;
	} else if (text == "couponTextColor"){

		document.getElementById("imageCouponLink1").style.color = colorcode;
		document.getElementById("imageCouponLink2").style.color = colorcode;
		document.getElementById("imageCouponLink3").style.color = colorcode;
	} else if (text == "couponContentsTextColor"){

		document.getElementById("imageCouponContents1").style.color = colorcode;
		document.getElementById("imageCouponContents2").style.color = colorcode;
		document.getElementById("imageCouponContents3").style.color = colorcode;
	}

	document.getElementById('colorPalette').style.display = "none";
}

function changeWidth(size){

	document.getElementById("imageTable").style.width = size;
	document.getElementById("imageDiv").style.width = size - 5;
}

function changeHeight(size){

	document.getElementById("imageDiv").style.height = size -100;
}

function calculateLandValue(price,land){

    var landValue = 0;

    if (isNaN(price) || isNaN(land)) {
        return "";
    }

    if (price != "" && land != ""){

        landValue = price/land;
        landValue = Math.round(landValue*100);
        landValue = landValue/100;
            
    }

    if (landValue == 0){

        landValue = "";
    }

    return landValue;

}

function calculateLand(div,data,tsuboValue,squareValue){

    var land = 0;

    if (!isNaN(data)){

        if (div == "TSUBO"){
            land = data * tsuboValue;
        } else {
            land = data * squareValue;
        }

        land = Math.round(land*100);
        land = land/100;

    }

    if (land == 0){

        land = "";
    }

    return land;
}

function checkedFlag(width){

    if (width != ""){

        return true;

    } else {

        return false;

    }

}

function editFromWarekiToSeireki(form,dealDiv){

    syouwa = 1925;
    heisei = 1988;
    nen = 0;

    if (dealDiv == ""){

        if (isNaN(form.constructionYear1.value)) {
            alert("和暦年を半角数値で入力して下さい。");
            return;  
        } 

        if(form.gengoFlag[0].checked == true) {
            if (form.constructionYear1.value > 63) {
                alert("昭和は63年までです。");
                /*form.constructionYear1.focus();*/
                return;                
            } else {
                nen = syouwa + parseInt(form.constructionYear1.value);
                form.constructionYear2.value = nen;
            }
        } else if(form.gengoFlag[1].checked == true) {
            nen = heisei + parseInt(form.constructionYear1.value);
            form.constructionYear2.value = nen;
        }

    } else {

        if (isNaN(form.incomeDuringYearCalculationYear1.value)) {
            alert("和暦年を半角数値で入力して下さい。");
            return;  
        } 

        if(form.gengoFlag1[0].checked == true) {
            if (form.incomeDuringYearCalculationYear1.value > 63) {
                alert("昭和は63年までです。");
                /*form.incomeDuringYearCalculationYear1.focus();*/
                return;                
            } else {
                nen = syouwa + parseInt(form.incomeDuringYearCalculationYear1.value);
                form.incomeDuringYearCalculationYear2.value = nen;
            }
        } else if(form.gengoFlag1[1].checked == true) {
            nen = heisei + parseInt(form.incomeDuringYearCalculationYear1.value);
            form.incomeDuringYearCalculationYear2.value = nen;
        }
    }

}

function editFromSeirekiToWareki(form,dealDiv){

    syouwa = 1925;
    heisei = 1988;
    nen = 0;

    if (dealDiv == ""){

        if (isNaN(form.constructionYear2.value)) {
            alert("西暦年を半角数値で入力して下さい。");
            return;  
        }

        if (form.constructionYear2.value > heisei ) {
            nen = parseInt(form.constructionYear2.value) - heisei ;
            form.constructionYear1.value = nen;
            form.gengoFlag[1].checked = true;
        } else if (syouwa >= form.constructionYear2.value) {
            if (form.constructionYear2.value != 0){
                alert("1925年以前の入力は不可です。");
                return;
            }
        } else {
            nen = parseInt(form.constructionYear2.value) - syouwa ;
            form.constructionYear1.value = nen;
            form.gengoFlag[0].checked = true;
        }

    } else {

        if (isNaN(form.incomeDuringYearCalculationYear2.value)) {
            alert("西暦年を半角数値で入力して下さい。");
            return;  
        }

        if (form.incomeDuringYearCalculationYear2.value > heisei ) {
            nen = parseInt(form.incomeDuringYearCalculationYear2.value) - heisei ;
            form.incomeDuringYearCalculationYear1.value = nen;
            form.gengoFlag1[1].checked = true;
        } else if (syouwa >= form.incomeDuringYearCalculationYear2.value) {
            if (form.incomeDuringYearCalculationYear2.value != 0){
                alert("1925年以前の入力は不可です。");
                return;
            }
        } else {
            nen = parseInt(form.incomeDuringYearCalculationYear2.value) - syouwa ;
            form.incomeDuringYearCalculationYear1.value = nen;
            form.gengoFlag1[0].checked = true;
        }
    }
}

/*----------------------------------------------------------------------------------
 * Pull Down Check Sonota Bukken Shubetu 1
 *---------------------------------------------------------------------------------*/
function sonota_shubetu1_check() {
	var doc = document.Form1;
	shubetu1_obj = doc.articleTypeDiv;
	shubetu1_val = doc.articleTypeDiv.value;

	var outvalue = '';

	arr_cnt1 = Number(shubetu1_val);
	if( arr_cnt1 == 99 ) {
		arr_cnt1 = Sonota_btype.length - 1;
	}

	if( ( shubetu1_val != '' ) && ( shubetu1_val != 0 ) ) {
			outvalue = Sonota_btype[arr_cnt1];
	}

	document.Form1.articleTypeDisplayName.value = outvalue;
}

function clickImage(form, type, num, picname) {
    var type_name = "";

    switch(type){
    case 1:
        type_name = type_madori;
	    break;
    case 2:
        type_name = type_gaikan;
	    break;
    case 3: 
        type_name = type_okunai;
	    break;
    case 4:
        type_name = type_chizu;
	    break;
    case 5:
        type_name = type_kukaku;
	    break;
    case 9:
        type_name = type_sonota;
	    break;
    }

    form.imageNumber.value = num;
    form.addImageNumber.value = num;
    form.updateImageNumber.value = num;
    form.deleteImageNumber.value = num;
	form.addImageType.value  = type_name;
    form.updateImageType.value = type_name;
    form.deleteImageType.value = type_name;
    form.imageType.value = type_name;
    form.imageDiv.value = type;
    form.imageFileNameTemp.value = picname;
}

function clickSubmit(form,action) {

    var file_name = "http://www.s-delight.co.jp/images/imgclick.jpg";
		
    switch(action){
    case "INSERT":        
    	if (form.addImageType.value == "" ){
    		alert( "画像をクリックしてください。" );
    		return;
    	}

		if (form.addImageFileName.value == "" ) {
			alert( "送信するファイルを選択してください。" );
    		return;
		}

        if (form.imageFileNameTemp.value != file_name){
            alert( "新規追加の場合は画像が登録されていない場所を選択してください。");
            return;
        }

        break;
    case "UPDATE":
        if (form.updateImageType.value == "" ){
    		alert( "画像をクリックしてください。" );
    		return;
    	}

		if( form.updateImageFileName.value == "" ) {
			alert( "送信するファイルを選択してください。" );
    		return;
		}

        if (form.imageFileNameTemp.value == file_name){
            alert( "入れ替えの場合は画像が登録されている場所を選択してください。");
            return;
        }
        
        break;

    case "DELETE":
        if (form.deleteImageType.value == "" ){
    		alert( "画像をクリックしてください。" );
    		return;
    	}

        if (form.imageFileNameTemp.value == file_name){
            alert( "削除の場合は画像が登録されている場所を選択してください。");
            return;
        }
	}

    submitPage(form, "imageRegist.php", action);
}

function set_image(img) {
	/* 一旦縦横とも"auto"にして実寸を取得。長い方を"356px"に再設定。そして表示。 */
	img.style.width = "auto";
	img.style.height = "auto";
	if (img.width > img.height) {
		if (img.width > 330) {
			img.style.width = "330px";
		}
	} else {
		if (img.height > 356) {
			img.style.height = "356px";
		}
	}
	img.style.visibility = "visible";
}
function set_imagethum(img) {
	/* 一旦縦横とも"auto"にして実寸を取得。長い方を"116px"に再設定。そして表示。 */
	img.style.width = "auto";
	img.style.height = "auto";
	if (img.width > img.height) {
		if (img.width > 110) {
			img.style.width = "110px";
		}
	} else {
		if (img.height > 88) {
			img.style.height = "88px";
		}
	}
	img.style.visibility = "visible";
}
function set_imagesmall(img) {
	/* 一旦縦横とも"auto"にして実寸を取得。長い方を"56px"に再設定。そして表示。 */
	img.style.width = "auto";
	img.style.height = "auto";
	if (img.width > img.height) {
		if (img.width > 48 ) {
			img.style.width = "48px";
		}
	} else {
		if (img.height > 48 ) {
			img.style.height = "48px";
		}
	}
	img.style.visibility = "visible";
}

function PicFullOpen( picpath ) {
	if( picpath != 'http://www.s-delight.co.jp/admin/articleImages/noimage.jpg' ) {
		var url = picpath;
		w = window.open( url,'_blank','width=670,height=510,status=no,scrollbars=no,directories=no,menubar=no,resizable=yes,toolbar=no' );
	}
}

function changeImage( imageName ) {
	document.images["topImage"].src = 'http://www.s-delight.co.jp/admin/articleImages/' + imageName;
}

