function validate_form(id_array,error_massage,action)
{
	if(action=="init")
	{
		for(var i=0;i<id_array.length;i++)
		{
			$("#"+id_array[i]).focus(function () {
				if($(this).val()==error_massage)
				{
				
					$(this).val('');
					$(this).css({
						'border':'1px solid black',
						'background-color':'white',
						'color':'black'
					});
				}
			});

		}

	}
	else
	{
		var result = true;
		var first_Null = '';
		for(var i=0;i<id_array.length;i++)
		{
			if($("#"+id_array[i]).val()=='' || $("#"+id_array[i]).val()==error_massage)
			{
				$("#"+id_array[i]).val(error_massage);
				
				$("#"+id_array[i]).css({
					'border':'1px solid red',
					'color':'red'
				});
				
				if(first_Null=='')
				{
					first_Null = id_array[i];
				}

				result = false;
			}
			else
			{
				$("#"+id_array[i]).css({
					'border':'1px solid black',
					'background-color':'white',
					'color':'black'
				});
			}
		}
		if(first_Null!="")
		{
			alert(error_massage);
			$("#"+first_Null).focus();
		}
		return result;
	}
}
/*************************************************************************************************/
function popup(src,width,height)
{
		window.open(src,'','width='+width+',height='+height);
}
function print_content_form_open(id,type)
{
	if(type=='N')
	{
		window.open('/print_service/'+id+'/394749357dj983/.print_operation','','width='+700+',height='+768);
	}
	else if(type=='Y')
	{
		window.open('/print_service/'+id+'/394749357dj983/.print_operation','','width='+700+',height='+768);
	}
}
/*******************************************************************************/
function image_size(_img_id,_img_layer_id,_operation,url)
{

	$("#"+_img_layer_id).css({'position' : 'absolute','border':'5px solid silver'});
	
	
	var obj = document.createElement("img");
	obj.src = url;
	
	_width = obj.width;
	_height = obj.height; 
	
	if(_operation=='+')
	{
		_width = $("#"+_img_id).width()+(_width/2);
		_height = $("#"+_img_id).height()+(_height/2);
	}
	else if(_operation=='-')
	{
		_width = $("#"+_img_id).width()-(_width/2);
		_height = $("#"+_img_id).height()-(_height/2);
	}
	else if(_operation=='100')
	{	
		_width = obj.width;
		_height = obj.height;
	}
	
	$("#"+_img_id).animate
	({
		width: _width,
		height: _height 
	});

	//centerLayer(_img_layer_id,_width,_height);
	//document.getElementById(_img_layer_id).style.top = 160+"px";
}
function image_reset(_id,img_layer_id)
{
	$("#"+img_layer_id).css({'position' : 'static','border':'5px solid silver'});
	$("#"+_id).animate
	({
		width: 251,
		height:165
	});
}
function centerLayer(_id,width,height)
{
	var myWidth = 0, myHeight = 0;

	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	document.getElementById(_id).style.left = ((myWidth/2)-parseInt(width/2))+"px";
	document.getElementById(_id).style.top = (((myHeight/2)+(document.documentElement.scrollTop)-100)-parseInt(height/4))+"px";
}
/*******************************************************************************/
function mail_send(url)
{
	var _validate = Array('_mail');
	if(validateForm(_validate))
	{
		document.getElementById("_to_mail").action="/_cms/ext/mail/main_ok.php";
		document.getElementById("_to_mail").submit();
	}
}
function mail_send_form_open(e,id)
{
	var x = document.body.clientWidth;
	x = parseInt(x/2);

	if(!document.getElementById("mail_send_form_area"))
	{	
		$('body').append("<div id='mail_send_form_area' style='position:absolute;display:none;background-color:#dfdfdf;'></div>");
	}
	
	e = e || window.event;	

	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 
	document.getElementById("mail_send_form_area").style.top = (layer_top+15)+"px";	
	document.getElementById("mail_send_form_area").style.left = (x)+"px";	
	

	var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
	$.ajax({
	   type: "POST",
	   url: "/_cms/ext/mail/mail.php",
	   data: "&rand_int="+rand_int+"&id="+id,
	   success: function(a){
		  $("#mail_send_form_area").html(a);
		  $("#mail_send_form_area").show("normal");
	   }
	});
}


function search_keyword(_id,url)
{		
	var search_keyword = $("#"+_id).val();
	search_keyword = encodeURIComponent(search_keyword);		
	location.href=url+"?search_keyword="+search_keyword;	
}

