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)
			{
				
				if(document.getElementById(id_array[i]).type=="text" || document.getElementById(id_array[i]).type=="textarea")
				{
					$("#"+id_array[i]).val(error_massage);
				}



				$("#"+id_array[i]).focus(function () {
					$(this).css({
							'border':'1px solid black',
							'background-color':'white',
							'color':'black'
					});
					if($(this).val()==error_massage)
					{
					
						$(this).val('');
						
					}
				});


				$("#"+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 _trim(str)
{
	str = str.replace(/^\s*/,'');
	str = str.replace(/\s*$/,'');
	return str;
}
function search_keyword(_id,url)
{		
	var search_keyword = _trim($("#"+_id).val());
	search_keyword = encodeURIComponent(search_keyword);	

	if(search_keyword=='')
	{
		alert('キーワードを入力してください。');
		$("#"+id).focus();
	}
	else
	{
		location.href=url+"?search_keyword="+search_keyword;	
	}
}
function search_keyword_n(id,url)
{
	var search_keyword = _trim($("#"+id).val());
	search_keyword = encodeURIComponent(search_keyword);		
	var obj = document.getElementsByName('sp');
	var sp = '';
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].checked==true)
		{
			sp = obj[i].value;
		}
	}
	
	if(search_keyword=='')
	{
		alert('キーワードを入力してください。');
		$("#"+id).focus();
	}
	else
	{
		location.href=url+"?sp="+sp+"&qr="+search_keyword;
	}		
}
function case_tab_show(show_cs,id)
{
	$('.case_studio').hide();
	$('.etc_case_studio').hide();
	$('.server_raid_case_studio').hide();
	$('.search_bg').hide();

	$('#tab_case01_').removeClass('tab_case01_over');
	$('#tab_case02_').removeClass('tab_case02_over');
	$('#tab_case03_').removeClass('tab_case03_over');
	$('#tab_case04_').removeClass('tab_case04_over');

	$('.'+show_cs).show();
	$('#'+id).addClass(id+'over');
}
function case_studio_search(ar)
{
	var obj_1,obj_2;
	var _value_1 = '';
	var _value_2 = '';
	if(ar=='sr_01')
	{	
		url = "/data-recovery-services/case-studies/hdd.html";
		obj_1 = document.getElementsByName("s_k_1");
		obj_2 = document.getElementsByName("s_k_2");
	}
	else if(ar=='sr_02')
	{
		url = "/raid-nas-server/case-studies/server-raid.html";
		obj_1 = document.getElementsByName("s_k_3");
		obj_2 = document.getElementsByName("s_k_4");
	}
	else if(ar=='sr_03')
	{
		url = "/data-recovery-services/case-studies/etc.html";
		obj_1 = document.getElementsByName("s_k_5");
		obj_2 = document.getElementsByName("s_k_6");
	}

	for(var i=0;i<obj_1.length;i++)
	{
		if(obj_1[i].checked==true)
		{
			_value_1 = obj_1[i].value;
			break;
		}
	}
	for(var i=0;i<obj_2.length;i++)
	{
		if(obj_2[i].checked==true)
		{
			_value_2 = obj_2[i].value;
			break;
		}
	}

	_value_1 = encodeURIComponent(_value_1);	
	_value_2 = encodeURIComponent(_value_2);	

	location.href = url+"?sk_01="+_value_1+"&sk_02="+_value_2;	
}

