function ini_ajax () {
    try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
    try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
    alert("XML Http Request not support.")
    return null
}

function login()
{	
	if ( document.getElementById("uname").value=="" || document.getElementById("pass").value=="" )
	{
		alert("Invalid Login");
	}
	else
	{
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText!=0)	{
					window.location.reload();
					//document.getElementById('member_zone').innerHTML=req.responseText;
					//window.open("user/user.php", "_self");
				} else 	{
					alert("Login fail!!");
					document.getElementById("uname").value="";
					document.getElementById("pass").value="";
				}
				//document.getElementById('wait').innerHTML="";
			} else {
				//document.getElementById('wait').innerHTML="<img src='images/wait.gif'></img>";
			}
		}

		var str=Math.random();
		url="login.php";
		url+="?time="+str;
		para="&uname="+encodeURIComponent(document.getElementById("uname").value);
		para+="&pass="+encodeURIComponent(document.getElementById("pass").value);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	}
}

function login2(page)
{	
	if ( document.getElementById("uname2").value=="" || document.getElementById("pass2").value=="" )
	{
		alert("Invalid Login");
	}
	else
	{
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==2)	{					
					window.open("index.php?module=post_job&step=2", "_self");
				} else if (req.responseText!=0)	{
					document.getElementById('member_zone').innerHTML=req.responseText;
				} else {
					alert("Login fail!!");
					document.getElementById("uname2").value="";
					document.getElementById("pass2").value="";
				}
				//document.getElementById('wait').innerHTML="";
			} else {
				//document.getElementById('wait').innerHTML="<img src='images/wait.gif'></img>";
			}
		}

		var str=Math.random();
		url="login.php";
		url+="?time="+str;
		para="&uname="+encodeURIComponent(document.getElementById("uname2").value);
		para+="&pass="+encodeURIComponent(document.getElementById("pass2").value);
		para+="&page="+encodeURIComponent(page);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	}
}

//Add by Manasanan on 19 Dec 2009
function login_new(page)
{		
	if ( document.getElementById("uname").value=="" || document.getElementById("pass").value=="" )
	{
		alert("Invalid Login");
	}
	else
	{
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText!=0)	{	
					if ( encodeURIComponent(page) != "") 
						window.location.reload();
					else 
						window.open("index.php?module=home", "_self");
					//document.getElementById('member_zone').innerHTML=req.responseText;
					//window.open("user/user.php", "_self");
				} else 	{
					
					alert("Login fail!!");
					document.getElementById("uname").value="";
					document.getElementById("pass").value="";
				}
				//document.getElementById('wait').innerHTML="";
			} else {
				//document.getElementById('wait').innerHTML="<img src='images/wait.gif'></img>";
			}
		}

		var str=Math.random();
		url="login.php";
		url+="?time="+str;
		para="&uname="+encodeURIComponent(document.getElementById("uname").value);
		para+="&pass="+encodeURIComponent(document.getElementById("pass").value);
		//alert(para + url);		
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	}	
}

function logout()
{
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			if (req.responseText==1)
			{
				window.open("index.php", "_self");
			}
		}
	}

	var str=Math.random();
	var querystr="";
	querystr+="logout.php";
	querystr+="?time="+str;
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(null);
}

function show(x,y)
{	
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			var a=document.getElementById(y);
			a.innerHTML=req.responseText;
			//document.getElementById('wait').innerHTML="";
		} else {
			//document.getElementById('wait').innerHTML="<img src='images/wait.gif'></img>";
		}
	}

	var str=Math.random();
	var querystr="";
	querystr+=x+".php";
	querystr+="?time="+str;
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(null);
}