/*************************************BBS PASSWORD FORM*************************************************/
function _passwd_form_open(id,e)
{
	var x = document.body.clientWidth;
	x = parseInt(x/2);

	e = e || window.event;	

	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 

	document.getElementById("passwd_input_area").style.top = (layer_top+10)+"px";
	//document.getElementById("passwd_input_area").style.left = (x-80)+"px";
	
	$("#passwd_input_area").show("normal",function(){
		document.getElementById("_private_passwd").focus();
	});
	$("#_id").val(id);
}
/*************************************BBS PASSWORD FORM*************************************************/
/*************************************BBS PASSWORD CHECKER*************************************************/
function check_password(id,url)
{
	url = url+"+"+id+".html";
	var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
	
	$.ajax({
	   type: "POST",
	   url: "/_cms/bbs/check_passwd.php?rand_int="+rand_int,
	   data: "&id="+id+"&private_passwd="+$("#_private_passwd").val(),
	   success: function(msg)
	   {	
			if(msg==1)
			{
				location.href = url;
			}
			else if(msg==0)
			{
				alert("PASSWORD IS NOT MATCH! PLEASE CHECK YOUR PASSWORD");
				$("#_private_passwd").val("");
			}
	   }
	});	
}
/*************************************BBS PASSWORD CHECKER*************************************************/
/*************************************BBS DELETE***************************************************/
function _del_form_open(e)
{
	var x = document.body.clientWidth;

	x = parseInt(x/2);

	e = e || window.event;	

	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 

	document.getElementById("passwd_input_area").style.top = (layer_top+20)+"px";
	//document.getElementById("passwd_input_area").style.left = (x+20)+"px";
	document.getElementById("_private_passwd").value='';

	$("#passwd_input_area").show("normal",function(){
		document.getElementById("_private_passwd").focus();
	});
}

