//function change_pic(object_id,pic_id){
//	
//	var my_select_object=document.getElementById(object_id);
//	var my_pic=document.getElementById(pic_id);
//	
//	var src_path="http://www.freelancer.jp/images/work"+my_select_object.options[my_select_object.selectedIndex].value+".gif";	
//	my_pic.setAttribute('src',src_path);
//}

function mail(url,random_name){
//	parent.window.navigate(url);
	var name='mail'+random_name;//we enable a new window created after every user click.By assigning the new winow a unique name which is construted by string 'mail' plus a random math number generated by php function mt_rand() --random_name.
	window.open(url,name);
}

function hp(url){
	//parent.window.navigate(url);	
	window.open(url,'hp');
}

function go_hp(url){
	window.navigate(url);
}

//this function used to show one user's former <select></select> settings.
function initiate_select(tag,select_value){
	var select_tag=document.getElementById(tag);
	for(point=0;point<select_tag.length;point++){
			if(select_tag.options[point].value==select_value)
				select_tag.options[point].selected=true;
	}
}

function user_id_check(tag_id)
{
	
var userid;
userid = document.getElementById(tag_id);
window.open('http://www.freelancer.jp/ssl/user-id-check.php?user_id='+userid.value,'newwindow', 'height=100, width=400, top=150,left=150, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');

}