/*************************************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; 
	var layer_left  =  e.pageX ? e.pageX : document.documentElement.scrollLeft+e.clientX; 

	document.getElementById("passwd_input_area").style.top = (layer_top+20)+"px";
	document.getElementById("passwd_input_area").style.left = (layer_left)+"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***************************************************/
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("必須項目を記入してください。");
		   		}
		   }
		});
	}
}
/*************************************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 toggleLayerCenter(_id,e)
{

	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;
	}

	e = e || window.event;	
	var layer_top  =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 
	var layer_left  =  e.pageX ? e.pageX : document.documentElement.scrollLeft+e.clientX; 

	document.getElementById(_id).style.top = (layer_top)+"px";
	document.getElementById(_id).style.left = ((myWidth/2))-448+"px";

	$("#"+_id).show("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;
}












/********************************************************************************************/
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; 
	
	if(!document.getElementById("insert_form_area"))
	{
		$("body").append("<div id='insert_form_area' style='position:absolute;left:0px;top:0px;background:white;border:1px solid gray;padding:10px;'></div>");
	}

	if(position=='top')
	{
		document.getElementById("insert_form_area").style.top = (layer_top+10)+"px";
		document.getElementById("insert_form_area").style.left = (x-220)+"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").show("normal");

			$("input,textarea").focus(function () {
				$(this).css({'background-color' : '#e4ffe4', 'color' : 'black'});
			});
			$("input,textarea").blur(function () {
				$(this).css({'background-color' : 'white', 'color' : '#4b4b4b'});
			});
	   }
	});	
}



function _modify_form_open(e,bbs_code,id)
{
	e = e || window.event;	

	var layer_top   =  e.pageY ? e.pageY : document.documentElement.scrollTop+e.clientY; 
	var layer_left  =  e.pageX ? e.pageX : document.documentElement.scrollLeft+e.clientX; 

	if(!document.getElementById("insert_form_area"))
	{
		$("body").append("<div id='insert_form_area' style='position:absolute;left:0px;top:0px;background:white;border:1px solid gray;padding:10px;'></div>");
	}

	document.getElementById("insert_form_area").style.top = (layer_top+10)+"px";
	document.getElementById("insert_form_area").style.left = (layer_left-600)+"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'});
			});
		
	   }
	});	
}

function _passwd_chk_form_open(id,e,url)
{
	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; 

	if(!document.getElementById("passwd_input_area"))
	{
		$("body").append
		(
			'<div id="passwd_input_area" style="position:absolute;left:0px;top:0px;background:white;border:1px solid gray;padding:10px;">'+
			'<form id="_passwd_form" method="post" action="javascript:;" name="passwd_form">'+
			'<input id="_private_passwd" type="password" style="width: 160px" name="private_passwd" /><br />'+
			'<a onclick="check_password(\''+id+'\',\''+url+'\');" href="javascript:;">'+
			'<img alt="送信" align="right" src="/bbs/img/bt_send.gif" /></a> <a onClick="$(\'#passwd_input_area\').hide(\'fast\');" href="javascript:;">'+
			'<img alt="キャンセル" align="right" src="/bbs/img/bt_close02.gif" /></a>'+
			'<input id="_id" type="hidden" name="id" value="'+id+'" />'+
			'</form>'+
			'</div>'
		);
	}
	
	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);
}

function check_password(id,url)
{
	
	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("");
			}
	   }
	});	
}

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; 

	var url = location.href;
	url = url.split("?");
	url = url[0];

	if(!document.getElementById("passwd_input_area"))
	{
		$("body").append
		(
			'<div id="passwd_input_area" style="position:absolute;left:0px;top:0px;background:white;border:1px solid gray;padding:10px;">'+
			'<form id="_passwd_form" method="post" action="javascript:;" name="passwd_form">'+
			'<input id="_private_passwd" type="password" style="width: 160px" name="private_passwd" /><br />'+
			'<a onclick="check_password(\''+url+'\');" href="javascript:;">'+
			'<img alt="送信" align="right" src="/bbs/img/bt_send.gif" /></a> <a onClick="$(\'#passwd_input_area\').hide(\'fast\');" href="javascript:;">'+
			'<img alt="キャンセル" align="right" src="/bbs/img/bt_close02.gif" /></a>'+
			'<input id="_id" type="hidden" name="id" value="'+id+'" />'+
			'</form>'+
			'</div>'
		);
	}

	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);
}

/********************************************************************************************/
