function ajaxTimeout()
{
	if(xmlHTTP.readyState==1)
	{
		xmlHTTP.abort();
		alert("ขาดการติดต่อจาก Server กรุณาเช็คสัญญาณอินเตอร์เน็ต");
		window.location = window.location.href;
	}
	clearTimeout(timeout);
}
function ajaxLoad(method,url,data,displayId,divLoad)
{
	var today = new Date();
	today.setTime( today.getTime() );
	url += "&td="+today;
	timeout=setTimeout("ajaxTimeout()",15000);
	document.getElementById(divLoad).style.display = "block";
	document.getElementById(displayId).style.display = "none";

	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open(method, url, true);
	if(method=="POST")
	{
		xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			document.getElementById(divLoad).style.display = "none";
			var var_msg = xmlHTTP.responseText;
			//alert(var_msg);
			if(var_msg=="redirect")
			{
				window.location = "http://www.job1hit.com/";
			}
			document.getElementById(displayId).style.display = "block";
			document.getElementById(displayId).innerHTML = var_msg;
			clearTimeout(timeout);
		}
	};
	if(method=="POST")
	{
		xmlHTTP.send(data);
	}
	else
	{
		xmlHTTP.send('');
	}
}
function job_folder(event)
{
	mouse_position(event,'div_process');

	var div_loading=document.getElementById("div_process");
	div_loading.style.display="block";

	var today = new Date();
	today.setTime( today.getTime() );
	var url = HOST_PATH+"module/check-session.php?td="+today;
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open("GET", url, true);
	
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			var var_msg = xmlHTTP.responseText;
			div_loading.style.display="none";
			if(var_msg=="false1")
			{
				alert("กรุณา login ก่อนใช้งานค่ะ")
				var from_url=window.location.href;
				window.location ="http://www.job1hit.com/jobseeker/member-login.php?url="+from_url;
			}
			else if(var_msg=="true1")
			{
				window.location ="http://www.job1hit.com/jobseeker/job-folder.php";
			}
			else
			{
				alert("เกิดข้อผิดพลาดในการดำเนินการ ลองกด f5 เพื่อ refesh หน้าจออีกครั้งค่ะ");
			}
			
			
		}
	};
	xmlHTTP.send('');
		
		

}
function ajaxLoad2(method,url,data,divLoad)
{
	document.getElementById(divLoad).style.display="block";

	var today = new Date();
	today.setTime( today.getTime() );
	url += "&td="+today;
	
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open(method, url, true);
	if(method=="POST")
	{
		xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			var var_msg = xmlHTTP.responseText;
			document.getElementById(divLoad).style.display="block";
			if(var_msg == "false1")
			{
				
				alert("สำหรับสมาชิกเท่านั้นค่ะ");
			}
			else if(var_msg=="false2")
			{
				
				alert("คุณได้สมัครงานนี้ไปแล้วไม่สามารถสมัครได้อีกค่ะ");
			}
			else if(var_msg=="false3")
			{
				
				alert("ไม่สามารถสมัครได้เนื่องจากคุณยังไม่ได้ update resume กรุณากลับไป update resume ค่ะ");
			}
			else
			{
			
				document.getElementById("div_loading").style.display = "none";
				window.location = "http://www.job1hit.com/jobseeker/job-apply.php";
			}
	
			
		}
	};
	if(method=="POST")
	{
		xmlHTTP.send(data);
	}
	else
	{
		xmlHTTP.send('');
	}
}
function apply_cnd(val)
{
	var div_loading=document.getElementById("div_loading");
	div_loading.style.display="block";

	var today = new Date();
	today.setTime( today.getTime() );
	var url = "http://192.168.0.81:81/employer/check-apply.php?job_id="+val+"&td="+today;
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open("GET", url, true);
	
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			var var_msg = xmlHTTP.responseText;
			if(var_msg == "false1")
			{
				document.getElementById("div_loading").style.display = "none";
				alert("สำหรับสมาชิกเท่านั้นค่ะ");
			}
			else if(var_msg=="false2")
			{
				document.getElementById("div_loading").style.display = "none";
				alert("คุณได้สมัครงานนี้ไปแล้วไม่สามารถสมัครได้อีกค่ะ");
			}
			else if(var_msg=="false3")
			{
				document.getElementById("div_loading").style.display = "none";
				alert("ไม่สามารถสมัครได้เนื่องจากคุณยังไม่ได้ update resume กรุณากลับไป update resume ค่ะ");
			}
			else
			{
				
				alert("ได้ส่งใบสมัครงานไปยังนายจัางเรียบร้อยแล้วค่ะ");
				document.getElementById("div_loading").style.display = "none";
				window.location = "http://www.job1hit.com/jobseeker/job-apply.php";
			}
	
			
		}
	};
	xmlHTTP.send('');
}
function add_FavoriteJob(event,action,id)
{
	mouse_position(event,'div_process');
	mouse_position(event,'div_dis');
	if(action=="check")
	{
		var div_loading=document.getElementById("div_process");
		div_loading.style.display="block";
	
		var today = new Date();
		today.setTime( today.getTime() );
		var url = HOST_PATH+"employer/job-detail-favorite.php?action="+action+"&id="+id+"&td="+today;
		xmlHTTP = createXMLHttpRequest();
		xmlHTTP.open("GET", url, true);
		
		xmlHTTP.onreadystatechange=function()
		{
			if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
			{
				var var_msg = xmlHTTP.responseText;
				
				if(var_msg=="false1")
				{
					div_loading.style.display="none";
					alert("กรุณา login ก่อนใช้งานค่ะ")
					var from_url=window.location.href;
					window.location ="http://www.job1hit.com/jobseeker/member-login.php?url="+from_url;
				}
				else if(var_msg=="false2")
				{
					div_loading.style.display="none";
					alert("ไม่สามารถเพิ่มได้อีก เนื่องจากตำแหน่งงานนี้มีอยู่ในแฟ้มเก็บตำแหน่งงานแล้วค่ะ");
				}
				else if(var_msg=="true")
				{
					/*var html="<img src='../images/add_image/success.gif' width='14' height='14' />&nbsp;<strong>จัดเก็บลงแฟ้มเก็บตำแหน่งงานเรียบร้อยแล้วค่ะ</strong><br><a href=\"http://www.job1hit.com/jobseeker/job-folder.php\">ดูตำแหน่งงานในแฟ้มทั้งหมด</a> | ปิด";
					div_loading.style.display="none";
					document.getElementById("div_dis").style.display ="block";
					document.getElementById("div_dis").innerHTML = html;*/
					div_loading.style.display="none";
					alert("เก็บข้อมูลเข้าแฟ้มเรียบร้อยแล้วค่ะ");
				}
				else
				{
					div_loading.style.display="none";
					alert("เกิดข้อผิดพลาดในการดำเนิด ลองกด f5 เพื่อ refesh หน้าจออีกครั้งค่ะ");
				}
				
				
			}
		};
		xmlHTTP.send('');
		
		
	}
	/*var txt ="<img src='http://www.job1hit.com/images/add_image/loading2.gif' /> กำลังดำเนินการจัดเก็บ ...";
	document.getElementById("div_process").innerHTML = txt;
	var url = "job-detail-favorite.php?page="+page+"&id="+id;
	ajaxLoad('GET',url,null,'div_dis','div_load');*/
	//div_loading.style.display="block";

}
function add_bookmark(val)
{
	var div_loading=document.getElementById("div_loading");
	div_loading.style.display="block";

	var today = new Date();
	today.setTime( today.getTime() );
	
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open("GET", url, true);
	
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			var var_msg = xmlHTTP.responseText;
			if(var_msg == "false1")
			{
				document.getElementById("div_loading").style.display = "none";
				alert("สำหรับสมาชิกเท่านั้นค่ะ");
			}
			else if(var_msg=="false2")
			{
				document.getElementById("div_loading").style.display = "none";
				alert("งานนี้ได้ถูกจัดเก็บอยู่แล้วค่ะไม่สามารถจัดเก็บได้อีก");
			}
			else
			{
				document.getElementById("div_loading").style.display = "none";
				document.getElementById("div_bookmark").style.display = "block";
				window.setTimeout("redirect()",500);
				//window.location = "http://www.job1hit.com/employer/job-list.php";
			}
			
		}
	};
	xmlHTTP.send('');
}
function redirect()
{
	window.location = "http://www.job1hit.com/jobseeker/job-folder.php";
}
function send_message(val)
{
	window.open("../message/"+val+".html","mywindow","toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,resizable=no,width=400,height=351");
}
function mouse_position(event,div_id)
{
	var div=document.getElementById(div_id);
	//alert(event.clientX);
	//alert(event.clientY);
	//alert(div_tooltip.offsetWidth);
	//alert(div_tooltip.offsetHeight); 
	
	var left = event.clientX+5;
	if((left + div.offsetWidth) > document.body.clientWidth)
	{
		left -= (div.offsetWidth + 10);
	}
	var top = event.clientY;
	if((top + div.offsetHeight) > document.body.clientHeight)
	{
		top -= (div.offsetHeight +10);
	}
	top += document.documentElement.scrollTop;
	div.style.top = top + "px";
	div.style.left = left + "px";
}
function send_to_friend()
{
	var str="";
	var next=1;
	var name_recv=document.getElementById("name_recv").value;
	var email_recv=document.getElementById("email_recv").value;
	var message_recv=document.getElementById("message_recv").value;
	var name_to=document.getElementById("name_to").value;
	var email_to=document.getElementById("email_to").value;
	var code_to=document.getElementById("code_to").value;
	var hid1=document.getElementById("hid1").value;
	var hid2=document.getElementById("hid2").value;
	var hid3=document.getElementById("hid3").value;
	if(name_recv =="")
	{
		str +="คุณยังไม่ได้กรอกค่าต่อไปนี้ \n * กรุณากรอกชื่อผู้รับ\n";
		next=0;
	}
	if(email_recv=="")
	{
		str +=" * กรุณากรอก email ผู้รับ\n";
		next=0;
	}
	if(name_to=="")
	{
		str +=" * กรุณากรอกชื่อผู้ส่ง\n";
		next=0;
	}
	if(email_to=="")
	{
		str +=" * กรุณากรอก email ผู้ส่ง\n";
		next=0;
	}
	if(next==0)
	{
		next=0;
		alert(str);
		return false;
	}
	if(check_email(email_recv)==false)
	{
		next=0;
		alert(" * กรุณากรอก email ผู้รับให้ถูกต้องด้วยค่ะ");
		return false;
	}
	if(check_email(email_to)==false)
	{
		next=0;
		alert(" * กรุณากรอก email ผู้ส่งให้ถูกต้องด้วยค่ะ");
		return false;
	}
	if(code_to != hid3 )
	{
		next=0;
		alert(" * กรุณากรอกรหัสภาพให้ถูกต้องด้วยค่ะ");
		return false;
	}
	if(next==1)
	{
		document.getElementById("dis_toFriendLoad").style.display = "block";
		document.getElementById("dis_toFriend").style.display ="none";
		name_recv=encodeURI(name_recv);
		email_recv=encodeURI(email_recv);
		message_recv=encodeURI(message_recv);
		name_to=encodeURI(name_to);
		email_to=encodeURI(email_to);
		hid1=encodeURI(hid1);
		hid2=encodeURI(hid2);
		hid3=encodeURI(hid3);
		var today = new Date();
		today.setTime( today.getTime() );
		var url = HOST_PATH+"employer/job-detail-sendToFriend.php?&td="+today;
		timeout=setTimeout("ajaxTimeout()",15000);
		var data = "";
		var data = "&name_recv="+name_recv+"&email_recv="+email_recv+"&message_recv="+message_recv+"&name_to="+name_to+"&email_to="+email_to+"&hid1="+hid1+"&hid2="+hid2;
	
		xmlHTTP = createXMLHttpRequest();
		xmlHTTP.open("POST", url, true);
		xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHTTP.onreadystatechange=function()
		{
			if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
			{
				document.getElementById("dis_toFriendLoad").style.display = "none";
				var var_msg = xmlHTTP.responseText;
				//alert(var_msg);
				if(var_msg=="redirect")
				{
					window.location = "http://www.job1hit.com/";
				}
				document.getElementById("dis_toFriend").style.display = "block";
				document.getElementById("dis_toFriend").innerHTML = var_msg;
				clearTimeout(timeout);
			}
		};
		xmlHTTP.send(data);

	}
	
	
	
}
function check_email(var_email)
{
	if(var_email != "")
	{
    	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!filter.test(var_email) && var_email.length != 0)
		{
			return false;
		}
	}
		
}
function get_form_SendToFriend(job_id)
{
	var today = new Date();
	today.setTime( today.getTime() );
	var url = HOST_PATH+"employer/job-detail-sendToFriend.inc.php?code_job="+job_id+"&td="+today;
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open("GET", url, false);
	xmlHTTP.send('');
	var var_msg = xmlHTTP.responseText;
	document.getElementById("dis_toFriend").innerHTML = var_msg;
}