function regis(x)
{
	if (x=='2')
	{			
		if (document.getElementById("username_status").value=="ok" && document.getElementById("password_status").value=="ok" && document.getElementById("password2_status").value=="ok" && document.getElementById("fname_status").value=="ok" && document.getElementById("lname_status").value=="ok" && document.getElementById("mobileno_status").value=="ok" && document.getElementById("phoneno_status").value=="ok" && document.getElementById("email_status").value=="ok" && document.getElementById("email2_status").value=="ok")
		{	
			document.getElementById('username_h').value=document.getElementById('username').value;
			document.getElementById('password_h').value=document.getElementById('password').value;
			document.getElementById("fname_h").value=document.getElementById("fname").value;
			document.getElementById("lname_h").value=document.getElementById("lname").value;
			document.getElementById("country_h").value=document.getElementById("country").value;
			document.getElementById("province_h").value=document.getElementById("province").value;
			document.getElementById("amper_h").value=document.getElementById("amper").value;
			document.getElementById("address_h").value=document.getElementById("address").value;
			document.getElementById("mobileno_h").value=document.getElementById("mobileno").value;
			document.getElementById("phoneno_h").value=document.getElementById("phoneno").value;
			document.getElementById("email_h").value=document.getElementById("email").value;
			document.getElementById("website_h").value=document.getElementById("website").value;
			document.getElementById("facebook_h").value=document.getElementById("facebook").value;
			document.getElementById("hi5_h").value=document.getElementById("hi5").value;
			document.getElementById("multiply_h").value=document.getElementById("multiply").value;
			document.getElementById("twitter_h").value=document.getElementById("twitter").value;
			document.getElementById("other_h").value=document.getElementById("other").value;
			show('regis_step2','regis_data');
		} else {
			//alert("กรุณากรอกข้อมูลให้ครบถ้วน");
			if (document.getElementById("username_status").value!="ok") { document.getElementById("username").focus(); alert("กรุณากรอกข้อมูล username");document.getElementById("error").innerHtml="กรุณากรอก username"; return false; }
			if (document.getElementById("password_status").value!="ok") { document.getElementById("password").focus(); alert("กรุณากรอกข้อมูล password");document.getElementById("error").innerHtml="กรุณากรอก password"; return false; }
			if (document.getElementById("password2_status").value!="ok") { document.getElementById("password2").focus(); alert("กรุณากรอกข้อมูลยืนยัน password");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน password"; return false; }
			if (document.getElementById("fname_status").value!="ok") { document.getElementById("fname").focus(); alert("กรุณากรอกข้อมูล ชื่อ");document.getElementById("error").innerHtml="กรุณากรอก ชื่อ"; return false; }
			if (document.getElementById("lname_status").value!="ok") { document.getElementById("lname").focus(); alert("กรุณากรอกข้อมูล นามสกุล");document.getElementById("error").innerHtml="กรุณากรอก นามสกุล"; return false; }
			if (document.getElementById("mobileno_status").value!="ok") { document.getElementById("mobileno").focus(); alert("กรุณากรอกข้อมูล เบอร์โทรศัพท์มือถือ");document.getElementById("error").innerHtml="กรุณากรอก เบอร์โทรศัพท์มือถือ"; return false; }
			if (document.getElementById("phoneno_status").value!="ok") { document.getElementById("phoneno").focus(); alert("กรุณากรอกข้อมูล  เบอร์โทรศัพท์");document.getElementById("error").innerHtml="กรุณากรอก  เบอร์โทรศัพท์"; return false; }
			if (document.getElementById("email_status").value!="ok") { document.getElementById("email").focus(); alert("กรุณากรอกข้อมูล email");document.getElementById("error").innerHtml="กรุณากรอก email"; return false; }
			if (document.getElementById("email2_status").value!="ok") { document.getElementById("email2").focus(); alert("กรุณากรอกข้อมูลยืนยัน email");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน email"; return false; }
		}
	}
	if (x=='3')
	{
		if (document.getElementById("cate_status").value=="ok" && document.getElementById("catesub_status").value=="ok" && document.getElementById("skill_status").value=="ok" )
		{
			for (i=1;i<=5 ;i++ )
			{
				document.getElementById('cate'+i+'_h').value=document.getElementById('cs'+i).value;
			}
			for (i=1;i<=10 ;i++ )
			{
				document.getElementById('skill'+i+'_h').value=document.getElementById('ss'+i).value;
			}
			
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					document.getElementById("regis_data").innerHTML=req.responseText;
					//document.getElementById('wait').innerHTML="";
				} else {
					//document.getElementById('wait').innerHTML="<img src='images/wait.gif'></img>";
				}
			}
			var str=Math.random();
			var url="";
			url+="regis_step3.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&password="+encodeURIComponent(document.getElementById('password_h').value);
			para+="&fname="+encodeURIComponent(document.getElementById('fname_h').value);
			para+="&lname="+encodeURIComponent(document.getElementById('lname_h').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&address="+encodeURIComponent(document.getElementById("address_h").value);
			para+="&mobileno="+encodeURIComponent(document.getElementById("mobileno_h").value);
			para+="&phoneno="+encodeURIComponent(document.getElementById("phoneno_h").value);
			para+="&email="+encodeURIComponent(document.getElementById("email_h").value);
			para+="&website="+encodeURIComponent(document.getElementById("website_h").value);
			para+="&facebook="+encodeURIComponent(document.getElementById("facebook_h").value);
			para+="&hi5="+encodeURIComponent(document.getElementById("hi5_h").value);
			para+="&multiply="+encodeURIComponent(document.getElementById("multiply_h").value);
			para+="&twitter="+encodeURIComponent(document.getElementById("twitter_h").value);
			para+="&other="+encodeURIComponent(document.getElementById("other_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&cate"+i+"="+encodeURIComponent(document.getElementById('cate'+i+'_h').value);
			}
			for (i=1;i<=10 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}

			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);

		} else {
			//alert("กรุณากรอกข้อมูลให้ครบถ้วน");
			if (document.getElementById("cate_status").value!="ok") { document.getElementById("cate").focus();alert("กรุณาเลือกหมวดหลัก");document.getElementById("error").innerHtml="กรุณาเลือกหมวดหลัก"; return false; }
			if (document.getElementById("catesub_status").value!="ok") { document.getElementById("catesub").focus();alert("กรุณาเลือกหมวดย่อย");document.getElementById("error").innerHtml="กรุณาเลือกหมวดย่อย"; return false; }
			if (document.getElementById("skill_status").value!="ok") { alert("กรุณาเลือกทักษะ");document.getElementById("error").innerHtml="กรุณาเลือกทักษะ"; return false; }
		}

	}
	if (x=='end')
	{
		if (document.getElementById("checkbox").checked) {
			if (confirm('ยืนยันการทำรายการ'))
			{
				var req = ini_ajax();
				req.onreadystatechange=function()
				{
					if (req.readyState==4)
					{
						//alert(req.responseText);
						if (req.responseText==1)	{
							//alert("Regis OK!!");
							window.open("index.php?module=complete&p=regis", "_self");
						} else 	{
							alert("Regis fail!!");
						}
					}
				}
				var str=Math.random();
				var url="";
				url+="regis_add.php";
				url+="?time="+str;
				para="&username="+encodeURIComponent(document.getElementById('username_h').value);
				para+="&password="+encodeURIComponent(document.getElementById('password_h').value);
				para+="&fname="+encodeURIComponent(document.getElementById('fname_h').value);
				para+="&lname="+encodeURIComponent(document.getElementById('lname_h').value);
				para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
				para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
				para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
				para+="&address="+encodeURIComponent(document.getElementById("address_h").value);
				para+="&mobileno="+encodeURIComponent(document.getElementById("mobileno_h").value);
				para+="&phoneno="+encodeURIComponent(document.getElementById("phoneno_h").value);
				para+="&email="+encodeURIComponent(document.getElementById("email_h").value);
				para+="&website="+encodeURIComponent(document.getElementById("website_h").value);
				para+="&facebook="+encodeURIComponent(document.getElementById("facebook_h").value);
				para+="&hi5="+encodeURIComponent(document.getElementById("hi5_h").value);
				para+="&multiply="+encodeURIComponent(document.getElementById("multiply_h").value);
				para+="&twitter="+encodeURIComponent(document.getElementById("twitter_h").value);
				para+="&other="+encodeURIComponent(document.getElementById("other_h").value);
				for (i=1;i<=5 ;i++ )
				{
					para+="&cate"+i+"="+encodeURIComponent(document.getElementById('cate'+i+'_h').value);
				}
				for (i=1;i<=10 ;i++ )
				{
					para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
				}

				//alert(para);
				req.open("POST", url , true);
				req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				req.send(para);
			}
		} else {
			alert("กรุณายอมรับเงื่อนไข");
		}
	}
}

function get_checkbox(x,y,z)
{
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert("checl = "+x+"="+req.responseText);
			document.getElementById(x+"_check").innerHTML=req.responseText;	
			if (x=="catesub")
			{
				for(i=1;i<=5; i++)
				{
					if (z!="edit")
					{
						document.getElementById('cs'+i).value="";
						document.getElementById('c'+i).innerHTML="";					
						document.getElementById('catesub_s').innerHTML="<img src='images/cross.gif'>";
						document.getElementById('catesub_status').value="no";
					}
				}
			} else if (x=="skill") {
				for(i=1;i<=y; i++)
				{	
					if (z!="edit")
					{				
						document.getElementById('ss'+i).value="";
						document.getElementById('s'+i).innerHTML="";					
						document.getElementById('skill_s').innerHTML="<img src='images/cross.gif'>";
						document.getElementById('skill_status').value="no";
					}
				}
			}			
		}
	}
	var str=Math.random();
	var url="";
	url+="get_checkbox_"+x+".php";
	url+="?time="+str;
	para="&cat="+encodeURIComponent(document.getElementById("cate").value);
	para+="&get="+encodeURIComponent(x);
	para+="&y="+encodeURIComponent(y);
	para+="&edit="+encodeURIComponent(z);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function check_reg(x)
{
	if (x=="password2")	{
		val = '&val='+encodeURIComponent(document.getElementById('password').value)+'&val2='+encodeURIComponent(document.getElementById(x).value);
	} else if (x=="email2")	{
		val = '&val='+encodeURIComponent(document.getElementById('email').value)+'&val2='+encodeURIComponent(document.getElementById(x).value);
	}  else if (x=="emailedit2")	{
		val = '&val='+encodeURIComponent(document.getElementById('emailedit').value)+'&val2='+encodeURIComponent(document.getElementById(x).value);
	} else {
		val = '&val='+encodeURIComponent(document.getElementById(x).value);
	}

	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert("checl = "+x+"="+req.responseText);
			if (req.responseText==0)	{
				document.getElementById(x+"_s").innerHTML="<img src='images/tick.gif'>";
				document.getElementById(x+"_status").value="ok";
			} else {
				document.getElementById(x+"_s").innerHTML="<img src='images/cross.gif'>";
				document.getElementById(x+"_status").value="no";
			}
		}
	}
	var str=Math.random();
	var url="";
	url+="check_reg.php";
	url+="?time="+str;
	para="&check="+encodeURIComponent(x);
	para+=val;
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function add_cate(x)
{
	if (document.getElementById("sub_"+x).checked==true)
	{
		for(i=1;i<=5; i++)
		{
			if (document.getElementById('cs'+i).value=="")
			{				
				document.getElementById('cs'+i).value=x;
				
				var i2=i;
				var req = ini_ajax();
				req.onreadystatechange=function()
				{
					if (req.readyState==4)
					{			
						//alert(req.responseText);						
						document.getElementById('c'+i2).innerHTML = req.responseText+" - "+document.getElementById("sub_"+x).value;
					}
				}

				var str=Math.random();
				var querystr="";
				querystr+="get_catname.php";
				querystr+="?time="+str;
				para="&cat="+encodeURIComponent(x);
				//alert(para);
				req.open("POST", querystr , true);
				req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				req.send(para);

				break;
			}
		}
		if (i==6)
		{
			alert("เลือกได้ไม่เกิน 5");
			document.getElementById('sub_'+x).checked=false;
		}
	} else if (document.getElementById("sub_"+x).checked==false) {
		
		for(i=1;i<=5; i++)
		{
			if (document.getElementById('cs'+i).value==x)
			{				
				document.getElementById('cs'+i).value="";
				document.getElementById('c'+i).innerHTML="";
				break;
			}
		}
		for(i=1;i<=5; i++)
		{
			if (document.getElementById('cs'+i).value=="")
			{	
				for(j=i;j<=5; j++)
				{
					if (document.getElementById('cs'+j).value!="")
					{				
						document.getElementById('cs'+i).value=document.getElementById('cs'+j).value;						
						document.getElementById('cs'+j).value="";
						document.getElementById('c'+i).innerHTML=document.getElementById('c'+j).innerHTML;
						document.getElementById('c'+j).innerHTML="";
						break;
					}
				}
			}
		}
	}

	for(i=1;i<=5; i++)
	{
		if (document.getElementById('cs'+i).value!="")
		{				
			document.getElementById('catesub_s').innerHTML="<img src='images/tick.gif'>";
			document.getElementById('catesub_status').value="ok";
			break;
		} else if (i==5 && document.getElementById('cs'+i).value=="") {
			document.getElementById('catesub_s').innerHTML="<img src='images/cross.gif'>";
			document.getElementById('catesub_status').value="no";
		}
	}
}


