/*
*
* Decodahlia Web Shop  
*
*/
//
var NPPayMax = 52300 ;	//52500 - 200
var IligualPayTypeDaiBiki = -1 ;
//
var TransSelect = 0 ;
var PaySelect = 0 ;
/**/
function Init_PayTypeArrayList() {
 var PayTypeList = new Array() ;
//
	PayTypeList[PayTypeList.length] = new Array( 6, 7, 13, 15, 17, 34, 23, 26, 27, 28) ; //宅急便
	PayTypeList[PayTypeList.length] = new Array(10, 9,  5,  1,  3, 35, -1, -1, -1, -1) ; //メール便
	PayTypeList[PayTypeList.length] = new Array(11, 8, 12, 14, 16, 36, -1, -1, -1, -1) ; //メール速達便
//
//---------- End of List ----------
return PayTypeList ;
}
/**/
function initialShoppingSelect() {
//
	var payval ;
//
	TransSelect = 0 ;
	PaySelect = 0 ;
//
	payval = GetCookieValue() ;
	if (payval) {
		document.form1.payment_id[TransSelect].checked = true ;
		if (!document.form1.payselect[PaySelect].disabled) {
			document.form1.payselect[PaySelect].checked = true ;
		}
	}
//	window.alert(TransSelect) ;
//	window.alert(PaySelect) ;
//
}
/**/
function shoppingTransSelect(val) {
	TransSelect = val ;
	SetCookie() ;
//
	refreshShoppingFrame(true) ;
}
/**/
function shoppingPaySelect(val) {
	PaySelect = val ;
	SetCookie() ;
//	window.alert(TransSelect) ;
//
	refreshShoppingFrame(true) ;
//
}
/**/
function shoppingSelectChk() {
 var paylist = Init_PayTypeArrayList() ;
 var payid ;
//
	payid = 0 ;
	do {
		if (document.form1.payselect[payid].checked) {
			break ;
		}
		payid++ ;
	} while (payid < document.form1.payselect.length) ;
//
	if (!document.form1.payment_id[TransSelect].checked) {
		window.alert("配送方法が、指定されていません。") ;
		return false ;
	}
	if (PaySelect != payid) {
		window.alert("支払い方法が、指定されていません。") ;
		return false ;
	}
//
	payid = paylist[TransSelect][PaySelect] ;
	if (payid == IligualPayTypeDaiBiki) {
		window.alert("代金引換の場合、メール便，メール速達便の\n御指定は出来ません。") ;
		return false ;
	}
//	
//	var selectindex = document.form1.deliveryHopeTime.selectedIndex ;
//	selectvalue = document.form1.deliveryHopeTime.options[selectindex].value ;
//	a = ""+selectindex ;
//	window.alert(a) ;
//
	if (TransSelect != 0 && document.form1.deliv_date.selectedIndex != 0) {
		window.alert("メール便，メール速達便の場合、お届け日の\n御指定は出来ません。") ;
		return false ;
	}
	if (TransSelect != 0 && document.form1.deliveryHopeTime.selectedIndex != 0) {
		window.alert("メール便，メール速達便の場合、お届け時間の\n御指定は出来ません。") ;
		return false ;
	}
	refreshShoppingFrame(false) ;
	return true ;
//
}
function shoppingPointChk() {
//
	var element1 ;
	var element2 ;
//
	element1 = document.getElementById("point_off") ;
	if (element1.value == 3) {
		return true ;
	}
	if(!document.form1['point_check'][0].checked) {
		return true ;
	}
    element1 = document.getElementById("user_point") ;
    element2 = document.getElementById("use_point") ;
	if (!isNumeric(element2.value)) {
		window.alert("御利用ポイントは、0-9の数値を入力して下さい。") ;
		return false ;
	}
	if (element1.innerText >= Math.abs(element2.value)) {
		return true ;
	}
	window.alert("御利用ポイントが、所持ポイントを超えています。") ;
	return false ;
//
}	
//
// Replacement "payment.tpl" innner Function's
//
function refreshShoppingFrame(true_) {
//
 var paylist = Init_PayTypeArrayList() ;
 var payid ;
 var element ;
//	
	payid = paylist[TransSelect][PaySelect] ;
    element = document.getElementById("setpayment" + TransSelect) ;
	element.value = payid ;
//
	if (true_) {
		document.form1['mode'].value = 'payment' ;
		document.form1.submit() ;
	}
//
}
//
function chgShopImgImageSubmit(fileName,imgObj) {
//
	if (shoppingPointChk()) {
		if (shoppingSelectChk()) {
			return ;
		}
	}
	var element = document.getElementById("setpayment" + TransSelect) ;
	element.name = "nonepayment" ;
	document.form1.submit() ;
//
}
//
// Extention Prc. "confim.tpl" innner Function's
//
function setConfimTransType() {
//
 var payval ;
 var transtype ;
//
	payval = GetCookieValue() ;
	if (!payval) rerturn ;
	switch (TransSelect) {
		case 0 : transtype = "宅急便" ; break ;
		case 1 : transtype = "メール便" ; break ;
		case 2 : transtype = "メール便 速達" ; break ;
		default : return ;
	}
	ChgMessage("confim_transtype",transtype) ;
//
}
//
//------------------------------------------------
//
function ChgMessage(MsgID,msg_) {
//
    var msg = document.getElementById(MsgID);
	msg.innerHTML = msg_ ;
//
}
function ChgLinkURL(AnchorID,url_) {
	//
    var anchor = document.getElementById(AnchorID) ;
	anchor.href = url_ ;
	//
}
function GetCookieValue() {
//
	var cookieval ;
	var wk ;	
    var allcookies = document.cookie ;
    if (allcookies == "") return false ;
//
    var pos = allcookies.indexOf("DecodahliaWebShopLngType=") ;
    if (pos == -1) return false ;
//
    var start = pos + 25 ;
    var end   = allcookies.indexOf(";",start) ;
    if (end == -1) end = allcookies.length ;
    var value = allcookies.substring(start,end) ;
	cookieval = decodeURIComponent(value) ;
//
	wk = cookieval / 100 ;
	TransSelect = Math.floor(wk) ;
	if (TransSelect > 2)
		TransSelect = Math.floor(TransSelect / 10) ;
    PaySelect = cookieval % 100 ;
//
	return true ;
//
}
//
function SetCookie() {
//
    var cookieval ;
    var cookiestr ;
//
	cookieval = TransSelect * 100 + PaySelect ;
    cookiestr = "DecodahliaWebShopLngType=" + encodeURIComponent(cookieval) +"; path=/" ;
    document.cookie = cookiestr ;
//
}
function isNumeric(num) {
    if (num.match(/[^0-9]/g)) {
        return false ;
    }
    return true ;
}
/*
ブラウザ名 : navigator.appName);
ブラウザのコード名 : navigator.appCodeName);
ブラウザのバージョン : navigator.appVersion);
ブラウザの使用言語 : navigator.browserLanguage
Cookiesは有効か？ : navigator.cookieEnabled 
ユーザーのOS : navigator.platform
ユーザーのOSのデフォルト言語 : navigator.systemLanguage
ユーザー使用言語 : navigator.language
ユーザーエージェントのヘッダ文字列 : navigator.userAgent
ユーザーのOS言語 : navigator.userLanguage
*///
//
function IsBrowser() {
//
var strUA = navigator.userAgent.toLowerCase() ;
//AppleWebKit
if(strUA.indexOf("iphone") != -1){
return(0) ;
}else if(strUA.indexOf("ipad") != -1){
return(1) ;
}else if(strUA.indexOf("safari") != -1){
return(2) ;
}else if(strUA.indexOf("firefox") != -1){
return(3) ;
}else if(strUA.indexOf("opera") != -1){
return(4) ;
}else if(strUA.indexOf("netscape") != -1){
return(5) ;
}else if(strUA.indexOf("msie") != -1){
return(6) ;    // Hate!!
}else if(strUA.indexOf("mozilla/4") != -1){
return(7) ;
}
return(-1) ;       // None
}


