/* 履歴番号　000001　2005/02/25　修正開始 */
/* 履歴番号　000002　2005/04/08　修正開始 */
/*=========================================================================
 * 関数名 OrderDateCheck
 *
 * 機能 
 *      注文日の月の月末を過ぎたら、そのアイテムに対しての
 *      個別の調整額は入力できないようにして、操作された場合は、
 *      ”全体調整額にて入力をお願いします。“とのメッセージを表示する
 *
 * 引数
 *     @1 調整額入力Textオブジェクト
 *     @2 hiddenオブジェクト(最終的にこのhiddenの値がパラメータで渡される)
 *     @3 注文日
 *     @4 システム日付
 *     @5 調整額のデフォルト値
 *
 * 戻り値
       @return true/false
===========================================================================*/
function OrderDateCheck(obj1, obj2, order_date, sys_date, value){
	
	//注文日の有無のチェック
	if( order_date != "" ){
		//日付型に変換
		//注文日の月末を算出
		var wDate = new Date(order_date);
		var cYear = wDate.getFullYear();
		var cMonth = wDate.getMonth() + 2;
		var order_comp = DateDayAdd(-1,cYear + "/" + cMonth + "/1");
		
		//システム日付のフォーマット変換
		var symd = sys_date.split("/");
		if (symd[1].length == 1){symd[1] = "0" + symd[1]};
		if (symd[2].length == 1){symd[2] = "0" + symd[2]};
		var sys_comp = symd[0] + "/" + symd[1] + "/" + symd[2];
		
		if( sys_comp > order_comp ){
			alert("全体調整額にて入力をお願いします。");
			obj1.value = value;
			return false;
		}
	}
	obj2.value = obj1.value;
		
	return true;
}
/* 履歴番号　000002　2005/04/08　修正終了 */

/*=========================================================================
 * 関数名 DateDayAdd
 *
 * 機能 
 *      日付を引数で指定された日数加算する
 *
 * 引数
 *     @1 加算する日数
 *     @2 加算対象となる日付
 *
 * 戻り値
       @return 指定された日数分加算されたYYYY/MM/DD
===========================================================================*/
function DateDayAdd(n, nDate){
	
	//YYYY[0] MM[1] DD[2]に分割
	var wymd = nDate.split("/");
	//10月未満の月は0埋め
	if (wymd[1].length == 1){wymd[1] = "0" + wymd[1]};
	if (wymd[2].length == 1){wymd[2] = "0" + wymd[2]};
	//日付型に変換
	var wDate = new Date(nDate);
	
	//加算するミリセック
	var wdaysMS = n * 1000 * 60 * 60 * 24;
	var DateMS = wDate.getTime();
	//日付を加算する
	DateMS += wdaysMS;
	wDate.setTime(DateMS);
	//年月日の取得
	var tYear = wDate.getFullYear();
	var tMonth = wDate.getMonth() + 1;
	var tDate = wDate.getDate();
	
	//10月未満の月は0埋め
	if (tMonth < 10){tMonth = "0" + tMonth};
	if (tDate < 10){tDate = "0" + tDate};
	return (tYear + "/" + tMonth + "/" + tDate);

}
/* 履歴番号　000001　2005/02/25　修正終了 */


