// JavaScript Document
// JavaScript Document
h=screen.height;
w=screen.width;
		
function openDialog(url,ht,wd,name) 
{
		
			l = (w) ? (w-wd)/2 : 0;
			t = (h) ? (h-ht)/2 : 0;
			window.open(url,name,'screenx=0,screeny=0,width='+wd+',height='+ht+',top='+t+',left='+l+',scrollbars=no,menubar=no,titlebar=no,toolbar=no,resizable=no');
			
}

function resizeWindow(wd,ht)
{
	window.resizeTo(wd,ht);
	/*try
	{
		window.innerHeight = ht;
		window.innerWidth = wd;
	}
	catch(e)
	{
	}*/
}

function windowPositionHandler(wd,ht)
{
	resizeWindow(wd,ht);
	
	var tarx = (w - wd)/2;
	var tary = (h - ht)/2;
	if(tarx<1)tarx = 1;
	if(tary<1)tary = 1;
	window.moveTo(tarx,tary);
}
function Submit(URL)
{
	document.main.action = URL;
	document.main.submit();
}

function SubmitFN(fname,URL)
{
		
	var fobj = eval('document.' + fname);
	if(fobj==null)alert("obj is null");
	
	fobj.action = URL;
	
	fobj.submit();
	
}
function do_login(URL)
{
	if(document.lform.usrid.value!="" && document.lform.psid.value!="")
	{
		document.lform.lreq.value = "do_login";
		SubmitFN("lform",URL);
	}
	else
	{
		alert("ユーザーIDとパスワードを入力してください");
		document.lform.usrid.focus();
	}
}

function isValidEmail(email)
{
	regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if(regex.test(email))
	{
		return true;
	}
	
	return false;
}
function validate_required(field,alerttxt)
{
	if(field==null)return false;
	with (field)
	{
	 if (value==null||value=="")
	  {
		alert(alerttxt);
		return false;
	  }
	}
	return true;
}
function check_cnt(tarname)
{
	var ret = 0;
	for(var ii=0;;ii++)
	{
		try
		{
			var chklist = document.getElementById(tarname+ii);
			if(chklist.checked)ret++;
		}catch(e)
		{
			break;
		}
	}
	return ret;
	
}

function check_all(obj,tarname)
{
	
	var value = false;
	if(obj.checked)
	{
		value = true;
	}
	for(var ii=0;;ii++)
	{
		try
		{
			var chklist = document.getElementById(tarname+ii);
			chklist.checked = value;
		}catch(e)
		{
			break;
		}
	}
	
}

function moji_chk(value) {
for (var i = 0; i < value.length; ++i) {
		var c = value.charCodeAt(i);
		if (c >= 0xff61 && c <= 0xff9f){ return false; }
		if ( (c >= 0x30a1 && c <= 0x30f6) || (c==0x30fc)) { return false; }
		if ( c > 255  &&  ( c < 0x30a1 || c > 0x30f6) && c!=0x30fc ) { return false; }
}
return true; 
}

function integer_chk(value)
{
	value = trim(value);
	for(var i=0;i<value.length;i++)
	{
		var c = value.charCodeAt(i);
		if(!(c>=0x30 && c<=0x39))
		{
			if(i==0)
			{
				if(c!=0x2b && c!=0x2d)
				{
					return false;
				}
			}
			else return false;
		}
		
	}
	
	return true;
}


 // Removes leading whitespaces
function LTrim( value ) {
  	
  	var re = /\s*((\S+\s*)*)/;
  	return value.replace(re, "$1");
  	
  }
  
 // Removes ending whitespaces
  function RTrim( value ) {
   	
   	var re = /((\s*\S+)*)\s*/;
  	return value.replace(re, "$1");
  	
  }
  
  // Removes leading and ending whitespaces
  function trim( value ) {
  	
  	return LTrim(RTrim(value));
  	
}


//Function for Window Popup
function winopen(url,ht) 
{
			var h=screen.height;
			var w=screen.width;
			var l;
			var t;
			var ht;
			
			l = (w) ? (w-550)/2 : 0;
			t = (h) ? (h-ht)/2 : 0;
			window.open(url,'','screenx=0,screeny=0,width=550,height='+ht+',top='+t+',left='+l+',scrollbars=no,menubar=no,titlebar=no,toolbar=no,resizable=no')
}
//Code to use in Link : javascript:winopen('<FileName>',Height)//

function isRequired(obj,txt)
{
		if(obj==null || obj.value==null || obj.value=="")
		{
			alert(txt);
			return false;
		}
		return true;
}


