var currentValue = "";

function gotoSpec(reference){
	var addr = "specification.cgi?refno=" + reference;
	window.open(addr,"spec","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=520,height=450");
}
function addData(){
	if(confirm("Are you sure to regist new company data?")){
		var addr = "./reg_second.cgi";
		window.open(addr,"_self","");
		exit();
	}
}
function editData(){
	if(currentValue == ""){
		alert("you must select a reference number you want to edit.");
		exit();
	}
	if(confirm("Are you sure to edit?")){
		var addr = "./reg_second.cgi?refno=" + currentValue;
		window.open(addr,"_self","");
		exit();
	}
	//var addr = "specification.cgi?refno=" + reference;
	//window.open(addr,"spec","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=520,height=550");
}
function deleteData(){
	if(currentValue == ""){
		alert("you must select a reference number you want to delete.");
		exit();
	}
	if(confirm("Are you sure to delete? if you select OK, this data will be delete completely")){
		var addr = "./delete.cgi?refno=" + currentValue;
		window.open(addr,"_self","");
		exit();
	}	
	
	//var addr = "specification.cgi?refno=" + reference;
	//window.open(addr,"spec","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=520,height=550");
}

function setValue(radiovalue){
	currentValue = radiovalue;
	//alert(currentValue);
}

function regist(){
	// get value
	var refno     = document.registrationForm.refno.value;
	var jobtitle  = document.registrationForm.jobtitle.value;
	var sector    = document.registrationForm.sector.value;
	var locations = document.registrationForm.locations.value;
	var salary    = document.registrationForm.salary.value;
	var require   = document.registrationForm.require.value;
	
	// check charactor numbers
	var refno_count     = refno.length;
	var jobtitle_count  = jobtitle.length;
	var sector_count    = sector.length;
	var locations_count = locations.length;
	var salary_count    = salary.length;
	var require_count   = require.length;
	
	if( refno_count < 1 ){
		alert("you have to insert Reference Number");
		exit();
	}
	
	data = refno.match(/^\w+$/);
	if (!data) {
		alert("you can only use numeric and character for Reference Number.");
		exit();
	}
	
	if( jobtitle_count < 1 ){
		alert("you have to insert Job Title");
		exit();
	}
	if( sector_count < 1 ){
		alert("you have to insert Sector");
		exit();
	}
	if( locations_count < 1 ){
		alert("you have to insert Location");
		exit();
	}
	if( salary_count < 1 ){
		alert("you have to insert Salary");
		exit();
	}
	if( require_count < 1 ){
		alert("you have to insert Require");
		exit();
	}
	
	
	if( refno_count > 10 ){
		alert("you can't insert over 10 charactors for Reference Number");
		exit();
	}
	if( jobtitle_count > 50 ){
		alert("you can't insert over 50 charactors for Job Title");
		exit();
	}
	if( sector_count > 25 ){
		alert("you can't insert over 25 charactors for Sector");
		exit();
	}
	if( locations_count > 40 ){
		alert("you can't insert over 40 charactors for Location");
		exit();
	}
	if( salary_count > 30 ){
		alert("you can't insert over 30 charactors for Salary");
		exit();
	}
	if( require_count > 1000 ){
		alert("you can't insert over 1000 charactors for Require");
		exit();
	}
	
	//alert("[refno is]" + refno + "[job is]" + jobtitle + "[sector is]" + sector + "[locations is]" + locations + "[salary is]" + salary + "[require is]" + require);
	
	document.registrationForm.action="./company_reg.cgi";
	document.registrationForm.submit();
}