function add_skill(x,y)
{
	if (document.getElementById("skill_"+x).checked==true)
	{
		for(i=1;i<=y; i++)
		{
			if (document.getElementById('ss'+i).value=="")
			{				
				document.getElementById('ss'+i).value=x;
				document.getElementById('s'+i).innerHTML=document.getElementById("skill_"+x).value;
				break;
			}
		}
		yy=y+1;
		if (i==yy)
		{
			alert("เลือกได้ไม่เกิน "+y);
			document.getElementById('skill_'+x).checked=false;
		}
	} else if (document.getElementById("skill_"+x).checked==false) {
		
		for(i=1;i<=y; i++)
		{
			if (document.getElementById('ss'+i).value==x)
			{				
				document.getElementById('ss'+i).value="";
				document.getElementById('s'+i).innerHTML="";
				break;
			}
		}
		for(i=1;i<=y; i++)
		{
			if (document.getElementById('ss'+i).value=="")
			{	
				for(j=i;j<=y; j++)
				{
					if (document.getElementById('ss'+j).value!="")
					{				
						document.getElementById('ss'+i).value=document.getElementById('ss'+j).value;						
						document.getElementById('ss'+j).value="";
						document.getElementById('s'+i).innerHTML=document.getElementById('s'+j).innerHTML;
						document.getElementById('s'+j).innerHTML="";
						break;
					}
				}
			}
		}
	}

	for(i=1;i<=y; i++)
	{
		if (document.getElementById('s'+i).innerHTML!="")
		{				
			document.getElementById('skill_s').innerHTML="<img src='images/tick.gif'>";
			document.getElementById('skill_status').value="ok";
			break;
		} else if (i==y && document.getElementById('s'+i).innerHTML=="") {
			document.getElementById('skill_s').innerHTML="<img src='images/cross.gif'>";
			document.getElementById('skill_status').value="no";
		}
	}
}

function get_live(x,y,z)
{
	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{			
			//alert(req.responseText);
			var a=document.getElementById(y);
			a.innerHTML=req.responseText;
			if (x=="province")
			{
				if (z!="")
				{
					get_live('amper','sel_amper',z);
				} else {
					get_live('amper','sel_amper');
				}
			}
			//document.getElementById('wait').innerHTML="";
		} else {
			//document.getElementById('wait').innerHTML="<img src='../images/wait.gif'></img>";
		}
	}

	var str=Math.random();
	var querystr="";
	querystr+="get_live.php";
	querystr+="?time="+str;
	para="&get="+encodeURIComponent(x);
	if (x=="province")
	{
		para+="&val="+encodeURIComponent(document.getElementById('country').value);
	} else if (x=="amper") {
		para+="&val="+encodeURIComponent(document.getElementById('province').value);
	}
	para+="&from="+encodeURIComponent(z);
	//alert(para);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}