function checkMedia(imagePath,cid,msg) 
{
		
   var pathLength = imagePath.length;
   var lastDot = imagePath.lastIndexOf(".");
   var fileType = imagePath.substring(lastDot,pathLength);

   if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".jpeg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG") || (fileType == "") || (fileType == ".mp3") || (fileType == ".flv")) 
	{
 		return true;
	} 
	else 
	{
		alert(msg);
		document.getElementById(cid).value = "";
		document.getElementById(cid).focus();
		return false;
	}
}

function checkImage(imagePath,cid,msg) 
{
		
   var pathLength = imagePath.length;
   var lastDot = imagePath.lastIndexOf(".");
   var fileType = imagePath.substring(lastDot,pathLength);

   if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".jpeg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")|| (fileType == "") ) 
	{
 		return true;
	} 
	else 
	{
		alert(msg);
		document.getElementById(cid).value = "";
		document.getElementById(cid).focus();
		return false;
	}
}
function getXMLHttp()
{
		
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
		  alert("現在のブラウザーでAJAXを有効なってないです!");
		  return false;
		  }
		}
	  }
	 
	  return xmlHttp;
 }
 function refimg()
{
	  var t = 120 // interval in seconds
      image = "../site/verifyimg.php" //name of the image
	  tmp = new Date();
	  tmp = "?"+tmp.getTime()
	  document.images["valiimg"].src = image+tmp
	  setTimeout("refimg()", t*1000) 
	  document.getElementById("imgverify").value="";
	  document.getElementById("imgvalicheck").innerHTML="";

}

function subscribe()
{
	
	var checkid = document.getElementById('mailaddr').value;
	
	if(valmailid(checkid))
	{
		
		document.getElementById('NLreq').value = "do_subscribe";
		//alert(document.getElementById('NLreq').value);
		
		SubmitFN('news_letter','index.php');
	}
}

function unsubscribe()
{
	
	var checkid = document.getElementById('mailaddr').value;
	
	if(valmailid(checkid))
	{
		 document.getElementById('NLreq').value = "do_unsubscribe";
		 
		SubmitFN('news_letter','index.php');
	}
}
function valmailid(mailid) 
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  if(regex.test(mailid) == false || mailid == "")
  {

	document.getElementById("newsletter_msgs").style.color = "#FF0000";
	document.getElementById("newsletter_msgs").innerHTML = "入力されたメールＩＤは正しくでわありません";
	ShowNLMSGS();
	return false;
  }  
  else
  {
  	return true;
  }
}
function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	}
	return true;
}
function NumberKey(evt)
{
	evt.value=evt.value.replace(/([^0-9])/g,"");
}

function isValidUserId(fld) {
    var ret =true;
	var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
   
    if (fld.value==null || fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "ユーザIDは未入力\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "ユーザーIDとして6～15半角文字を入力してください\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "ユーザーIDは違法文字を含んでいます。\n";
    } else {
        fld.style.background = 'White';
    }
	if(error!="")
	{
		alert(error);
		ret = false;
		
	}
    return ret;
}
function compare_email(str,cid,msg) 
{
	var eid=document.getElementById("email").value;	
	if(str=="")
	{
		if(eid=="")
		{
			document.getElementById("eidcomp").innerHTML = "";
			return true;
		}
		else return false;
	}
	if(str==eid)
	{
		//isValidEmail(str);
		if(document.getElementById(cid).value != "")
		{
			document.getElementById("eidcomp").innerHTML = "";
			return true;
		}
	}
	else
	{
		document.getElementById("eidcomp").innerHTML = msg;
		//document.getElementById(cid).value = "";
		//document.getElementById(cid).focus();
		return false;
	}
}
function compare_psw(str,cid,msg) 
{
	
	var eid=document.getElementById("passwd").value;
	if(str=="")
	{
		if(eid=="")
		{
			document.getElementById("passcomp").innerHTML = "";
			return true;
		}
		else return false;
	}
	if(str==eid)
	{
		document.getElementById("passcomp").innerHTML = "";
		return true;
	}
	else
	{
		document.getElementById("passcomp").innerHTML = msg;
		//document.getElementById(cid).value = "";
		//document.getElementById(cid).focus();
		return false;
	}
}
function stopresize()
{
	try
	{
		window.innerHeight = 650;
		window.innerWidth = 910;
	}
	catch(e)
	{
	}
	var tarx = (w - 910)/2;
	var tary = (h - 650)/2;
	if(tarx<1)tarx = 1;
	if(tary<1)tary = 1;
	window.moveTo(tarx,tary);
}
function handleError() {
      return true;
}

window.onerror = handleError;
//window.history.forward(1);
