/*

information{
	ファイル名 : /js/common.css;
	概要: このJSファイルは、ページ共通部分で使用される変数・関数が定義してあります。;
	サイト名 : クーポンメール;
	URL : http://www.couponmail.jp/;
	コピーライト : Copyright (C) 2006 REALUS Inc. All Rights Reserved.;
}

 */


/* index
------------------------------------

	1.ナビゲーション
	2.文字可変
	3.ポップアップウィンドウ
	4.折りたたみ
	5.お問い合わせフォームのエラー
	6.Flash埋め込み
	7.スクロールスムーズ

----------------------------------*/



/* 1.ナビゲーション
----------------------------------------------------------------------　*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
	}
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
  }
}



/* 2.文字可変
----------------------------------------------------------------------　*/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title)
        a.disabled = false;
    }
  }
  createCookie("style", title, 365);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
      return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);



/* 3.ポップアップウィンドウ
----------------------------------------------------------------------　*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



/* 4.折りたたみ
----------------------------------------------------------------------　*/

function getObjById( idName ){
	if ( document.getElementById ) { //N6,Moz,IE5,IE6
		return document.getElementById( idName )
	} else if ( document.all ) { //IE4
		return document.all( idName )
	}
}


function dd(obj){
	new Image().src = "images/top/txt_minus.gif";
	op = "images/coupon/special/icon_more.gif";
	cl = "images/coupon/special/icon_more.gif";
	OBJ1 = getObjById( obj ).style;
	IMG1 = getObjById( obj + "i" );
	if ( OBJ1 && IMG1 ) {
		OBJ1.display = ( OBJ1.display == 'none' ) ? '' : 'none';
		IMG1.src = ( IMG1.src.indexOf( 'txt_plus' ) > 0 ) ? op : cl;
	}
}



/* 5.お問い合わせフォームのエラー
----------------------------------------------------------------------　*/

function check(){
	var iCount;
	var iCode;
	st_val=document.f1.namekana.value;

	for (iCount=0 ; iCount<st_val.length ; iCount++){
    	iCode = st_val.charCodeAt(iCount);
      	if ((12449<= iCode && iCode <= 12542)){
			return;
	}
    	}
	alert("氏名（カナ）をご入力ください（必須項目です）");
	return(false);
}
function chk_form() {
/*	if ( document.f1.namekana.value == "" ) {
		alert ( "氏名（カナ）をご入力ください（必須項目です）" );
		document.f1.namekana.focus();
		return(false);
	}else{
		check()	
	}*/
	if ( document.f1.name.value == "" ) {
		alert ( "氏名をご入力ください（必須項目です）" );
		document.f1.name.focus();
		return(false);
	}
	if ( document.f1.mail.value == "" ) {
		alert ( "PCメールアドレスをご入力ください（必須項目です）" );
		document.f1.mail.focus();
		return(false);
	}
	if ( document.f1.what.value == "" ) {
		alert ( "何に関するお問い合わせかをご入力ください（必須項目です）" );
		document.f1.what.focus();
		return(false);
	}
	if ( document.f1.question.value == "" ) {
		alert ( "具体的なお問い合わせ内容をご入力ください（必須項目です）" );
		document.f1.question.focus();
		return(false);
	}
	if ( document.f1.mail.value.indexOf( "@", 0 ) <= 0 ) {
		alert ( "正しいメールアドレスを入力して下さい（必須項目です）" );
		document.f1.mail.focus();
		return(false);
	}
	return(true);
}



/* 6.Flash埋め込み
----------------------------------------------------------------------　*/

function swf_embed (url,width,height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" />\n');
	document.write('<param name="movie" value="'+url+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="menu" value="false" />');
	document.write('<embed src="'+url+'" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>\n');
	document.write('</object>\n');
}



/* 7.スクロールスムーズ
----------------------------------------------------------------------　
Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;
	speed:10,

	// returns the Y position of the div
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	// returns the current scroll position
	scrollTop: function (){
		body=document.body
	    d=document.documentElement
	    if (body && body.scrollTop) return body.scrollTop
	    if (d && d.scrollTop) return d.scrollTop
	    if (window.pageYOffset) return window.pageYOffset
	    return 0
	},

	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
	    if (event.addEventListener) return event.addEventListener(body, d,false)
	    if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
      		return;
    	}
	    if (e.preventDefault && e.stopPropagation) {
	      e.preventDefault()
	      e.stopPropagation()
	    }
	},
	
	// move the scroll bar to the particular div.
	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/Scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/Scroller.speed)
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
	  	Scroller.offsetTop=a
	},
	// initializer that adds the renderer to the onload function of the window
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	// this method extracts all the anchors and validates then as # and attaches the events.
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
	    for (i=0;i<a.length;i++) {
	      l = a[i];
	      if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
	      	Scroller.add(l,'click',Scroller.end)
	      		l.onclick = function(){
	      			Scroller.end(this);
		        	l=this.hash.substr(1);
		        	 a = document.getElementsByTagName('a');
				     for (i=0;i<a.length;i++) {
				     	if(a[i].name == l){
				     		clearInterval(Scroller.interval);
				     		Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
						}
					}
				}
	      	}
		}
	}
}
// invoke the initializer of the scroller
Scroller.init();
*/