function post_job(x)
{
	if (x=='2')
	{	
		//alert(x);
		if (document.getElementById("username_status").value=="ok" && document.getElementById("password_status").value=="ok" && document.getElementById("password2_status").value=="ok" && document.getElementById("fname_status").value=="ok" && document.getElementById("lname_status").value=="ok" && document.getElementById("mobileno_status").value=="ok" && document.getElementById("phoneno_status").value=="ok" && document.getElementById("email_status").value=="ok" && document.getElementById("email2_status").value=="ok" && document.getElementById("checkbox").checked)
		{		
			to_h('username_h','username');
			regis_h();
			//show('post_job_step2','post_job_data');
		} else {
			//alert("กรุณากรอกข้อมูลให้ครบถ้วน");
			if (document.getElementById("username_status").value!="ok") { document.getElementById("username").focus(); alert("กรุณากรอกข้อมูล username");document.getElementById("error").innerHtml="กรุณากรอก username"; return false; }
			if (document.getElementById("password_status").value!="ok") { document.getElementById("password").focus(); alert("กรุณากรอกข้อมูล password");document.getElementById("error").innerHtml="กรุณากรอก password"; return false; }
			if (document.getElementById("password2_status").value!="ok") { document.getElementById("password2").focus(); alert("กรุณากรอกข้อมูลยืนยัน password");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน password"; return false; }
			if (document.getElementById("fname_status").value!="ok") { document.getElementById("fname").focus(); alert("กรุณากรอกข้อมูล ชื่อ");document.getElementById("error").innerHtml="กรุณากรอก ชื่อ"; return false; }
			if (document.getElementById("lname_status").value!="ok") { document.getElementById("lname").focus(); alert("กรุณากรอกข้อมูล นามสกุล");document.getElementById("error").innerHtml="กรุณากรอก นามสกุล"; return false; }
			if (document.getElementById("mobileno_status").value!="ok") { document.getElementById("mobileno").focus(); alert("กรุณากรอกข้อมูล เบอร์โทรศัพท์มือถือ");document.getElementById("error").innerHtml="กรุณากรอก เบอร์โทรศัพท์มือถือ"; return false; }
			if (document.getElementById("phoneno_status").value!="ok") { document.getElementById("phoneno").focus(); alert("กรุณากรอกข้อมูล  เบอร์โทรศัพท์");document.getElementById("error").innerHtml="กรุณากรอก  เบอร์โทรศัพท์"; return false; }
			if (document.getElementById("email_status").value!="ok") { document.getElementById("email").focus(); alert("กรุณากรอกข้อมูล email");document.getElementById("error").innerHtml="กรุณากรอก email"; return false; }
			if (document.getElementById("email2_status").value!="ok") { document.getElementById("email2").focus(); alert("กรุณากรอกข้อมูลยืนยัน email");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน email"; return false; }
		}
	}
	if (x=='3')
	{	
		if (document.getElementById("topic_status").value=="ok" && document.getElementById("cate_status").value=="ok" && document.getElementById("catesub_status").value=="ok")
		{
			text_to_jv("detail","detail_h");
			//alert("username="+document.getElementById('username_h').value);
			for (i=1;i<=5 ;i++ )
			{
				document.getElementById('skill'+i+'_h').value=document.getElementById('ss'+i).value;
			}
			to_h('topic_h','topic');
			to_h('cate_h','cate');
			to_h('catesub_h','catesub');			
			to_h('xcate_h','xcate');
			to_h('detail_h','detail');
			to_h('xskill_h','xskill');
			to_h('country_h','country');
			to_h('province_h','province');
			to_h('amper_h','amper');
			to_h('period_h','period');
			to_h('price_h','price');
			to_h('postperiod_h','postperiod');
			to_h('eststart_h','eststart');
			//alert(document.getElementById("detail").value);
			//show('post_job_step3','post_job_data');
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					document.getElementById('post_job_data').innerHTML=req.responseText;
					//alert(document.getElementById("detail_h").value);
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_step3.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}
			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		} else {			
			if (document.getElementById("topic_status").value!="ok") { document.getElementById("topic").focus();alert("กรุณากรอกข้อมูล Topic");document.getElementById("error").innerHtml="กรุณากรอก Topic"; return false; }
			if (document.getElementById("cate_status").value!="ok") { document.getElementById("cate").focus();alert("กรุณาเลือกหมวดหลัก");document.getElementById("error").innerHtml="กรุณาเลือกหมวดหลัก"; return false; }
			if (document.getElementById("catesub_status").value!="ok") { document.getElementById("catesub").focus();alert("กรุณาเลือกหมวดย่อย");document.getElementById("error").innerHtml="กรุณาเลือกหมวดย่อย"; return false; }
			if (document.getElementById("skill_status").value!="ok") { alert("กรุณาเลือกทักษะ");document.getElementById("error").innerHtml="กรุณาเลือกทักษะ"; return false; }
		}
	}
	if (x=='end')
	{
		if (confirm('ยืนยันการทำรายการ'))
		{
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					if (req.responseText!=0)	{
						//alert("post job OK!!");
						window.open(req.responseText, "_self");
					} else 	{
						alert("post job fail!!");
						alert(req.responseText);
					}
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_add.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}

			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		}
	}
}

