/* --------------------------------------------------
	SiteName : AHINEI AD
	FileName : default.js
	Description : common scripts
-------------------------------------------------- */

function popUp(url){
sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=1, scrollbars=1,resizable=1,width=507,height=450');
self.name = "mainWin";
}

function windowOpen(URL,target,ww,wh,wresize,wcenter,wscroll){
	var subWin;
	if ( document.all || document.layers || document.getElementById ){
		scW = screen.availWidth / 2;
		scH = screen.availHeight / 2;
	}
	else {
		wcenter = 0;	
	}	
	if ( wcenter == 1 ){
		woption = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=" + wresize + ",width=" + ww + ",height=" + wh + ",left=" + (scW - (ww / 2)) + ",top=" + (scH - (wh / 2));
	}
	else {
		woption = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=" + wresize + ",width=" + ww + ",height=" + wh;
	}
	subWin = window.open(URL,target,woption);
	subWin.focus();
}
// ポップアップウインドウ2
function windowOpen2(URL,target,ww,wh,wresize,wcenter,wscroll){
	var subWin;
	if ( document.all || document.layers || document.getElementById ){
		scW = screen.availWidth / 2;
		scH = screen.availHeight / 2;
	}
	else {
		wcenter = 0;	
	}	
	if ( wcenter == 1 ){
		woption = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=" + wresize + ",width=" + ww + ",height=" + wh + ",left=" + (scW - (ww / 2)) + ",top=" + (scH - (wh / 2));
	}
	else {
		woption = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=" + wresize + ",width=" + ww + ",height=" + wh;
	}
	subWin = window.open(URL,target,woption);
	subWin.focus();
}

function radioChange() {
	if(document.form1.nouhin[0].checked == true) {
	document.form1.delivery1.disabled = false;
	document.form1.delivery2.disabled = true;
	document.form1.delivery1.style.backgroundColor='#FFFFFF';
	document.form1.delivery2.style.backgroundColor='#EEEEEE';
	}else if(document.form1.nouhin[1].checked == true) {
	document.form1.delivery1.disabled = true;
	document.form1.delivery2.disabled = false;
	document.form1.delivery1.style.backgroundColor='#EEEEEE';
	document.form1.delivery2.style.backgroundColor='#FFFFFF';
	}else {
	document.form1.delivery1.disabled = false;
	document.form1.delivery2.disabled = false;
	document.form1.delivery1.style.backgroundColor='#EEEEEE';
	document.form1.delivery2.style.backgroundColor='#EEEEEE';
}
}

function Rollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_ov."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_ov.", "_off."));
				}
			}
		}
	}
}
if(window.addEventListener) {
	window.addEventListener("load", Rollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", Rollover);
}

(function(){
  function rollover(){
    var targetClassName = "hoverImg";//指定するクラス名
    var suffix = "_ov";//ファイル名の後ろにつけるやつ（rollover後のファイル）

    var overReg = new RegExp("^(.+)(\\.[a-z]+)$");
    var outReg = new RegExp("^(.+)" + suffix + "(\\.[a-z]+)$");

    var preload = new Array();
    var images = document.images;
    var inputs = document.getElementsByTagName("input");

    for (var i = 0, il = images.length; i < il; i++) {
      var classStr = images[i].getAttribute("class") || images[i].className;
      var classNames = classStr.split(/\s+/);
      for(var j = 0, cl = classNames.length; j < cl; j++){
        if(classNames[j] == targetClassName){

          //preload
          preload[i] = new Image();
          preload[i].src = images[i].getAttribute("src").replace(overReg, "$1" + suffix + "$2");

          //mouseover
          images[i].onmouseover = function() {
            this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
          }

          //mouseout
          images[i].onmouseout = function() {
            this.src = this.getAttribute("src").replace(outReg, "$1$2");
          }
        }
      }
    }
    
    for (var v = 0, vl = inputs.length; v < vl; v++){
      var classStr = inputs[v].getAttribute("class") || inputs[v].className;
      var classNames = classStr.split(/\s+/);
      for(var j = 0, cl = classNames.length; j < cl; j++){
        if(classNames[j] == targetClassName){
          //preload
          preload[v] = new Image();
          preload[v].src = inputs[v].getAttribute("src").replace(overReg, "$1" + suffix + "$2");
    
          //mouseover
          inputs[v].onmouseover = function() {
            this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
          }
    
          //mouseout
          inputs[v].onmouseout = function() {
            this.src = this.getAttribute("src").replace(outReg, "$1$2");
          }
        }
      }
    }
  }

  function addEvent(elem,event,func){
    if(elem.addEventListener) {
      elem.addEventListener(event, func, false);
    }else if(elem.attachEvent) {
      elem.attachEvent("on" + event, func);
    }
  }
  addEvent(window,"load",rollover);
})();


function popOpen(form,ww,wh) { 
w=window.open("", "pop"+form.name,"resizable=yes,width=" + ww + ",height=" + wh + ",scrollbars=yes");
w.focus();
form.target = "pop"+form.name ;
form.method = "POST" ;
form.submit() ;
}


new function(){
	if(window.opera || navigator.userAgent.indexOf("Firefox") != -1){
		var wordBreak = function() {
			var wordBreakClass = "wordBreak";
			var table = document.getElementsByTagName("table");
			for(var i=0,len=table.length ; i<len ; i++){
				var tbClass = table[i].className.split(/\s+/);
				for (var j = 0; j < tbClass.length; j++) {
					if (tbClass[j] == wordBreakClass) {
						recursiveParse(table[i])
					}
				}
			}
		}
		var recursiveParse = function(pNode) {
			var childs = pNode.childNodes;
			for (var i = 0; i < childs.length; i++) {
				var cNode = childs[i];
				if (childs[i].nodeType == 1) {
					recursiveParse(childs[i]);
				}else if(cNode.nodeType == 3) {
					if(cNode.nodeValue.match("[^\n ]")){
						var plTxt = cNode.nodeValue.replace(/\t/g,"")
						var spTxt = plTxt.split("");
						spTxt = spTxt.join(String.fromCharCode(8203));
						var chNode = document.createTextNode(spTxt);
						cNode.parentNode.replaceChild(chNode,cNode)
					}
				}
			}
		}

	}else{
		var wordBreak = function() {
			if( document.styleSheets[0].addRule ){
				document.styleSheets[0].addRule(".wordBreak","word-break:break-all");
			}else if( document.styleSheets[0].insertRule ){
				document.styleSheets[0].insertRule(".wordBreak{word-break:break-all}", document.styleSheets[0].cssRules.length );
			}else{
				return false;
			}
		}
	}
	var addEvent = function(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",wordBreak);
}
