// JavaScript Document
var nn4 = document.layers;
var ie = document.all;
var dom = document.getElementById && !document.all; 

var currentTime = new Date();
var request;

function browser(id){
  if(nn4) {
  path = document.layers[id];
  }
  else if(ie) {
  path = document.all[id];
  } 
  else {
  path = document.getElementById(id);
  }
return path;  //return the path to the css layer depending on which browser is looking at the page
}

function confirm_alert()
{
	input_box=confirm("Click OK or Cancel to Continue");
	if (input_box==true) { 
		return true;
	} else {
		return false;}
}

var SelectProduct = function(pro_id) {
	
	var cvalue = '';
	if ($('product'+pro_id).checked == true) {
		cvalue = 'checked';
	} else {
		cvalue = 'notchecked';
	}
	
	var url = "../engine_selectproduct.php";
	var pars = "pro_id="+pro_id+"&cvalue="+cvalue+"&time="+currentTime;
	//alert(pars);
	var myAjax = new Ajax.Request( url, {	method: 'post',	parameters: pars,	onComplete: DisplaySelectProduct	} );	
}

var DisplaySelectProduct = function(rspText) {
	upd  = eval('(' +  rspText.responseText + ')');
	
	if (upd['ustatus'] == 'break') {
		alert("4台以上のデモ機を一度に予約することは出来ません。");
		
		$('product'+upd['pro_id']).checked = false;
	}
	//alert(rspText.responseText);
}

function validation()
{
	var frm = document.contactform;
	var checkform = "";
	//booking
	if (frm.sel_year.value == "" || frm.sel_month.value == "" || frm.sel_date.value == "")
	{
		checkform = "fail";
		document.getElementById("selectdate").bgColor = "#FFD3CE";
	} else {
		document.getElementById("selectdate").bgColor = "#FFFFFF";	
	}
	
	if (!frm.period[0].checked && !frm.period[1].checked)
	{
		checkform = "fail";
		document.getElementById("speriod").bgColor = "#FFD3CE";
	} else {
		document.getElementById("speriod").bgColor = "#FFFFFF";	
	}
	//end booking
	if (frm.sel_year.value == "" || frm.sel_month.value == "" || frm.sel_date.value == "")
	{
		checkform = "fail";
		document.getElementById("selectdate").bgColor = "#FFD3CE";
	} else {
		document.getElementById("selectdate").bgColor = "#FFFFFF";	
	}
	
	if (frm.name1.value == "")
	{
		checkform = "fail";
		document.getElementById("sname1").bgColor = "#FFD3CE";
		
		frm.name1.onblur = function(){
			if (frm.name1.value != "") {	
				document.getElementById("sname1").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("sname1").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("sname1").bgColor = "#FFFFFF";	
	}
	
	if (frm.cprovince.value == "")
	{
		checkform = "fail";
		document.getElementById("scprovince").bgColor = "#FFD3CE";
		
		frm.cprovince.onblur = function(){
			if (frm.cprovince.value != "") {	
				document.getElementById("scprovince").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("scprovince").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("scprovince").bgColor = "#FFFFFF";	
	}
	
	if (frm.tf_1.value == "")
	{
		checkform = "fail";
		document.getElementById("stf_1").bgColor = "#FFD3CE";
		
		frm.tf_1.onblur = function(){
			if (frm.tf_1.value != "") {	
				document.getElementById("stf_1").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("stf_1").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("stf_1").bgColor = "#FFFFFF";	
	}
	
	if (frm.tf_2.value == "")
	{
		checkform = "fail";
		document.getElementById("stf_2").bgColor = "#FFD3CE";
		
		frm.tf_2.onblur = function(){
			if (frm.tf_2.value != "") {	
				document.getElementById("stf_2").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("stf_2").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("stf_2").bgColor = "#FFFFFF";	
	}
	
	if (frm.tf_5.value == "")
	{
		checkform = "fail";
		document.getElementById("stf_5").bgColor = "#FFD3CE";
		
		frm.tf_5.onblur = function(){
			if (frm.tf_5.value != "") {	
				document.getElementById("stf_5").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("stf_5").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("stf_5").bgColor = "#FFFFFF";	
	}
	
	if (frm.email.value == "")
	{
		checkform = "fail";
		document.getElementById("semail").bgColor = "#FFD3CE";
		
		frm.email.onblur = function(){
			if (frm.email.value != "") {	
				document.getElementById("semail").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("semail").bgColor = "#FFD3CE";	
			}
		};
	} else {
		document.getElementById("semail").bgColor = "#FFFFFF";	
	}
	
	if (frm.cemail.value == "")
	{
		checkform = "fail";
		document.getElementById("semail").bgColor = "#FFD3CE";
		
		frm.cemail.onblur = function(){
			if (frm.cemail.value != "") {	
				document.getElementById("semail").bgColor = "#FFFFFF";	
			} else {
				document.getElementById("semail").bgColor = "#FFD3CE";	
			}
		};
	} else {
		if (frm.cemail.value != frm.email.value)
		{
			checkform = "fail";
			document.getElementById("semail").bgColor = "#FFD3CE";
			
			frm.cemail.onblur = function(){
				if (frm.cemail.value == frm.email.value) {	
					document.getElementById("semail").bgColor = "#FFFFFF";	
				} else {
					document.getElementById("semail").bgColor = "#FFD3CE";
				}
			};
		} else {
			document.getElementById("semail").bgColor = "#FFFFFF";	
		}
	}
	
	if (frm.email.value.indexOf("@")<1 || frm.email.value.lastIndexOf(".")-frm.email.value.indexOf("@")<2 )
	{
		checkform = "fail";
		document.getElementById("semail").bgColor = "#FFD3CE";
		
		frm.email.onblur = function(){
			if (frm.email.value.indexOf("@")<1 || frm.email.value.lastIndexOf(".")-frm.email.value.indexOf("@")<2 ) {	
				document.getElementById("semail").bgColor = "#FFD3CE";	
			} else {
				document.getElementById("semail").bgColor = "#FFFFFF";	
			}
		};
	} else {
		document.getElementById("semail").bgColor = "#FFFFFF";	
	}
	
	if (frm.cb_1.checked == false && frm.cb_2.checked == false) {
		checkform = "fail";
		document.getElementById("cb_12").bgColor = "#FFD3CE";
	} else {
		document.getElementById("cb_12").bgColor = "#FFFFFF";	
	}
	
	if (checkform == "fail")
	{
		
		/*var target_div = browser("errmsg");
		var content = "未入力の項目があるため保存出来ません。";
		if(nn4) {	
			target_div.document.open();
			target_div.document.write(content); //write content to layer
			target_div.document.close();
			}
		else {	    
			target_div.innerHTML = content;  //write content to layer
		}*/
		
		return false;	
	} else {
		return true;
	}	
}