function post_job_new(x)
{
	if (x=='checkmember_step3')
	{	
		if (document.getElementById("username_status").value=="ok" && document.getElementById("password_status").value=="ok" && document.getElementById("password2_status").value=="ok" && document.getElementById("fname_status").value=="ok" && document.getElementById("lname_status").value=="ok" && document.getElementById("mobileno_status").value=="ok" && document.getElementById("phoneno_status").value=="ok" && document.getElementById("email_status").value=="ok" && document.getElementById("email2_status").value=="ok" && document.getElementById("checkbox").checked)
		{		
			to_h('username_h','username');
			regis_h();					
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					document.getElementById('post_job_data').innerHTML=req.responseText;
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_step3.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			para+="&password="+encodeURIComponent(document.getElementById('password').value);
			para+="&fname="+encodeURIComponent(document.getElementById('fname').value);
			para+="&lname="+encodeURIComponent(document.getElementById('lname').value);
			para+="&mobileno="+encodeURIComponent(document.getElementById("mobileno").value);
			para+="&phoneno="+encodeURIComponent(document.getElementById("phoneno").value);
			para+="&email="+encodeURIComponent(document.getElementById("email").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		} else {
			if (document.getElementById("username_status").value!="ok") { document.getElementById("username").focus(); alert("กรุณากรอกข้อมูล username");document.getElementById("error").innerHtml="กรุณากรอก username"; return false; }
			if (document.getElementById("password_status").value!="ok") { document.getElementById("password").focus(); alert("กรุณากรอกข้อมูล password");document.getElementById("error").innerHtml="กรุณากรอก password"; return false; }
			if (document.getElementById("password2_status").value!="ok") { document.getElementById("password2").focus(); alert("กรุณากรอกข้อมูลยืนยัน password");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน password"; return false; }
			if (document.getElementById("fname_status").value!="ok") { document.getElementById("fname").focus(); alert("กรุณากรอกข้อมูล ชื่อ");document.getElementById("error").innerHtml="กรุณากรอก ชื่อ"; return false; }
			if (document.getElementById("lname_status").value!="ok") { document.getElementById("lname").focus(); alert("กรุณากรอกข้อมูล นามสกุล");document.getElementById("error").innerHtml="กรุณากรอก นามสกุล"; return false; }
			if (document.getElementById("mobileno_status").value!="ok") { document.getElementById("mobileno").focus(); alert("กรุณากรอกข้อมูล เบอร์โทรศัพท์มือถือ");document.getElementById("error").innerHtml="กรุณากรอก เบอร์โทรศัพท์มือถือ"; return false; }
			if (document.getElementById("phoneno_status").value!="ok") { document.getElementById("phoneno").focus(); alert("กรุณากรอกข้อมูล  เบอร์โทรศัพท์");document.getElementById("error").innerHtml="กรุณากรอก  เบอร์โทรศัพท์"; return false; }
			if (document.getElementById("email_status").value!="ok") { document.getElementById("email").focus(); alert("กรุณากรอกข้อมูล email");document.getElementById("error").innerHtml="กรุณากรอก email"; return false; }
			if (document.getElementById("email2_status").value!="ok") { document.getElementById("email2").focus(); alert("กรุณากรอกข้อมูลยืนยัน email");document.getElementById("error").innerHtml="กรุณากรอกยืนยัน email"; return false; }
		}
	}
	if (x=='check_regis')
	{	
		if (document.getElementById("topic_status").value=="ok" && document.getElementById("cate_status").value=="ok" && document.getElementById("catesub_status").value=="ok")
		{
			text_to_jv("detail","detail_h");
			//alert("username="+document.getElementById('username_h').value);
			for (i=1;i<=5 ;i++ )
			{
				document.getElementById('skill'+i+'_h').value=document.getElementById('ss'+i).value;
			}
			to_h('topic_h','topic');
			to_h('cate_h','cate');
			to_h('catesub_h','catesub');			
			to_h('xcate_h','xcate');
			to_h('detail_h','detail');
			to_h('xskill_h','xskill');
			to_h('country_h','country');
			to_h('province_h','province');
			to_h('amper_h','amper');
			to_h('period_h','period');
			to_h('price_h','price');
			to_h('postperiod_h','postperiod');
			to_h('eststart_h','eststart');
			//alert(document.getElementById("detail").value);
			//show('post_job_step3','post_job_data');
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					document.getElementById('post_job_data').innerHTML=req.responseText;
					//alert(document.getElementById("detail_h").value);
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_step1.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}
			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		} else {			
			if (document.getElementById("topic_status").value!="ok") { document.getElementById("topic").focus();alert("กรุณากรอกข้อมูล Topic");document.getElementById("error").innerHtml="กรุณากรอก Topic"; return false; }
			if (document.getElementById("cate_status").value!="ok") { document.getElementById("cate").focus();alert("กรุณาเลือกหมวดหลัก");document.getElementById("error").innerHtml="กรุณาเลือกหมวดหลัก"; return false; }
			if (document.getElementById("catesub_status").value!="ok") { document.getElementById("catesub").focus();alert("กรุณาเลือกหมวดย่อย");document.getElementById("error").innerHtml="กรุณาเลือกหมวดย่อย"; return false; }
			if (document.getElementById("skill_status").value!="ok") { alert("กรุณาเลือกทักษะ");document.getElementById("error").innerHtml="กรุณาเลือกทักษะ"; return false; }
		}
	}
	if (x=='check_step3')
	{	
		if (document.getElementById("topic_status").value=="ok" && document.getElementById("cate_status").value=="ok" && document.getElementById("catesub_status").value=="ok")
		{
			text_to_jv("detail","detail_h");
			for (i=1;i<=5 ;i++ )
			{
				document.getElementById('skill'+i+'_h').value=document.getElementById('ss'+i).value;
			}
			to_h('topic_h','topic');
			to_h('cate_h','cate');
			to_h('catesub_h','catesub');			
			to_h('xcate_h','xcate');
			to_h('detail_h','detail');
			to_h('xskill_h','xskill');
			to_h('country_h','country');
			to_h('province_h','province');
			to_h('amper_h','amper');
			to_h('period_h','period');
			to_h('price_h','price');
			to_h('postperiod_h','postperiod');
			to_h('eststart_h','eststart');
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					document.getElementById('post_job_data').innerHTML=req.responseText;
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_step3.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		} else {			
			if (document.getElementById("topic_status").value!="ok") { document.getElementById("topic").focus();alert("กรุณากรอกข้อมูล Topic");document.getElementById("error").innerHtml="กรุณากรอก Topic"; return false; }
			if (document.getElementById("cate_status").value!="ok") { document.getElementById("cate").focus();alert("กรุณาเลือกหมวดหลัก");document.getElementById("error").innerHtml="กรุณาเลือกหมวดหลัก"; return false; }
			if (document.getElementById("catesub_status").value!="ok") { document.getElementById("catesub").focus();alert("กรุณาเลือกหมวดย่อย");document.getElementById("error").innerHtml="กรุณาเลือกหมวดย่อย"; return false; }
			if (document.getElementById("skill_status").value!="ok") { alert("กรุณาเลือกทักษะ");document.getElementById("error").innerHtml="กรุณาเลือกทักษะ"; return false; }
		}
	}
	if (x=='save_job')
	{
		if (confirm('ยืนยันการทำรายการ'))
		{
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					if (req.responseText!=0)	{
						window.open(req.responseText, "_self");
					} else 	{
						alert("post job fail!!");
						alert(req.responseText);
					}
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_add.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		}
	}
	if (x=='save_member_job')
	{
		if (confirm('ยืนยันการทำรายการ'))
		{	
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					if (req.responseText!=0)	{
						//alert("post job OK!!");
						window.open(req.responseText, "_self");
						//window.open("index.php?module=main&cat=DM", "_self");
					} else 	{
						alert("post job fail!!");
						alert(req.responseText);
					}
				}
			}
			var str=Math.random();
			var url="";
			url+="post_job_add.php";
			url+="?time="+str;
			para="&username="+encodeURIComponent(document.getElementById('username_h').value);
			para+="&invite="+encodeURIComponent(document.getElementById('invite').value);
			para+="&country="+encodeURIComponent(document.getElementById('country_h').value);
			para+="&province="+encodeURIComponent(document.getElementById("province_h").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper_h").value);
			para+="&topic="+encodeURIComponent(document.getElementById("topic_h").value);
			para+="&cate="+encodeURIComponent(document.getElementById("cate_h").value);
			para+="&cate_sub="+encodeURIComponent(document.getElementById("catesub_h").value);
			para+="&xcate="+encodeURIComponent(document.getElementById("xcate_h").value);
			para+="&detail="+encodeURIComponent(document.getElementById("detail_h").value);
			para+="&xskill="+encodeURIComponent(document.getElementById("xskill_h").value);
			para+="&price="+encodeURIComponent(document.getElementById("price_h").value);
			para+="&period="+encodeURIComponent(document.getElementById("period_h").value);
			para+="&postperiod="+encodeURIComponent(document.getElementById("postperiod_h").value);
			para+="&eststart="+encodeURIComponent(document.getElementById("eststart_h").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('skill'+i+'_h').value);
			}

			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		}
	}
}

