
function callServer(Url,Content) {

	if (window.XMLHttpRequest)
		{
        	xmlHttp = new XMLHttpRequest();
    	}
    else if (window.ActiveXObject)
    	{
        	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

	if(Content == void 0)
		{
			xmlHttp.open("GET", Url, false);
			xmlHttp.send(null);
		}
	else
		{
            xmlHttp.open("POST", Url, false);
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-Length",Content.length);
			xmlHttp.send(Content);
		}

	if (xmlHttp.readyState == 4)
	{
	if (xmlHttp.status == 200)
		{

			var response = xmlHttp.responseText;

			return response;

		}
	}
	else
	{
	//waiting to load...

	}


}

 function setbrowseview(stu){

	if ( stu==0 || stu==1 )	{


			var strContent = "action=setbrowseview&stu=" + encodeURIComponent(stu);
			var Result=callServer("/ajax.php",strContent);

			response=eval(Result)[0];

			if (response.result)
			{
				window.open(window.location.href,"_self");
			}
			else
			{
				alert ("error");
			}


	}
	return false;

 }
 function showallcategory(stu){	
				if (stu==0)
				{
				$("*[name=s_cat]").css("display","block");				
				$("#categoryboxmore_less").attr("style","display:block");
				$("#categoryboxmore_more").attr("style","display:none");				
				}
				else
				{
				$("*[name=s_cat]").css("display","none");				
				$("#categoryboxmore_more").attr("style","display:block");
				$("#categoryboxmore_less").attr("style","display:none");
				}			
	return false;
 }
 function showallcity(stu,num){
				if (stu==0)
				{
					//for (i=4; i<=num; i++)
//					{
//					document.getElementById("s_city"+i).style.display="block";
//					}
				$("*[name=s_city]").css("display","block");	
				$("#cityboxmore_more").attr("style","display:none");
				$("#cityboxmore_less").attr("style","display:block");
				
				}
				else
				{
					//for (i=5; i<=num; i++)
//					{
//					document.getElementById("s_city"+i).style.display="none";
//					}
				$("*[name=s_city]").css("display","none");	
				$("#cityboxmore_more").attr("style","display:block");
				$("#cityboxmore_less").attr("style","display:none");
				}
	return false;
 }
function sendurl(num)
    {
       $("#errorsendurl").empty();
	   var myemail = window.document.getElementById("myemail"+num).value;
	   var toemail = window.document.getElementById("toemail"+num).value;
	   var sendurlmessage = window.document.getElementById("sendurlmessage"+num).value;
	   var urltitle = window.document.getElementById("urltitle").value;
	   var urltitle = document.title;
	   var bs_error = window.document.getElementById("errorsendurl"+num);
		var expComEmail=/^[\w\.]+@[\w]+\.[\w]+[\w\.]*/;
		
		textAfter=expComEmail.test(myemail);
		if(myemail==""){bs_error.innerHTML=$("#error_sf_from1").text(); return false;}
		if (!textAfter) { bs_error.innerHTML=$("#error_sf_from2").text();  return false;}

		textAfter=expComEmail.test(toemail);
		if(toemail==""){bs_error.innerHTML=$("#error_sf_to1").text(); return false;}
		if (!textAfter) { bs_error.innerHTML=$("#error_sf_to2").text();  return false;}
		window.document.getElementById("sendurlbutton"+num).disabled=true;
		
		
		jQuery.post(
					"/ajax.php",
					{
						"action":sendurl,
						"myemail":myemail,
						"toemail":toemail,
						"urlnow":window.location.href,
						"sendurlmessage":sendurlmessage,
						"sendtype":num,
						"urltitle":urltitle,
						"topjobs":$("#topjobs").val()
					},
					function(data,status){
						if(status=="success"){
							response=eval(data)[0];
								if (response.result)
								{
									window.document.getElementById("sendurlbutton"+num).disabled=false;
									window.document.getElementById("Canvas").style.display="block";
									window.document.getElementById("float_div").style.display="block";
									$("#float_div").empty();
									window.document.getElementById("float_div").innerHTML="<div class=\"popup_jobs\" onclick=\"javascript:closepopup()\"><div class=\"popup_jobs_content_info\">"+$("#error_sf_pop1").text()+"</div></div>";
									window.setTimeout("closepopup();", 5000);
								}
								else
								{
									window.document.getElementById("sendurlbutton"+num).disabled=false;
									alert ("error");
								}
						}
					},
					"text"
		);
//		var strContent = "action=sendurl&myemail=" + encodeURIComponent(myemail) + "&toemail=" + encodeURIComponent(toemail) + "&urlnow=" + encodeURIComponent(window.location.href) + "&sendurlmessage=" + encodeURIComponent(sendurlmessage)+ "&sendtype=" + encodeURIComponent(num)+ "&urltitle=" + encodeURIComponent(urltitle)+"&topjobs="+$("#topjobs").val();
//			var Result=callServer("/ajax.php",strContent);

//		response=eval(Result)[0];



		return false;
    }
	


function replyerror()
{
	_alert("This user has chosen not to receive replies to this ad. ");
}
function replyjobs()
    {
       $("#errorreply").empty();
	   var replyemail = window.document.getElementById("replyemail").value;
	    var adsemail = window.document.getElementById("adsemail").value;
	   var replycontent = window.document.getElementById("replycontent").value;
	   var error = window.document.getElementById("errorreply");
		var expComEmail=/^[\w\.]+@[\w]+\.[\w]+[\w\.]*/;
		textAfter=expComEmail.test(replyemail);
		if(replyemail==""){error.innerHTML=$("#error_replyto_r1").text(); return false;}
		if (!textAfter) { error.innerHTML=$("#error_replyto_r2").text();  return false;}
		textAfter=expComEmail.test(adsemail);
		if(adsemail==""){error.innerHTML=$("#error_replyto_a1").text(); return false;}
		if (!textAfter) { error.innerHTML=$("#error_replyto_a1").text();  return false;}
		if(replycontent==""){error.innerHTML=$("#error_replyto_a2").text(); return false;}

		if($("#replycontent").val()==$("#replycontent").attr("defval") || jQuery.trim($("#replycontent").val()).length<1){
			error.innerHTML=$("#error_replyto_a2").text();
			return false;
		}


		window.document.getElementById("sendreplybutton").disabled=true;
		var strContent = "action=sendreply&replyemail=" + encodeURIComponent(replyemail) + "&replycontent=" + encodeURIComponent(replycontent) + "&adsemail=" + encodeURIComponent(adsemail) + "&adid="+encodeURIComponent($("#replyadid").val());
			var Result=callServer("/ajax.php",strContent);

			response=eval(Result)[0];

			if (response.result)
			{
				window.document.getElementById("sendreplybutton").disabled=false;
				window.document.getElementById("Canvas").style.display="block";
				window.document.getElementById("float_div").style.display="block";
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML="<div class=\"popup_jobs\" onclick=\"javascript:closepopup()\"><div class=\"popup_jobs_content_info\">"+$("#error_replyto_pop1").text()+"</div></div>";
				window.setTimeout("closepopup();", 5000);
			}
			else
			{
				window.document.getElementById("sendreplybutton").disabled=false;
				alert ("error");
			}

		return false;
    }
 function changecity(stu){
			if (stu==0)
			{
				$("#changecity").css("display","block");
			}
			else
			{
				$("#changecity").css("display","none");
			}

	return false;
 }
 String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function confirmAbuseReport(id)
{
	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	var strContent = "action=reportabuse&adid="+id;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=response.popup;


			}
			else
			{
				
				var html = "<div class='popup_jobs'><div class='popup_jobs_content_info'>"+$("#error_bw_alert_4").text()+"</div></div>";
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=html;
				window.setTimeout("closepopup();", 5000);

			}
	return false;

}
function sendreportabuse(id,val,group)
{
	closepopup();
	var strContent = "action=sendreportabuse&adid="+id+"&abusetype="+val;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				window.document.getElementById("Canvas").style.display="block";
				window.document.getElementById("float_div").style.display="block";
				var html = "<div class='popup_jobs'><div class='popup_jobs_content_info'>"+$("#error_bw_alert_4").text()+"</div></div>";
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=html;
				window.setTimeout("closepopup();", 5000);
				//var geturl = '/include/postabuse.php?adid='+id;
//				jQuery.post(
//						geturl,
//						{"do":"reportabuse"},
//						function(){window.location.reload()}
//					);
			}
			else
			{
				alert ("error");
			}
	return false;
}
function searchkeyword()
{
			keyword=window.document.getElementById("searchkeyword").value;
			if(isNaN(keyword.substr(0,1)))
			{
				var strContent = "action=searchkeyword&key="+encodeURIComponent(keyword);
				var Result=callServer("/ajax.php",strContent);
				response=eval(Result)[0];
				if (response.result)
				{
					window.open(response.popup,"_self");
				}
				else
				{
					alert ("Please enter you search keyword");
				}
			}
	return false;
}
function lpad(str, maxl, pchar){
	pstr="";
	for(counter=str.length;counter<maxl;counter++){
		pstr+=pchar;
	}
	return pstr+str;
}