function user_mail_check(tag_id)
{
	var mail;
	mail=document.getElementById(tag_id);
	
	window.open('http://www.freelancer.jp/ssl/mail-check.php?mail='+mail.value,'newwindow', 'height=100, width=400, top=150,left=150, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	
}

function chkStr(user_id,pwd,name,name_kana,confirm_pwd,mail,type_radio,address_no,tel,comment,skill,money,sal_from,sal_to,address){
	
	if(user_id!=''){
	in_str = document.getElementById(user_id).value.toString();
  var result = in_str.match(/[0-9a-zA-Z_\-@\.]+/); 
  if (in_str != result){
	  window.alert("会員IDは半角英数字で入力して下さい\nYou can use only alphabet and number.");
     return false;}
	}
	
	if(name!=''){
		in_str = document.getElementById(name).value.toString();
		if(in_str.length==0){
			alert('The name field should not be empty!');
			return false;
		}
	}
	
	if(name_kana!=''){
		in_str = document.getElementById(name_kana).value.toString();
		if(in_str.length==0){
			alert('The name_kana field should not be empty!');
			return false;
		}
	}
	
	if(pwd!=''){
  		in_str = document.getElementById(pwd).value.toString();
  		var result = in_str.match(/[0-9a-zA-Z]+/); 
  		if (in_str != result)
    		{window.alert("パスワードは半角英数字で入力して下さい。\nYou can use only alphabet and number on the password.");
     			return false;}
	 
			if(in_str.length<6){
			alert('パスワードは6文字から20文字の範囲内で入力してください。\nThe length of your password is too short!it should be between 6 to 20 characters!');
				return false;}
	}
	
	if(confirm_pwd!=''){
			if(in_str!=document.getElementById(confirm_pwd).value.toString()){
				alert('確認用パスワードを入力してください。\nPlease confirm your password!');	
				return false;
			}
	}
			
	if(mail!=''){
		in_str=document.getElementById(mail).value.toString();
   		var result=in_str.match(/[0-9a-zA-Z]+[0-9a-zA-Z_\-\.]*@[0-9a-zA-Z]+[0-9a-zA-Z_\-\.]*\.[0-9a-zA-Z]+[0-9a-zA-Z_\.\-]*/);
   		if (in_str != result)
    		{window.alert("メールは半角英数字で入力して下さい。\nYou can use only alphabet and number on the mail.");
    		 return false;} 
	}
	
	if(type_radio!=''){
		 var radio=document.getElementsByName(type_radio);
		if(!radio[0].checked&&!radio[1].checked){
		alert('フリーランサーまたは企業を選択してください。\nPlease select your type, freelancer or company!!');
		return false;
		}
	}

/*if(user_id!=''&&pwd!=''&&confirm_pwd!=''&&mail!=''&&type_radio!=''){
	if(confirm("この内容で登録します。よろしいですか？\nDo you really want to submit?"))
	return true;
		else 
			return false;
		}*/
		
if(address_no!=''){
	in_str = document.getElementById(address_no).value.toString();
  var result = in_str.match(/[0-9\-]+/); 
  if (in_str != result){
	  window.alert("郵便番号は半角数字または-で入力してください。\n〒 You should not be empty and only 0-9 and -.");
     return false;}
	}

if(address!=''){
	in_str = document.getElementById(address).value.toString();
  if (in_str ==''){
	  window.alert("住所を入力してください。\nPlease input your detail address information!!");
     return false;}
	}
	
if(tel!=''){
	in_str = document.getElementById(tel).value.toString();
  var result = in_str.match(/[0-9\-]+/); 
  if (in_str != result){
	  window.alert("電話番号は半角数字で入力して下さい。\nTel should not be empty and only 0-9 and -.");
     return false;}
	}

if(skill!=''){
	in_str = document.getElementById(skill).value.toString();
	
	var pattern=/^[\s　]*$/;	//this if code bolck used to check the skill textaera if it's empty or consists of all space . the form will not submit.
	if(pattern.test(in_str)){
		alert('資格を記入して下さい。\nskill can not be empty!');
		return false;
	}
	
  if (in_str.length>50){
	  window.alert("資格欄は半角50文字（全角25文字）以内で入力して下さい。\nThe skill length less than 50.");
     return false;}
	}
	
if(comment!=''){
	in_str = document.getElementById(comment).value.toString();  
	
	var pattern=/^[\s　]*$/; //like the skill above
	if(pattern.test(in_str)){
		alert('コメントを記入して下さい。\ncomment can not be empty!');
		return false;
	}
	
  if (in_str.length>400){
	  window.alert("コメントは半角400文字（全角200文字）以内で入力して下さい。\nThe comment length less than 400.");
     return false;}
	}
	
	if(money!=''){
	in_str = document.getElementById(money).value.toString();
  if (in_str.length>50){
	  window.alert("金額の詳細は半角450文字（全角225文字）で入力して下さい。\nThe money length less than 450");
     return false;}
	}
	
	if(sal_from!=''&&sal_to!=''){
		var from=document.getElementById(sal_from).value.toString();
		var to=document.getElementById(sal_to).value.toString()
  if(parseInt(from)>parseInt(to)){
	  window.alert("給料希望範囲をもう一度　正確に選択して下さい。\nsal_from should be less than sal_to");
     return false;}
	}
	
	return true;
}

//this function used to check wether user password is correct after they change the pwd on modify page.
function check_password(pwd){
	in_str = document.getElementById(pwd).value.toString();
  var result = in_str.match(/[0-9a-zA-Z]+/); 
  if (in_str != result)
    {window.alert("パスワードは半角英数字で入力して下さい。\nYou can not be empty.");
     return false;}
	 return true;
}

//this function used to whether clear the key word input box
function clear_box(box_id){
	var box=document.getElementById(box_id);
	  if(box.value=="スペース入力で複数検索ができます。")
	  		box.value="";
}
//this function is used to replace the <form> tag on home page.because form tag always make lay out design trouble
function sub_search(work,address1,sal_type,sal_from,sal_to,key_word,search_order,type){
	var work_str=document.getElementById(work).value.toString();
	var address1_str=document.getElementById(address1).value.toString();
	var sal_type_str=document.getElementById(sal_type).value.toString();
	var sal_from_str=document.getElementById(sal_from).value.toString();
	var sal_to_str=document.getElementById(sal_to).value.toString();
	var key_word_str=document.getElementById(key_word).value.toString();
	var search_order_str=document.getElementById(search_order).value.toString();
	 if(type=='f')
		window.navigate('http://www.freelancer.jp/find-an-employee/fr_list.php?f_work='+work_str+'&f_address1='+address1_str+'&f_sal_type='+sal_type_str+'&f_sal_from='+sal_from_str+'&f_sal_to='+sal_to_str+'&f_key_word='+key_word_str+'&f_search_order='+search_order_str);
		else
		window.navigate('http://www.freelancer.jp/find-a-job/c_list.php?c_work='+work_str+'&c_address1='+address1_str+'&c_sal_type='+sal_type_str+'&c_sal_from='+sal_from_str+'&c_sal_to='+sal_to_str+'&c_key_word='+key_word_str+'&c_search_order='+search_order_str);
}

//this function used to create a new pop up window which has the user's profile.
function show_profile(profile_url){
	window.open(profile_url,'profile','height=350, width=800, top=150,left=150, toolbar=no, menubar=no,scrollbars=yes,resizable=no,location=no, status=no');
}

//this function used to initiate the login data form after an error occured. For example the user_id has already existed!! This function is supposed to use on login.php page.
function recover_login_data(user_id,name,name_kana,pwd,mail,type){
	var user_id_field=document.getElementById("user_id");
	var name_field=document.getElementById("name");
	var name_kana_field=document.getElementById("name_kana");
	var pwd_field=document.getElementById("pwd");
	var confirm_pwd_field=document.getElementById("confirm_pwd");
	var mail_field=document.getElementById("mail");
	var type_field=document.getElementsByName("type");
	user_id_field.value=user_id;
	name_field.value=name;
	name_kana_field.value=name_kana;
	pwd_field.value=pwd;
	confirm_pwd_field.value=pwd;
	mail_field.value=mail;
	if(type=='f')
		type_field[0].checked=true;
		 else if(type=='c')
		 	type_field[1].checked=true;
}

//functions of navigation bar (developed by Mr Okada)
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


function sub_search2(work,search_order,type){
	var work_str=document.getElementById(work).value.toString();
	var search_order_str=document.getElementById(search_order).value.toString();
	 if(type=='f')
		window.navigate('http://www.freelancer.jp/find-an-employee/fr_list.php?f_work='+work_str+'&f_search_order='+search_order_str);
		else
		window.navigate('http://www.freelancer.jp/find-a-job/c_list.php?c_work='+work_str+'&c_search_order='+search_order_str);
}
//
//initiate user type 
//function intiate_window(index_id){
//	var array=document.getElementById(index_id);
//	alert(array.id);
//	array.click();
//}