function regis_h()
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{			
			//window.open("index.php?module=main&cat=DM", "_self");
		}
	}
	var str=Math.random();
	var querystr="";
	querystr+="regis_h_add.php";
	querystr+="?time="+str;
	para="&username="+encodeURIComponent(document.getElementById('username').value);
	para+="&password="+encodeURIComponent(document.getElementById('password').value);
	para+="&fname="+encodeURIComponent(document.getElementById('fname').value);
	para+="&lname="+encodeURIComponent(document.getElementById('lname').value);
	para+="&mobileno="+encodeURIComponent(document.getElementById("mobileno").value);
	para+="&phoneno="+encodeURIComponent(document.getElementById("phoneno").value);
	para+="&email="+encodeURIComponent(document.getElementById("email").value);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);	
}

function post_job_invite(inv)
{	
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		
		if (req.readyState==4)
		{
			document.getElementById('post_job_top').innerHTML=req.responseText;
		}
		
	}

	var str=Math.random();
	var querystr="";
	querystr+="post_job_invite.php";
	querystr+="?time="+str;
	para="&invite="+encodeURIComponent(inv);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);	
}

function cate_option() {
	
	
		var req = ini_ajax();
		
		req.onreadystatechange=function()
		{
			
			if (req.readyState==4)
			{
				document.getElementById('csub').innerHTML=req.responseText;
			}
			
		}

		var str=Math.random();
		var querystr="";
		querystr+="cate_option.php";
		querystr+="?time="+str;
		para="&cate="+encodeURIComponent(document.getElementById('cate').value);
		req.open("POST", querystr , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);	
	if (document.getElementById('cate').value=="OT")
	{
		document.getElementById('othercate').innerHTML='กรุณาใส่รายละเอียดของหมวดอื่นๆ<br /><input id="xcate" type="text" size="30" maxlength="30" />(เช่น เดินกล้องวงจรปิด , ส่งของ)';
	}		
}

function text_to_jv(x,y) {
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById(y).value=req.responseText;
		}
		
	}

	var str=Math.random();
	var querystr="";
	querystr+="text_to_jv.php";
	querystr+="?time="+str;
	para="&text="+encodeURIComponent(document.getElementById(x).value);
	//alert(para);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);			
}

function to_h(x,y) {
	document.getElementById(x).value=document.getElementById(y).value;	
}

function get_catesub(page,cate) {
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('search_data').innerHTML=req.responseText;
			get_data(page,'0','1');
		}
		
	}

	var str=Math.random();
	var querystr="";
	querystr+="search_form.php";
	querystr+="?time="+str;
	para="&cate="+encodeURIComponent(cate);
	para+="&page="+encodeURIComponent(document.getElementById('page').value);
	//alert(para);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);			
}

function get_data(page,y,p) {
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById(page+'_data').innerHTML=req.responseText;
			document.getElementById("show_count").innerHTML=document.getElementById("sc").value;
			document.getElementById('search').value="";
		}
		
	}

	var str=Math.random();
	var querystr="";
	querystr+=page+"_data.php";
	querystr+="?time="+str;
	para="&cateid="+encodeURIComponent(document.getElementById('cateid').value);
	para+="&page="+(p);
	para+="&search="+document.getElementById('search').value;	
	
	if (document.getElementById('sub').value!="")
	{
		para+="&sub="+document.getElementById('sub').value;
		
		for (i=1;i<=document.getElementById('sub').value ;i++ )
		{
			if (document.getElementById('catesub'+i).checked)
			{
				//alert(document.getElementById('catesub'+i).value);
				para+="&catesubid"+i+"="+document.getElementById('catesub'+i).value;
			}
		}
	}
	para+="&countrycode="+encodeURIComponent(document.getElementById('country').value);
	para+="&provincecode="+encodeURIComponent(document.getElementById('province').value);
	para+="&citycode="+encodeURIComponent(document.getElementById('amper').value);
	if (document.getElementById('sel2').checked)
	{
		para+="&sel2="+encodeURIComponent(document.getElementById('sel2').value);
	}
	if (page=="find_job")
	{
		if (document.getElementById('sel1').checked)
		{
			para+="&sel1="+encodeURIComponent(document.getElementById('sel1').value);
		}
		para+="&price="+encodeURIComponent(document.getElementById('price').value);
		para+="&period="+encodeURIComponent(document.getElementById('period').value);
	} else if (page=="find_x") {
		para+="&skill="+encodeURIComponent(document.getElementById('skill').value);
	}

	//alert(para);
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);			
}

function popme(page,v,w,h) 
{
	url = page+".php";
	if (v!="")
	{
		url+=v;
	}
	window.open(url,null,"height="+h+",width="+w+",toolbar=no,menubar=no,location=no");
}

function look_offer(jobid,offerid,x) {
	if (document.getElementById('offer'+x).innerHTML!="")
	{
		document.getElementById('offer'+x).innerHTML="";
		document.getElementById('lnk'+x).innerHTML="<img src='images/button/plus.gif' border='0'>";
	} else {
		var req = ini_ajax();
		
		req.onreadystatechange=function()
		{		
			if (req.readyState==4)
			{
				//alert(req.responseText);
				document.getElementById('lnk'+x).innerHTML="<img src='images/button/minus.gif' border='0'>";
				document.getElementById('offer'+x).innerHTML=req.responseText;
			}		
		}

		var str=Math.random();
		var querystr="";
		querystr+="look_offer.php";
		querystr+="?time="+str;
		para="&jobid="+encodeURIComponent(jobid);
		para+="&offerid="+encodeURIComponent(offerid);
		//alert(para);
		req.open("POST", querystr , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);			
	}
}