function arraysearch()
{

			marray_s_city= $("*[name=array_s_city]");

			array_city="";
			var len = marray_s_city.length;
			var checked = false;
			for (i = 0; i < len; i++)
			{
				if (marray_s_city[i].checked == true)
				{
					array_city=array_city+lpad(marray_s_city[i].value,4,'0');
				}
			}
			if (array_city=='')
			{
				alert("Please select cities.");
				return false;
			}
			marray_s_date=window.document.getElementsByName("array_s_date");
			array_date="";
			var len = marray_s_date.length;
			var checked = false;
			if (len==0)
			{
				array_date="A";
			}
			else
			{
				for (i = 0; i < len; i++)
				{
					if (marray_s_date[i].checked == true)
					{
						array_date=marray_s_date[i].value;
						break;
					}
				}
			}
			marray_s_type=window.document.getElementsByName("array_s_type");
			array_type="";
			var len = marray_s_type.length;
			var checked = false;
			if (len==0)
			{
				array_type=0;
			}
			else
			{
				for (i = 0; i < len; i++)
				{
					if (marray_s_type[i].checked == true)
					{
						array_type=marray_s_type[i].value;
						break;
					}
				}
			}

			var strContent = "action=arraysearch&array_s_city="+encodeURIComponent(array_city)+"&array_s_date="+encodeURIComponent(array_date)+"&array_s_type="+encodeURIComponent(array_type);
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];
			if (response.result)
			{
				window.open(response.popup,"_self");
			}
			else
			{
				alert ("Please enter you search keyword");
			}
	return false;
}
function check_input(input_object){
	var check_result=true;
	if(input_object.value.trim()==""){
		check_result=false;
	}
	if(input_object.name=="attach" || input_object.name=="q"){
		return true;
	}
	if(input_object.name=="email" && input_object.value.split("@").length<=1){
		check_result=false;
	}
	if(check_result){
		input_object.parentNode.parentNode.getElementsByTagName("div")[1].style.display="block";	//right
		input_object.parentNode.parentNode.getElementsByTagName("div")[2].style.display="none";	//wrong
	}else{
		input_object.parentNode.parentNode.getElementsByTagName("div")[1].style.display="none";	//right
		input_object.parentNode.parentNode.getElementsByTagName("div")[2].style.display="block";	//wrong
	}
	return check_result;
}

 function AddFavorite(sURL, sTitle)
    {
        try
        {
            window.external.addFavorite(sURL, sTitle);
        }
        catch (e)
        {
            try
            {
                window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch (e)
            {
                alert("Please use Ctrl+D to bookmark page.");
            }
        }
    }

 function openmessagebox(num)
 {
    
	$("#openmessagebox"+num).attr("style","display:none");
	$("#closemessagebox"+num).attr("style","display:block");	
	$("#sendurlmessage"+num).empty();
 }
function closemessagebox(num)
{
	if($("#sendurlmessage" + num).val() == "")
	{
		$("#sendurlmessage" + num).attr("value",$("#sf_template").text());
		$("#messageboxtxtbutton2").attr("style","display:block");
		$("#messageboxtxtbutton").attr("style","display:none");
	}
	else
	{
		$("#sendurlmessage" + num).attr("value","");
		$("#messageboxtxtbutton").attr("style","display:block");
		$("#messageboxtxtbutton2").attr("style","display:none");		
    }
}

//popup ajax
function shareurl(){

	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	var strContent = "action=shareurl";
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=response.popup;
				$("#urlnow3").val(window.location.href);

			}
			else
			{
				alert ("error");
			}
	return false;
}