function _delete_passwd_check(url)
{
	var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
	var params = $("#_passwd_form").formSerialize();
	$.ajax({
	   type: "POST",
	   url: "/_cms/bbs/bbs_delete.php?rand_int="+rand_int,
	   data: params,
	   success: function(a)
	   {
			if(a==1)
			{
				location.replace(url);
			}
			else if(a==0)
			{

				alert("PASSWORD IS NOT MATCH! PLEASE CHECK YOUR PASSWORD"+a);
				$("#_private_passwd").val("");
				$("#_private_passwd").focus();
			}
			else
			{
				alert('ERROR');
			}
	   }
	});	
}
/*************************************BBS DELETE***************************************************/
/*************************************BBS WRITE****************************************************/
function write_form_open(e,bbs_code,position,url)
{
	
	var x = document.body.clientWidth;
	var y = document.body.clientHeight;

	x = parseInt(x/2);
	y = parseInt(y/2);

	e = e || window.event;	
	
	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 

	document.getElementById("insert_form_area").style.top = (layer_top+10)+"px";
	document.getElementById("insert_form_area").style.left = (x-630)+"px";

	var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
	$.ajax({
	   type: "POST",
	   url: "/_cms/bbs/bbs_write.php?rand_int="+rand_int,
	   data: "&bbs_code="+bbs_code+"&url="+url,
	   success: function(a)
	   {
		
		
	       $("#insert_form_area").html(a);
	       $("#insert_form_area").toggle("normal");
	       
	       	$("input,textarea").focus(function () {
		      	$(this).css({'background-color' : '#e4ffe4', 'color' : 'black'});
			});
	       	
			$("input,textarea").blur(function () {
		      	$(this).css({'background-color' : 'white', 'color' : '#4b4b4b'});
			});
			
			validate_form
			(
				new Array(
					"_title",
					"_user_name",
					"_private_passwd",
					"_content",
					"__in_code"
				),
				"必須項目を入力下さい。",
				"init"
			);
	   }
	});	
}
function insert_bbs(url)
{
	if
	(
		validate_form
		(
			new Array
			(
				"_title",
				"_user_name",
				"_private_passwd",
				"_content",
				"__in_code"
			),
			"必須項目を入力下さい。",
			"validate"
		)
	)
	{
		var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
		var params = $("#_write_form").formSerialize();
		
		$.ajax({
		   type: "POST",
		   url: "/_cms/bbs/bbs_save.php",
		   data: params+"&rand_int="+rand_int,
		   success: function(a)
		   {
		   		if(a==0){
		   			alert("SAVE COMPLETED.");
		   			location.replace(url);
		   		}else if(a==1){
		   			alert("PERMISSION ERROR");
		   		}else if(a==2){
		   			alert("認証コード MISS MATCH!");
		   		}else if(a==3){
		   			alert("必須項目を記入してください。");
		   		}else{
		   			alert(a);
		   			//alert("ERROR.");
		   		}
		   }
		});
	}
}
/*************************************BBS WRITE****************************************************/
/*************************************BBS MODIFY***************************************************/
function modify_bbs(url,id){
	if
	(
		validate_form
		(
			new Array
			(
				"_title",
				"_user_name",
				"__private_passwd",
				"_content"
			),
			"必須項目を入力下さい。",
			"validate"
		)
	)
	{
		var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
		var params = $("#_write_form").formSerialize();

		$.ajax({
		   type: "POST",
		   url: "/_cms/bbs/bbs_modify_ok.php?rand_int="+rand_int,
		   data: params+"&rand_int="+rand_int,
		   success: function(a)
		   {
		   		if(a==0)
				{
		   			alert("SAVE COMPLETED.");
		   			location.replace(url);
		   		}
				else if(a==1)
				{
		   			alert("PERMISSION ERROR");
		   		}
				else if(a==2)
				{
		   			alert("パスワード ERROR");
		   		}
				else if(a==3)
				{
		   			alert("必須項目を記入してください。");
		   		}
		   }
		});
	}
}
function _modify_form_open(e,bbs_code,id)
{
	var x = document.body.clientWidth;
	var y = document.body.clientHeight;
	var position = 'top';

	x = parseInt(x/2);
	y = parseInt(y/2);

	e = e || window.event;	
	
	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 
	
	document.getElementById("insert_form_area").style.top = (layer_top+10)+"px";
	document.getElementById("insert_form_area").style.left = (x-630)+"px";
	
	var rand_int = Math.floor(Math.random() * 1000000000 ) + 1;
	$.ajax({
	   type: "POST",
	   url: "/_cms/bbs/bbs_modify.php?rand_int="+rand_int,
	   data: "&bbs_code="+bbs_code+"&id="+id,
	   success: function(a)
	   {
			$("#insert_form_area").html(a);
			$("#insert_form_area").show("normal");
			   
			$("input,textarea").focus(function () {
				$(this).css({'background-color' : '#e4ffe4', 'color' : 'black'});
			});
			$("input,textarea").blur(function () {
				$(this).css({'background-color' : 'white', 'color' : '#4b4b4b'});
			});
			
			validate_form
			(
				new Array(
					"_title",
					"_user_name",
					"__private_passwd",
					"_content",
					"__in_code"
				),
				"必須項目を入力下さい。",
				"init"
			);
	   }
	});	
}
/*************************************BBS MODIFY***************************************************/
function detail_search_layer_open(e)
{
	$("#detail_form").toggle("normal");
	$("#normal_form").toggle("normal");
}
function search_keyword_detail(url)
{
	var as_eq = $("#_as_eq").val();
	var as_st = $("#_as_st").val();
	var as_or = $("#_as_or").val();
	var as_ft = $("#_as_ft").val();
		
	as_eq = encodeURIComponent(as_eq);	
	as_st = encodeURIComponent(as_st);	
	as_or = encodeURIComponent(as_or);	
	as_ft = encodeURIComponent(as_ft);	

	location.href=url+"?dt=true&amp;as_eq="+as_eq+"&amp;as_st="+as_st+"&amp;as_or="+as_or+"&amp;as_ft="+as_ft;	
}
function validateForm(_validate)
{
	for(var i=0;i<_validate.length;i++)
	{
		if($("#"+_validate[i]).val()=='')
		{
			if($("#msg"+_validate[i]))
			{
				$("#msg"+_validate[i]).html("<br /><br />&nbsp;&nbsp;<font color='red'>* 必須項目を記入してください。</font></br ><br /><br />"); 
			}
			else
			{
				alert("* 必須項目を記入してください。");
			}
		}
		else
		{
			if($("#msg"+_validate[i]))
			{
				$("#msg"+_validate[i]).html(""); 
			}
		}
	}
	for(var i=0;i<_validate.length;i++)
	{
		if($("#"+_validate[i]).val()=='')
		{
			$("#"+_validate[i]).focus(); 
			return false;
		}
	}
	return true;
}
function toggleLayer(id)
{
	if(document.getElementById(id).style.display=="none"){
		$("#"+id).show("fast");
	}else{
		$("#"+id).hide("fast");
	}
}
function setCenter(id,top,left,display) 
{
	var screen_width = window.innerWidth || self.innerWidth || document.body.clientWidth;
	var obj_width = parseInt(document.getElementById(id).style.width)/2;
	width = parseInt(screen_width/2) - obj_width;
	width = width + parseInt(left);
	document.getElementById(id).style.left = width+"px";
	document.getElementById(id).style.top = top+"px";
	document.getElementById(id).style.display=display;
}
