function setformaction(form)
{
	
	/// get form object
	frm=document.getElementById("jobsearch");
	
	/// check that is there txttitle_company
	if(document.getElementById("txtcompany"))
	{
		
		//var site_url="http://shivam/websites/salarydom.com/";
		//***********GET USER ENTERED VALUES***********///
		// this is for job title
		
		var txtjobtitle=trim(document.getElementById("txtjobtitle").value)=='Job Title' ? '' : trim(document.getElementById("txtjobtitle").value);
		document.getElementById("txtjobtitle").value=txtjobtitle;
		txtjobtitle=strReplace(" ", "-", txtjobtitle);
		
		// this is for companany 
		
		var txtcompany=trim(document.getElementById("txtcompany").value)=='Company Name' ? '' : trim(document.getElementById("txtcompany").value)
		// set value to textbox
		document.getElementById("txtcompany").value=txtcompany;
		txtcompany=strReplace(" ", "-", txtcompany);
		
		// this is for page no.
		var Page=null;
		if(document.getElementById("Page"))
		{
			Page=document.getElementById("Page").value;
			//alert(Page);
		}
		
		
		// this is for city
		var txtcity=null;
		
		/////////// VARIABLE DECLARATIONS///////////////
		// var for form action
		var formAction="";
		
		/// var for formated company name and job title
		var newCompanyJobtitle="";
		
		// post fix for job title and company
		var postFix="Salaries";
		
		// pre fix for city
		var preFix="in";
		
			
		///// if entered only jobtitle like software engineer
		if(document.getElementById("txtcity"))
		{
			txtcity=trim(document.getElementById("txtcity").value)=='Location (city, state or zip)' ? '' : trim(document.getElementById("txtcity").value);
			
		}
		
		var newCompanyJobtitle=null;
		// if user entered company name;
		if(txtcompany!="" && txtjobtitle!="")
		{
			newCompanyJobtitle=txtcompany+"-Salaries-for-"+txtjobtitle;
		}
		else
		{
			if(txtcompany!="")
			{
				if(txtjobtitle=="")
				{
					extra="company"
				}
				newCompanyJobtitle=txtcompany+"-"+extra+"-"+postFix;
			}
			
			// if user entered job title;
			if(txtjobtitle!="")
			{
				if(txtcompany=="")
				{
					extra="jobtitle"
				}
				newCompanyJobtitle=txtjobtitle+"-"+extra+"-"+postFix;
			}
		}
		/// merging post fix
		//newCompanyJobtitle+="-"+postFix;
		
		//// creating form action
		if(txtcity!=null && txtcity.length>0)
		{
			
			if(newCompanyJobtitle==null || newCompanyJobtitle=="")
			{
				formAction=postFix+"-"+preFix+"-"+txtcity;
			}
			else
			{
				formAction=newCompanyJobtitle+"-"+preFix+"-"+txtcity;
			}
		}
		else
		{
			formAction=newCompanyJobtitle;
		}
		
		// set form action
		//frm.action="Page-"+Page+"-"+formAction+".htm";
		//frm.action=formAction+"-"+Page+".htm".toLowerCase();
		page_param=Page>1 ? "-"+document.getElementById('page_sep').value+"-"+Page : "";
		if(formAction=="" || formAction==null)
		{
			alert("Please enter some search criteria");
			return false;
		}
		
		
		frm.action=strReplace(" ","-", formAction+page_param+".htm".toLowerCase());
		
		frm.action=strReplace(",","", frm.action);
		
		//submit form
		
		window.frm.submit();
		return true;
	}
	return false;
	
}
function setJobSearchFormAction(form)
{
	
	//var site_url="http://shivam/websites/salarydom.com/";
	
	// actual URL
	// http://salarydom.com/searchjob.php?txttitle=software+engineer&salary=900-20000&txtcity=ca
	
	// formatted URL
	// http://salarydom.com/software engineer-900to20000-Jobs-in-ca
	
	// VARIABLE DECLARATIONS 
	var Page=null;
	if(document.getElementById("Page"))
	{
		Page=document.getElementById("Page").value;
	}
	
	var formAction="";
	
	// post fix for job title and company
	var postFix="Jobs";
	
	// pre fix for city
	var preFix="in";
	
	// GET FORM VALUES.
	var txttitle=trim(document.getElementById("txttitle").value)=='Job Title' ? '' : trim(document.getElementById("txttitle").value);
		document.getElementById("txttitle").value=txttitle;
		txttitle=strReplace(" ", "-", txttitle);
	var salary=trim(document.getElementById("salary").value)=='Minimum Salary' ? '' : trim(document.getElementById("salary").value);
		document.getElementById("salary").value=salary
	var txtcity=trim(document.getElementById("txtcity").value)=='Location (city, state or zip)' ? '' : trim(document.getElementById("txtcity").value);
		document.getElementById("txtcity").value=txtcity;
		txtcity=strReplace(" ", "-", txtcity);
	
	/*if(txttitle=="")
	{
		alert("Please you must insert job title.");
		return false;
	}*/

	if(txttitle.length>0)
	{
		if(salary!="")
		{
			formAction=txttitle;
		}
		else
		{
			formAction=txttitle+"-jobtitle";
		}
	}
	
	if(salary!="")
	{
		salary=salary;
		formAction+=formAction.length>0 ? "-minimum-salary-"+salary : salary+"-minimum-salary";
	}
	
	/// adding postFix
	das=trim(formAction).length>0 ? "-" : "";
	formAction+=das+postFix;
	
	if(txtcity!="")
	{
		formAction+="-"+preFix+"-"+txtcity;
	}
	//alert(formAction);
	if(formAction.length>0)
	{
		var frm=document.getElementById("formname_search")
		//frm.action="Page-"+Page+"-"+formAction+".htm";
		page_param=Page>1 ? "-"+document.getElementById('page_sep').value+"-"+Page : "";
		
		
		if(formAction==postFix)
		{
			alert("Please enter some search criteria.");
			return false;
		}
		
		frm.action=formAction+page_param+".htm".toLowerCase();
		frm.action=strReplace(",","", frm.action);
		//alert(frm.action);
		
		window.document.getElementById("formname_search").submit();
		return true;
	}
	return false;
}
function setTotalRecordUrl(page)
{
	// PATERN
	//http://phpserver/websites/salarydom.com/software-engineer-company-motorola-in-IL.htm
	if(document.getElementById("Page"))
	{
		
		// set value to page no.
		document.getElementById("Page").value=page;
		
		// get values for URL generation
		var txtjobtitle=document.getElementById('txtjobtitle').value;
		var txtcompany=document.getElementById('txtcompany').value;
		var txtcity=document.getElementById('txtcity').value;
		var page=document.getElementById('Page').value;
		
		//txttitle_company=strReplace(" ", "-",txttitle_company);
		// file extention where we have to do redirect
		var fileExt=".htm";
		
		// URL generation
		var url=strReplace(" ", "-", txtjobtitle+"-company-"+txtcompany+"-in-"+txtcity);
		
		// set page no value if page <=1 then no need to add page no.
		page_param=page>1 ? "-"+page : "";
		
		// merge page value and file extension this is final url
		url+=page_param+fileExt;
		
		// finally redirect to the generated url
		window.location.href=url;
	}
}
function strReplace(oldStr, newStr, str)
{
	str=str.replace(oldStr, newStr);
	str=str.replace(oldStr, newStr);
	str=str.replace(oldStr, newStr);
	str=str.replace(oldStr, newStr);
	str=str.replace(oldStr, newStr);
	str=str.replace(oldStr, newStr);
	return str;
}
function submitSalSearch(pageNo)
{
	if(document.getElementById("Page"))
	{
		document.getElementById("Page").value=pageNo;
		
		if(document.getElementById("jobsearch"))
		{
			var form=document.getElementById("jobsearch");
			setformaction(form);
			return;
		}
		
		if(document.getElementById("formname_search"))
		{
			var form=document.getElementById("formname_search");
			setJobSearchFormAction(form);
		}
	}
}
function submitJobSearch(pageNo)
{
	
	if(document.getElementById("Page"))
	{
		document.getElementById("Page").value=pageNo;
		if(document.getElementById("formname_search"))
		{
			var form=document.getElementById("formname_search");
			setJobSearchFormAction(form);
		}
	}
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function search_job1(company)
{
	company=company.replace("@", "");
    arr=company.split(",");
 	
	 if(arr[1]==4)
	 {
		 var txt="";
		 txt=arr[0];
		 document.getElementById("txttitle").value=txt;
		 frm=document.getElementById("formname_search");
		
		// document.getElementById("divJobBySallery").style.display='block';
		// document.getElementById("divJobSearch").style.display='none';
		 setJobSearchFormAction(frm);
	
	 }
	 if(arr[1]==3)
	 {
		document.getElementById("txtjobtitle").value=arr[0];
		frm=document.getElementById("jobsearch");
		setformaction(frm);
		window.frm.submit();
	 }
	 if(arr[1]==1)
	 {
		document.getElementById("txtcompany").value=arr[0];
		frm=document.getElementById("jobsearch");
		setformaction(frm);
		window.frm.submit();
	}
}
function search_job(value, searchType)
{
	
	 if(searchType=='jobtitle')
	 {
		 document.getElementById("txttitle").value=value;
	 }
	 if(searchType=='salary')
	 {
		document.getElementById("salary").value=value;
	 }
	 if(searchType=='city')
	 {
		document.getElementById("txtcity").value=value;
	 }
	frm=document.getElementById("formname_search");
	//document.getElementById("divJobBySallery").style.display='block';
	//document.getElementById("divJobSearch").style.display='none';
	setJobSearchFormAction(frm);
	window.document.getElementById("formname_search").submit();
	return false;
}

function search_salary(value, searchType)
{
	 if(searchType=='company')
	 {
		 
		 document.getElementById("txtcompany").value=value;
	 }
	 if(searchType=='jobtitle')
	 {
		
		document.getElementById("txtjobtitle").value=value;
	 }
	 if(searchType=='city')
	 {
		
		document.getElementById("txtcity").value=value;
		
	 }
	
	frm=document.getElementById("jobsearch");
	
	
	//alert(frm);
	//document.getElementById("divJobBySallery").style.display='none';
	//document.getElementById("divJobSearch").style.display='block';
	setformaction(frm);
	return false;
}