function showsavealert(path,date,msg){	
	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";	
	var strContent = "action=showsavealert&path=" + path + "&date=" + encodeURIComponent(date) +"&msg=" + encodeURIComponent(msg);	
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();				
				window.document.getElementById("float_div").innerHTML=response.popup;
				window.setTimeout("closepopup();", 5000);
				//$("#urlnow3").val(window.location.href);
			}
			else
			{
				alert ("error");
			}
	return false;
}
function movecat(rowid){

	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	var strContent = "action=movecat&id=" + rowid ;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=response.popup;
				//$("#urlnow3").val(window.location.href);
			}
			else
			{
				alert ("error");
			}
	return false;
}
function closepopup(){
	window.document.getElementById("Canvas").style.display="none";
	window.document.getElementById("float_div").style.display="none";
	$("#float_div").empty();
	return false;
}

function savealert()
{
	var emailaddress;
	emailaddress = encodeURIComponent(document.getElementById("emailaddress").value);
	if(emailaddress == "")
	{
		alert("Please input your email address");
		return false;
	}
	jQuery.post(
		"/ajax.php",
		{
			"action":"savealert",
			"freq":$("#alert_freq").val(),
			"emailaddress":emailaddress,
			"url":window.location.href,
			"urlinfo":$("#urlinfo").text(),
			"path":$("#alertpath").html(),
			"title":document.title
		},
		function(data,status){
			if(status=="success"){
				response=eval(data)[0];
				if(response.result){
					showsavealert(document.getElementById("alertpath").innerHTML,$("#alert_freq").val());
				}else{
					switch(response.str){
						case "5TIMES":
							showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_1").text());
						break;
						default:
							showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_2").text());
					}
				}
			}
		}
	);
	
	/*var strContent = "action=savealert&freq="+$("#alert_freq").val()+"&emailaddress=" + emailaddress + "&url="+encodeURIComponent(window.location.href) + "&urlinfo=" + encodeURIComponent(document.getElementById("urlinfo").innerHTML) + "&path=" + encodeURIComponent(document.getElementById("alertpath").innerHTML) + "&title=" + encodeURIComponent(document.title);
	
	var Result=callServer("/ajax.php",strContent);
	response=eval(Result)[0];
	
	if (response.result)
	{		
		showsavealert(document.getElementById("alertpath").innerHTML,$("#alert_freq").val());
	}
	else if (response.str == "5TIMES")
	{		
		showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_1").text());
	}
	else
	{		
		showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_2").text());
	}*/
}
function saveadvancealert()
{
	var emailaddress;
	emailaddress = encodeURIComponent(document.getElementById("advanceemailaddress").value);
	if(emailaddress == "")
	{
		alert($("#error_bw_alert_3").text());
		return false;
	}
	var strContent = "action=savealert&freq="+$("#advancealert_freq").val()+"&emailaddress=" + emailaddress + "&url="+encodeURIComponent(window.location.href) + "&urlinfo=" + encodeURIComponent(document.getElementById("urlinfo").innerHTML) + "&path=" + encodeURIComponent(document.getElementById("alertpath").innerHTML) + "&title=" + encodeURIComponent(document.title);
	var Result=callServer("/ajax.php",strContent);
	response=eval(Result)[0];

	if (response.result)
	{
		showsavealert(document.getElementById("alertpath").innerHTML);

	}
	else if (response.str == "5TIMES")
	{
		showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_1").text());
		
	}
	else
	{
		showsavealert(document.getElementById("alertpath").innerHTML,'',$("#error_bw_alert_2").text());
	}
}
function showadvancealert()
{
	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	jQuery.post(
				"/ajax.php",
				{
					"action":"showadvancealert",
					"path":$("#alertpath").html()
				},
				function(data,status){
					if(status=="success"){
						response=eval(data)[0];
						if(response.result){
							$("#float_div").empty();
							$("#float_div").append(response.popup);
						}else{
							alert ("error");
						}
					}
				}
			);
	//var strContent = "action=showadvancealert&path=" + encodeURIComponent(document.getElementById("alertpath").innerHTML);
	//		var Result=callServer("/ajax.php",strContent);
	//		response=eval(Result)[0];
	//
	//		if (response.result)
	//		{
	//			$("#float_div").empty();
	//			$("#float_div").append(response.popup);
	//		}
	//		else
	//		{
	//			alert ("error");
	//		}
	return false;
}

