/******************************************************************************
 JavaScript
 $Author: hattori $
 $Revision: 1.7 $
 $Id: script.js,v 1.7 2007/10/11 03:27:36 hattori Exp $
 ******************************************************************************/

function submitAction(fname, context, aname) {
	document.forms[fname].action = '/' + context + '/exec/' + aname;
	document.forms[fname].submit();
	return false;
}

function resetNarrowSearch() {
    for (var i = 0; i < document.forms.length; i++) {
        for (var j = 0; j < document.forms[i].elements.length; j++) {
            if (document.forms[i].elements[j].name.match(/category\[[0-9]+\]\.categoryId|pubId/i)) {
                document.forms[i].elements[j].options[0].selected = true;
            }
        }
    }
}

var sent = false;
function send() {
	if (sent) {
		return false;
	} else {
		sent = true;
		return true;
	}
}

function checkEula() {
	if (typeof(document.eulaForm.eulaCheck) != 'undefined' && !document.eulaForm.eulaCheck.checked) {
		alert(document.eulaForm.eulaMessage.value);
		return false;
	}
	return true;
}

function popupEulaView(context, bookId) {
	var eula = window.open('/' + context + '/exec/eula/view?bookId='+ bookId, 'eula', 'width=640,height=350');
}

function popupImageLargeView(context, imageLargeFileName) {
	var imageLarge = window.open('/' + context + '/exec/image/large/view?imageLargeFileName='+ imageLargeFileName, 'new', 'width=235,height=344');
}

function resizeImageLarge(width, height) {
	if (width == 0 || height == 0) {
		width = 215;
		height = 304;
	}
	width += 20;
	height += 40;
	self.resizeTo(width, height)
	// 内寸取得
	if(window.opera || document.layers) {		// n4,o6用
		var w = self.innerWidth;
		var h = self.innerHeight;
	} else if(document.all) {					// e用
		var w = self.document.body.clientWidth;
		var h = self.document.body.clientHeight;
	} else if(document.getElementById) {		// n6,n7,m1用
		var w = self.innerWidth;
		var h = self.innerHeight;
	}
	// resizeToの結果内寸が 正しければ、そのまま。
	//                      違うなら、差分を加算。
	if(width != w || height != h) {
		self.resizeBy((width - w), (height - h))
		if (document.layers)
			self.location.reload(0);			// n4はreloadでresizeバグ回避
	}
	self.focus();
}

function inputCardNumber(nNewNumber) {
	nCardNumberValue = document.cardPaymentForm.cardNumber.value;
	if(nNewNumber == 'C') {
		document.cardPaymentForm.cardNumber.value = '';
	} else if(nNewNumber == 'B') {
		document.cardPaymentForm.cardNumber.value = nCardNumberValue.substring(0,nCardNumberValue.length - 1);
	} else {
		document.cardPaymentForm.cardNumber.value = nCardNumberValue + nNewNumber;
	}
}

function showhide(id){
	if(document.getElementById){
		if(document.getElementById(id).style.display == "block"){
			document.getElementById(id).style.display = "none";
		} else {
			document.getElementById(id).style.display = "block";
		}
	}
}

function checkOs4Protect(context, token){
	//ブラウザ確認
	if (navigator.appName!="Microsoft Internet Explorer") {
		location.href="/" + context + "/exec/download/security/os/invalid";
		return;
	}
	// OS確認
	if (navigator.appVersion.indexOf("X11") > 0) {
		location.href="/" + context + "/exec/download/security/os/invalid";
		return;
	}
	if (navigator.appVersion.indexOf("Mac") > 0) {
		location.href="/" + context + "/exec/download/security/os/invalid";
		return;
	}
	location.href="/" + context + "/exec/download/security/install/decoder?org.apache.struts.taglib.html.TOKEN=" + token;
}