function hire() {

	 if (isNaN(document.getElementById('price').value))
	{
		alert("กรุณากรอกราคาเป็นตัวเลขเท่านั้น");
	} else if (document.getElementById('startdate').value=="" || document.getElementById('enddate').value=="") {
		alert("กรุณากำหนดวันที่เริ่มต้นและสิ้นสุด");		
	} else {

		var req = ini_ajax();
		
		req.onreadystatechange=function()
		{		
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==1) {
					window.opener.location.reload();
					window.self.close();					
				} else {
					alert("Fail");
				}						
			}		
		}

		var str=Math.random();
		var querystr="";
		querystr+="hire_add.php";
		querystr+="?time="+str;
		para="&jobid="+encodeURIComponent(document.getElementById('jobid').value);
		para+="&offerid="+encodeURIComponent(document.getElementById('offerid').value);
		para+="&startdate="+encodeURIComponent(document.getElementById('startdate').value);
		para+="&enddate="+encodeURIComponent(document.getElementById('enddate').value);
		para+="&price="+encodeURIComponent(document.getElementById('price').value);
		//alert(para);
		req.open("POST", querystr , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);		
	}
}

function get_point(cat)
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('rate_data').innerHTML=req.responseText;
		}
	}
	var str=Math.random();
	url="profile_point.php";
	url+="?time="+str;
	para="&memberid="+encodeURIComponent(document.getElementById('memberid').value);
	para+="&cat="+encodeURIComponent(document.getElementById('cate').value);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function work_data(status)
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('work_data').innerHTML=req.responseText;
		}
	}
	var str=Math.random();
	url="work_data.php";
	url+="?time="+str;
	para="&status="+encodeURIComponent(status);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function chkbox(x) {
	if (x=="catesub")
	{
		y=document.getElementById('total_oldc').value;
	}
	for (i=1;i<=y ;i++ )
	{
		//
		if (document.getElementById('oldc_'+i).value!="")
		{			
			add_cate(document.getElementById('oldc_'+i).value);
			//alert(document.getElementById('oldc_'+i).value);
		}
	}
}

function profile_edit(x)
{	
	if (x=="H") {
		if (document.getElementById("emailedit2_status").value=="ok") {
			ok="ok";
		} else { ok="no"; }		
	} else {
		if (document.getElementById("catesub_status").value=="ok" && document.getElementById("skill_status").value=="ok") {
			ok="ok";
		} else { ok="no"; }
	}
	if (document.getElementById("password_status").value=="ok" && document.getElementById("password2_status").value=="ok" && document.getElementById("fname_status").value=="ok" && document.getElementById("lname_status").value=="ok" && document.getElementById("mobileno_status").value=="ok" && document.getElementById("phoneno_status").value=="ok" && document.getElementById("emailedit_status").value=="ok" && ok=="ok") 
	{
	
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==1)	{
					alert("edit OK!!");
					window.open("index.php?module=profile&id="+document.getElementById('username').value, "_self");
				} else 	{
					alert("Fail");
				}
			}
		}
		var str=Math.random();
		var url="";
		url+="profile_ed.php";
		url+="?time="+str;
		para="&memberid="+encodeURIComponent(document.getElementById('memberid').value);
		para+="&group="+encodeURIComponent(document.getElementById('group').value);
		para+="&password="+encodeURIComponent(document.getElementById('password').value);
		para+="&fname="+encodeURIComponent(document.getElementById('fname').value);
		para+="&lname="+encodeURIComponent(document.getElementById('lname').value);
		para+="&mobileno="+encodeURIComponent(document.getElementById("mobileno").value);
		para+="&phoneno="+encodeURIComponent(document.getElementById("phoneno").value);
		para+="&email="+encodeURIComponent(document.getElementById("emailedit").value);		
		if (x=="X") {		
			para+="&country="+encodeURIComponent(document.getElementById('country').value);
			para+="&province="+encodeURIComponent(document.getElementById("province").value);
			para+="&amper="+encodeURIComponent(document.getElementById("amper").value);
			para+="&address="+encodeURIComponent(document.getElementById("address").value);
			para+="&website="+encodeURIComponent(document.getElementById("website").value);
			para+="&facebook="+encodeURIComponent(document.getElementById("facebook").value);
			para+="&hi5="+encodeURIComponent(document.getElementById("hi5").value);
			para+="&multiply="+encodeURIComponent(document.getElementById("multiply").value);
			para+="&twitter="+encodeURIComponent(document.getElementById("twitter").value);
			para+="&other="+encodeURIComponent(document.getElementById("other").value);
			para+="&slogan="+encodeURIComponent(document.getElementById("slogan").value);
			para+="&about="+encodeURIComponent(document.getElementById("about").value);
			para+="&expe="+encodeURIComponent(document.getElementById("expe").value);
			para+="&extra="+encodeURIComponent(document.getElementById("extra").value);
			para+="&award="+encodeURIComponent(document.getElementById("award").value);
			para+="&edu="+encodeURIComponent(document.getElementById("edu").value);
			para+="&team="+encodeURIComponent(document.getElementById("team").value);
			para+="&pay="+encodeURIComponent(document.getElementById("pay").value);
			for (i=1;i<=5 ;i++ )
			{
				para+="&cate"+i+"="+encodeURIComponent(document.getElementById('cs'+i).value);
			}
			for (i=1;i<=10 ;i++ )
			{
				para+="&skill"+i+"="+encodeURIComponent(document.getElementById('ss'+i).value);
			}
		}
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	} else {
		alert("กรอกข้อมูลไม่ถูกต้อง");
	}
}

function get_pic_main(mem,folder,page)
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('pic_main').innerHTML=req.responseText;
		}
	}
	var str=Math.random();
	url="pic_main.php";
	url+="?time="+str;
	para="&memberid="+encodeURIComponent(mem);
	para+="&folder="+encodeURIComponent(folder);
	para+="&page="+encodeURIComponent(page);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function pic_data(mem,filename)
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('pic_data').innerHTML=req.responseText;
		}
	}
	var str=Math.random();
	url="pic_data.php";
	url+="?time="+str;
	para="&memberid="+encodeURIComponent(mem);
	para+="&filename="+encodeURIComponent(filename);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function delete_pic()
{	
	if (confirm("ยืนยันการลบ"))
	{
	
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==1)	{
					//alert("ลบแล้วจ้า");
					window.location.reload();
				}
			}
		}
		var str=Math.random();
		url="pic_del.php";
		url+="?time="+str;
		para="&memberid="+encodeURIComponent(document.getElementById('memberid').value);
		para+="&filename="+encodeURIComponent(document.getElementById('filename').value);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	}
}

function get_ship(x)
{	
	var req = ini_ajax();
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			//alert(req.responseText);
			document.getElementById('ship_data').innerHTML=req.responseText;
		}
	}
	var str=Math.random();
	url="membership_data.php";
	url+="?time="+str;
	para="&page="+encodeURIComponent(x);
	para+="&payid="+encodeURIComponent(document.getElementById('payid').value);
	//alert(para);
	req.open("POST", url , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(para);
}