function Popup(page, wID, width, height)
{
	nowDate = new Date();
	strPath = new String(page)
	if (page.indexOf("?") > 0)
	{
		page = page + "&Time=" + nowDate;
	}
	else
	{
		page = page + "?Time=" + nowDate;
	}
	OpenWin = this.open(page, wID, "height="+height+",width="+width+",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	OpenWin.focus();
}


function checkMailAddress2(obj) //for Address book
								//accepts empty string
{
	txt = obj.value;
	txt = txt.replace(/＠/gi, "@");
	txt = txt.replace(/．/gi, ".");
	txt = txt.replace(/＿/gi, "_");
	txt = txt.replace(/−/gi, "-");
	txt = CheckDblByteNumbers(txt);
	txt = CheckDblByteLCase(txt);
	txt = CheckDblByteUCase(txt);
	
	data = txt.match(/^\S+@\S+\.\S+$/);
	alertText = "メールアドレスが明らかに間違っています。ご確認ください。";
	if (!data){
		if (obj.value.length > 0){
		alert(alertText);
		obj.value = "";
		obj.focus();
		}
	}
		obj.value = txt;
}


function checkCardNumber(obj) //accepts empty string
{
	txt = obj.value;
	txt = CheckDblByteNumbers(txt)
	
	//data = txt.match(/^\(?\d+\)?\-?\d+\-?\d+$/);
	  data = txt.match(/^\(?\d+\)?\-?\d+$/);
	alertText = "クレジットカード番号は、数字のみを受付けます。";
	alertText2 = "番号を確認してください"; // no use currently
	if (!data){
		if (obj.value.length > 0){
		alert(alertText);
		obj.value = "";
		obj.focus();
		}
	}
//	else{
//		if(txt.length<10){
//			alert(alertText2);
//			obj.value = "";
//			obj.focus();		
//		}
		obj.value=txt;
	}

function checkCardOwner(obj) //accepts empty string
{
	txt = obj.value;
	txt = CheckDblByteNumbers(txt)
	
	data = txt.match(/^[\w\s]+$/);
	alertText = "カード名義は、半角英数字でご入力ください。";
	alertText2 = "文字数が制限を越えています．内容をご確認ください．"; // no use currently
	if (!data){
		if (obj.value.length > 0){
		alert(alertText);
		obj.value = "";
		obj.focus();
		}
	}
	else{
		if(txt.length > 120){
			alert(alertText2);
			obj.value = "";
			obj.focus();		
		}
		obj.value=txt;
	}
}

function CheckDblByteNumbers(str){
// replace dbl byte numbers to single byte numbers
	txt = str;
	rExp = /１/gi;
	txt = txt.replace(rExp, "1");
	rExp = /２/gi;
	txt = txt.replace(rExp, "2");
	rExp = /３/gi;
	txt = txt.replace(rExp, "3");
	rExp = /４/gi;
	txt = txt.replace(rExp, "4");
	rExp = /５/gi;
	txt = txt.replace(rExp, "5");
	rExp = /６/gi;
	txt = txt.replace(rExp, "6");
	rExp = /７/gi;
	txt = txt.replace(rExp, "7");
	rExp = /８/gi;
	txt = txt.replace(rExp, "8");
	rExp = /９/gi;
	txt = txt.replace(rExp, "9");
	rExp = /０/gi;
	txt = txt.replace(rExp, "0");
	return txt;
}

function CheckDblByteLCase(str){
// replace dbl byte numbers to single byte numbers
	txt = str;
	rExp = /ａ/gi;
	txt = txt.replace(rExp, "a");
	rExp = /ｂ/gi;
	txt = txt.replace(rExp, "b");
	rExp = /ｃ/gi;
	txt = txt.replace(rExp, "c");
	rExp = /ｄ/gi;
	txt = txt.replace(rExp, "d");
	rExp = /ｅ/gi;
	txt = txt.replace(rExp, "e");
	rExp = /ｆ/gi;
	txt = txt.replace(rExp, "f");
	rExp = /ｇ/gi;
	txt = txt.replace(rExp, "g");
	rExp = /ｈ/gi;
	txt = txt.replace(rExp, "h");
	rExp = /ｉ/gi;
	txt = txt.replace(rExp, "i");
	rExp = /ｊ/gi;
	txt = txt.replace(rExp, "j");
	rExp = /ｋ/gi;
	txt = txt.replace(rExp, "k");
	rExp = /ｌ/gi;
	txt = txt.replace(rExp, "l");
	rExp = /ｍ/gi;
	txt = txt.replace(rExp, "m");
	rExp = /ｎ/gi;
	txt = txt.replace(rExp, "n");
	rExp = /ｏ/gi;
	txt = txt.replace(rExp, "o");
	rExp = /ｐ/gi;
	txt = txt.replace(rExp, "p");
	rExp = /ｑ/gi;
	txt = txt.replace(rExp, "q");
	rExp = /ｒ/gi;
	txt = txt.replace(rExp, "r");
	rExp = /ｓ/gi;
	txt = txt.replace(rExp, "s");
	rExp = /ｔ/gi;
	txt = txt.replace(rExp, "t");
	rExp = /ｕ/gi;
	txt = txt.replace(rExp, "u");
	rExp = /ｖ/gi;
	txt = txt.replace(rExp, "v");
	rExp = /ｗ/gi;
	txt = txt.replace(rExp, "w");
	rExp = /ｘ/gi;
	txt = txt.replace(rExp, "x");
	rExp = /ｙ/gi;
	txt = txt.replace(rExp, "y");
	rExp = /ｚ/gi;
	txt = txt.replace(rExp, "z");
	return txt;
}

function CheckDblByteUCase(str){
// replace dbl byte numbers to single byte numbers
	txt = str;
	rExp = /Ａ/gi;
	txt = txt.replace(rExp, "A");
	rExp = /Ｂ/gi;
	txt = txt.replace(rExp, "B");
	rExp = /Ｃ/gi;
	txt = txt.replace(rExp, "C");
	rExp = /Ｄ/gi;
	txt = txt.replace(rExp, "D");
	rExp = /Ｅ/gi;
	txt = txt.replace(rExp, "E");
	rExp = /Ｆ/gi;
	txt = txt.replace(rExp, "F");
	rExp = /Ｇ/gi;
	txt = txt.replace(rExp, "G");
	rExp = /Ｈ/gi;
	txt = txt.replace(rExp, "H");
	rExp = /Ｉ/gi;
	txt = txt.replace(rExp, "I");
	rExp = /Ｊ/gi;
	txt = txt.replace(rExp, "J");
	rExp = /Ｋ/gi;
	txt = txt.replace(rExp, "K");
	rExp = /Ｌ/gi;
	txt = txt.replace(rExp, "L");
	rExp = /Ｍ/gi;
	txt = txt.replace(rExp, "M");
	rExp = /Ｎ/gi;
	txt = txt.replace(rExp, "N");
	rExp = /Ｏ/gi;
	txt = txt.replace(rExp, "O");
	rExp = /Ｐ/gi;
	txt = txt.replace(rExp, "P");
	rExp = /Ｑ/gi;
	txt = txt.replace(rExp, "Q");
	rExp = /Ｒ/gi;
	txt = txt.replace(rExp, "R");
	rExp = /Ｓ/gi;
	txt = txt.replace(rExp, "S");
	rExp = /Ｔ/gi;
	txt = txt.replace(rExp, "T");
	rExp = /Ｕ/gi;
	txt = txt.replace(rExp, "U");
	rExp = /Ｖ/gi;
	txt = txt.replace(rExp, "V");
	rExp = /Ｗ/gi;
	txt = txt.replace(rExp, "W");
	rExp = /Ｘ/gi;
	txt = txt.replace(rExp, "X");
	rExp = /Ｙ/gi;
	txt = txt.replace(rExp, "Y");
	rExp = /Ｚ/gi;
	txt = txt.replace(rExp, "Z");
	return txt;
}

function CheckDeleteContents(strURL){
	ans = confirm("削除してよろしいですか？");
	if (ans == true) {
		location.href=strURL;
	} else {
		
	}
}

function CheckNoShowContents(strURL){
	ans = confirm("非表示にしてよろしいですか？");
	if (ans == true) {
		location.href=strURL;
	} else {
		
	}
}

function bytecheck(obj,num)
{
	var bytes=0
	for(i=0;i<obj.value.length;i++)
	{
		bytes+=((obj.value.charAt(i)>="｡"&&obj.value.charAt(i)<="ﾟ")?1:(escape(obj.value.charAt(i)).length>3?2:1))
	}
	if(bytes>num)
	{
		alert("制限文字数を超えています。 ("+bytes+"/"+num+" bytes)")
		obj.focus()
	}
}

function bytecheck2(obj,num, inputName)
{
	var bytes=0
	for(i=0;i<obj.value.length;i++)
	{
		bytes+=((obj.value.charAt(i)>="｡"&&obj.value.charAt(i)<="ﾟ")?1:(escape(obj.value.charAt(i)).length>3?2:1))
	}
	if(bytes>num)
	{
		alert(inputName + "が長すぎます。"+num +"文字以内で入力してください。")
		obj.focus()
	}
}

function bytecheck3(obj,num, inputName)
{
	var bytes=0
	for(i=0;i<obj.value.length;i++)
	{
		bytes+=((obj.value.charAt(i)>="｡"&&obj.value.charAt(i)<="ﾟ")?1:(escape(obj.value.charAt(i)).length>3?2:1))
	}
	if(bytes>num)
	{
		alert(inputName + "が長すぎます。半角"+num +"文字以内で入力してください。")
		obj.focus()
	}
}

function bytecheck_PW(obj,num)
{
	var bytes=0
	for(i=0;i<obj.value.length;i++)
	{
		bytes+=((obj.value.charAt(i)>="｡"&&obj.value.charAt(i)<="ﾟ")?1:(escape(obj.value.charAt(i)).length>3?2:1))
	}
	if(bytes>num)
	{
		alert("パスワードは最大50文字までにしてください。")
		obj.focus()
	}
}

function CheckCloseContents(strURL){
	ans = confirm("以降、このデータの変更はできません。\nこのデータは本日夜間自動的に出版社に送信されます。\nよろしいですか？");
	if (ans == true) {
		location.href=strURL;
	} else {
		
	}
}

function CheckItemCount(obj){
		num = parseInt(obj.value);
		if(num <= 0 || num >= 1000){
			alert("1〜999の間で指定してください。");
			obj.focus();
		}
}

function checkCountNum(obj) //replace DblByte Numbers
{
	txt = obj.value;
	txt = CheckDblByteNumbers(txt)
	data = txt.match(/^[0123456789]+$/);
	alertText = "数字で入力してください。";
	if (!data){
		if (obj.value.length > 0){
		alert(alertText);
		obj.value = "";
		obj.focus();
		}
	}
	else{
		obj.value=txt;
	}
}

function CheckItemCountblnk(obj){
		if (obj.value.length < 1){
		alert("口数を入力してください。");
			obj.focus();
		}
}

function wc(text, outputName, num){
	var display=document.getElementById(outputName);
	display.innerHTML=""+text.length+"文字/最大" + num + "文字"

}
function checkMaxLength(obj, num){
	txt = obj.value;
	if(txt.length > num) {
    /* 入力文字数が最大文字数を超えている場合 */
    alert(num + '文字以内で入力してください。');
  	return false;
  	}
}

function wordCountCheck(obj,num, inputName)
{
	var bytes=0
	for(i=0;i<obj.value.length;i++)
	{
		bytes+=((obj.value.charAt(i)>="｡"&&obj.value.charAt(i)<="ﾟ")?1:(escape(obj.value.charAt(i)).length>3?2:1))
	}
	if(bytes>num)
	{
		alert(inputName + "は全角" + num/2 + "文字以内、半角"+ num + "文字以内で入力してください。")
		obj.focus()
	}
}
//