function showdelete(id)
{

	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	var strContent = "action=showdeleteconfirm&id=" + id;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=response.popup;
				//$("#urlnow3").val(window.location.href);
			}
			else
			{
				alert ("error");
			}
	return false;
}

function showspam(id)
{

	window.document.getElementById("Canvas").style.display="block";
	window.document.getElementById("float_div").style.display="block";
	var strContent = "action=showspamconfirm&id=" + id;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				$("#float_div").empty();
				window.document.getElementById("float_div").innerHTML=response.popup;
				//$("#urlnow3").val(window.location.href);
			}
			else
			{
				alert ("error");
			}
	return false;
}

function dodelete(type)
{

	var strContent = "action=deletesuccess&type=" + type + "&rowid=" + document.getElementById("delrowid").value + "&email=" + document.getElementById("delemail").value;
			var Result=callServer("/ajax.php",strContent);
			response=eval(Result)[0];

			if (response.result)
			{
				window.open(window.location.href,"_self");
			}
			else
			{
				alert ("error");
			}
	return false;
}











function changeordertype(str)
{

	var url = document.location.href;

	//if (document.getElementById("sortby").value == 1)
	//{
		var strappend = "/" + document.getElementById("sortby").value + "_1/";
	//}
	//else
	//{
	//	var strappend = "";
	//}

	var pattern = /http\:\/\/\w+.\w+.\w+\/[\w_-]+\/[\w_-]+$/;

	if (pattern.test(url))
	{
		window.location.href = url + strappend;
	}
	else
	{
		var pattern = /http\:\/\/\w+.\w+.\w+\/[\w_-]+$/;
		if (pattern.test(url))
		{
			window.location.href = url + strappend;
		}
		else
		{
			var pattern = /\/\d+\/$/;
			if (pattern.test(url))
			{
				window.location.href = url.replace(/\/\d+\/$/,strappend);
			}
			else
			{
				var pattern = /\/[0-9_]+\/$/;
				if (pattern.test(url))
				{
					window.location.href = url.replace(/\/[0-9_]+\/$/,strappend);
				}
			}
		}
	}

}

function reportoptvalue()
{
	for(var i=1;i<=4;i++)
	{
		if(document.getElementById("opt" + i).checked == true)
			return document.getElementById("opt" + i).value
	}
}