function buy_xp()
{	
	if (confirm("ยืนยันการซื้อหน่วย XP"))
	{
	
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				alert(req.responseText);
				if (req.responseText==1)	{
					//alert("สั่งซื้อเรียบร้อยแล้ว");
					get_ship('3');
				} 
			}
		}
		var str=Math.random();
		url="membership_xp.php";
		url+="?time="+str;
		para="&xp="+encodeURIComponent(document.getElementById('xp').value);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
	}
}

function confirm_pay()
{	
	
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==1)	{
					alert("แจ้งการชำระเงินเรียบร้อย รอการอนุมัติ");
					get_ship('1');
					//document.getElementById('tranid').value="";
					//document.getElementById('msg').value="";
				} else {
					alert("เลขที่สั่งซื้อไม่ถูกต้อง กรุณาตรวจดูที่อีเมลล์ของท่าน");
				}
			}
		}
		var str=Math.random();
		url="membership_pay.php";
		url+="?time="+str;
		para="&tranid="+encodeURIComponent(document.getElementById('tranid').value);
		para+="&msg="+encodeURIComponent(document.getElementById('msg').value);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
}


function subscribe(type)
{	
	
		var req = ini_ajax();
		req.onreadystatechange=function()
		{
			if (req.readyState==4)
			{
				//alert(req.responseText);
				if (req.responseText==1)	{
					alert("แจ้งการรับข่าวสารเรียบร้อยแล้ว");
					document.getElementById('submail_'+type).value="";
				} else if (req.responseText==2) {
					alert("กรุณากรอกอีเมลล์ให้ถูกต้อง");
				}
			}
		}
		var str=Math.random();
		url="subscribe.php";
		url+="?time="+str;
		para="&submail="+encodeURIComponent(document.getElementById('submail_'+type).value);
		para+="&type="+encodeURIComponent(type);
		//alert(para);
		req.open("POST", url , true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(para);
}


function ban_offer(jobid,memid)
{	
	if (document.getElementById('comment'+memid).value=="") {
		alert("กรุณาใส่เหตุผลด้วย");
		return false;
	} else {
		if (confirm("ยืนยันการ Ban Offer"))
		{
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					//alert(req.responseText);
					if (req.responseText==1)	{
						alert("Ban Offer นี้แล้ว");
						window.location.reload();
					} else {
						alert("Fail");
					}
				}
			}
			var str=Math.random();
			url="ban_offer.php";
			url+="?time="+str;
			para="&jobid="+encodeURIComponent(jobid);
			para+="&memid="+encodeURIComponent(memid);
			para+="&comment="+encodeURIComponent(document.getElementById('comment'+memid).value);
			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		}
	}
}

function delete_comment(articleid,mentid)
{	
	if (document.getElementById('comment'+mentid).value=="") {
		alert("กรุณาใส่เหตุผลด้วย");
		return false;
	} else {
		if (confirm("ยืนยันการ Ban Offer"))
		{
			var req = ini_ajax();
			req.onreadystatechange=function()
			{
				if (req.readyState==4)
				{
					//alert(req.responseText);
					if (req.responseText==1)	{
						alert("Ban Offer นี้แล้ว");
						window.location.reload();
					} else {
						alert("Fail");
					}
				}
			}
			var str=Math.random();
			url="delete_comment.php";
			url+="?time="+str;
			para="&articleid="+encodeURIComponent(articleid);
			para+="&mentid="+encodeURIComponent(mentid);
			para+="&comment="+encodeURIComponent(document.getElementById('comment'+mentid).value);
			//alert(para);
			req.open("POST", url , true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(para);
		}
	}
}


function chspace()
{
if(event.keyCode == 32)
return false;

return true;
}

//--------------------------history hash -----------------------------

var expectedHash = "";

function makeHistory(newHash)
{
  //alert(newHash);
  window.location.hash = newHash;
  expectedHash = window.location.hash;
  //return true;
}

function handleHistory()
{
  if ( window.location.hash != expectedHash )
  {
    expectedHash = window.location.hash;
	
	var qs = new Querystring();
	mod = qs.get("module");
	var newoption = expectedHash.substring(3,1);
	if (mod=="membership")
	{	    
		get_ship(newoption);
	} else if (mod=="regis" && newoption=="1") {
		showback('regis','regis_data');
	} else if (mod=="regis" && newoption=="2") {
		showback('regis_step2','regis_data');
	} else if (mod=="post_job") {
		showback('post_job_step2','post_job_data');
	}
  }
}

function pollHash() {
  handleHistory();
  window.setInterval("handleHistory()", 100);
  //return true;
}

function showback(x,y)
{	
	var req = ini_ajax();
	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{
			var a=document.getElementById(y);
			a.innerHTML=req.responseText;
			fillform(x);
		}
	}

	var str=Math.random();
	var querystr="";
	querystr+=x+".php";
	querystr+="?time="+str;
	req.open("POST", querystr , true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(null);
}

function fillform(x)
{
	if (x=="regis")
	{
		document.getElementById('username').value=window.parent.document.getElementById('username_h').value;
		document.getElementById('fname').value=window.parent.document.getElementById('fname_h').value;
		document.getElementById('lname').value=window.parent.document.getElementById('lname_h').value;
		document.getElementById('address').value=window.parent.document.getElementById('address_h').value;
		document.getElementById('mobileno').value=window.parent.document.getElementById('mobileno_h').value;
		document.getElementById('phoneno').value=window.parent.document.getElementById('phoneno_h').value;
		document.getElementById('email').value=window.parent.document.getElementById('email_h').value;
		document.getElementById('website').value=window.parent.document.getElementById('website_h').value;
		document.getElementById('facebook').value=window.parent.document.getElementById('facebook_h').value;
		document.getElementById('hi5').value=window.parent.document.getElementById('hi5_h').value;
		document.getElementById('multiply').value=window.parent.document.getElementById('multiply_h').value;
		document.getElementById('twitter').value=window.parent.document.getElementById('twitter_h').value;
		document.getElementById('other').value=window.parent.document.getElementById('other_h').value;		
	}
	if (x=="post_job_step2")
	{
		document.getElementById('topic').value=window.parent.document.getElementById('topic_h').value;
		var str = document.getElementById('detail_h').value;
		for (q=1;q<1000 ;q++ )
		{
			str = str.replace("\\n", "<br>");
		}
		//document.getElementById('detail').value=str;
		//document.getElementById('detail').innerHTML=str;
		document.getElementById('xskill').value=document.getElementById('xskill_h').value;
		document.getElementById('eststart').value=document.getElementById('eststart_h').value; 
	}
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
