var loginUrl = '';
var loaderText = 'Please wait...';
var formSubmit = '';

function formatStr(str) {
	str = str.strip().replace(/%/g,'*1').replace(/#/g,'*2').replace(/&/g,'*3').replace(/\//g,'*4').replace(/'/g,'*5').replace(/\$/g,'*6').replace(/\+/g,'*7').replace(/ /g,'+');
	str = str.replace(/\'/g,'').replace(/\"/g,'');
	str = escape(str);
	str = str.replace(/%20/g,'+');
	str = str.replace(/ /g,'+');
	str = str.replace(/%A3/g,'');
	return str;
}

function highlightInputs(obj,res){
	for(i=0;i<$(obj).elements.length;i++){
    	tmp = res.split('#'+$(obj).elements[i].name+'#');
        if(tmp.length>1){
        	$($(obj).elements[i].name+'_f').style.color='red';
        }
    }
}

function dehighlightInputs(obj){
	for(i=0;i<$(obj).elements.length;i++){
        if($($(obj).elements[i].name+'_f')!=null) $($(obj).elements[i].name+'_f').style.color='#006699';
    }
}

function getHeight(){
    if(/Gecko/.test(navigator.userAgent)) return window.innerHeight;
    else return document.documentElement.offsetHeight;
}

var usertype = '';
var type= '';
var loggedin= '';

function doLogin(){
	if($('loginFrm').login_email.value.strip().length==0){
    	showAlert('Error','Please enter your email');
        //$('loginFrm').login_email.focus();
        return false;
    }
	if($('loginFrm').login_password.value.strip().length==0){
    	showAlert('Error','Please enter your password');
        //$('loginFrm').login_password.focus();
        return false;
    }
    showLoader(loaderText);
    $('loginFrm').request({
        onComplete: function(transport) {
            hideLoader();
            var response = transport.responseText.stripScripts();
            response = response.strip();
            tmp = response.split('Following errors found');
            if (tmp.length==1) {
                if(response == ''){
                    if (formSubmit!='') {
                    	$(formSubmit).submit();
                        return true;
                    }
                    new Ajax.Request(siteurl+"ajax/getUserType", {method: 'get',  onSuccess: function(transport){
                        var response = transport.responseText.stripScripts();
                        response = response.strip();
                        usertype = response;
                        loggedin = 1;
                        new Ajax.Request(siteurl+"ajax/getUserHeader", {method: 'get',  onSuccess: function(transport){
	                        var response = transport.responseText.stripScripts();
	                        response = response.strip();
	                        $('userheaderInfo').update(response);
	                    }});
                        if (type != '') {
                        	if(type != usertype){
                            	if(type=='employer'){
                                	showAlert('Error','Only employers can access this section. Please login with the employer account!');
                                }
								else {
                                	showAlert('Error','Only jobseekers can access this section. Please login with the jobseeker account!');
                                }
								return false;
                            }
                        }
						if(loginUrl=='') {
							window.location.reload();
							return true;
						}
						else {
							if (loginUrl=='bugreport'){
								$('login_div').hide();
								showDiv('bug_report');
							}
							else {
								window.location.href=loginUrl;
								return true;
							}
						}
                    }});
                }
                else {
					window.location.href = siteurl+response;
				}
            } else {
	            tmp2 = response.split('ban');
	            if (tmp2.length==1) {
	                showAlert('Error','Invalid email/password combination!');
                }
                else {
	                showAlert('Error','Your account has been banned.<br/> You may no longer use this site.<br/> If you think this is an error, you may appeal by going to <a href="'+siteurl+'support/appeal">www.findajobalready.com/support/appeal</a>.');
                }
            }
        }
    })
}

function actEmail(){
    if( !($('regFrm').email.value.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$/)) ){
        showAlert('Error',"Email that you entered is not valid. Please reenter a valid one");
        //$('regFrm').email.focus();
        return false;
    }
    showLoader(loaderText);
    $('regFrm').request({
        onComplete: function(transport) {
            hideLoader();
            var response = transport.responseText.stripScripts();
            response = response.strip();
            if (response == 'ok') {
				showAlert('Message','Check your inbox and click on the link to confirm you email and continue signup.');
                showSelects();
                $('login_div').hide();
				$('regFrm').reset();
				//reloadCaptcha();
				$('freecap').src = baseurl+'plugins/secretcode/turing-image.php?rnd='+Math.random();
            } else {
	            tmp2 = response.split('ban');
	            if (tmp2.length==1) {
	                showAlert('Error', response.replace(/Following errors found:/,'').replace(/<br\/>/g,'').replace(/text-align:left/,''));
                }
                else {
	                showAlert('Error', 'Your email/ip has been banned.<br/> You may no longer use this site.<br/> If you think this is an error, you may appeal by going to <a href="http://www.findajobalready.com/support">www.findajobalready.com/support</a>.');
                }
            }
        }
    })
}

function doForgot(){
	if($('loginFrm').login_email.value.strip().length==0){
    	showAlert('Error','Please enter your email');
        //$('loginFrm').login_email.focus();
        return false;
    }
    showLoader(loaderText);
    new Ajax.Request(siteurl+"ajax/forgotPassword", {method: 'post', postBody: 'login_email='+escape($('loginFrm').login_email.value.strip()),  onSuccess: function(transport){
        var response = transport.responseText.stripScripts();
        response = response.strip();
	    hideLoader();
        if(response == 'ok'){
	        showAlert('Information','Please check your email. <br/>Your password was successfully sent there.');
            $('login_div').hide();
	    }
		else if (response == 'inactive') {
			showAlert('Error',' Your registration wasn\'t finished. Please check your email and find the link to activate FindAJobAlready account.');
        }
		else {
			showAlert('Error','Email that you entered wasn\'t found in our database.');
		}
    }});
}

function showLogin(val,val2,frm){
	if (frm!=null) {
    	formSubmit = frm;
    }
	if(val2==null) val2 = '';
    loginUrl = val;
    type = val2;
    if(loggedin!=''){
      if(loggedin == '1'){
    	if(loginUrl=='') window.location.reload();
        else window.location.href=loginUrl;
        return false;
      }
    }
    var tableObj = $('parent_table');
    $('login_div').style.top = '0px';
    $('login_div').style.left = '0px';
    $('login_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('login_div').style.height = getHeight()+'px';
    else
      $('login_div').style.height = tableObj.offsetHeight+'px';
    $('freecap').src = $('freecap').src+Math.floor(Math.random()*100)+'';
    $('login_div').show();
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showWhySignup(){
    var tableObj = $('parent_table');
    $('why_div').style.top = '0px';
    $('why_div').style.left = '0px';
    $('why_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('why_div').style.height = getHeight()+'px';
    else
      $('why_div').style.height = tableObj.offsetHeight+'px';
    $('why_div').show();
    window.scroll(0,0);
}

function showResumeUpload(){
    var tableObj = $('parent_table');
    $('upload_div').style.top = '0px';
    $('upload_div').style.left = '0px';
    $('upload_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('upload_div').style.height = getHeight()+'px';
    else
      $('upload_div').style.height = tableObj.offsetHeight+'px';
    $('upload_div').show();
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showResumeCopy(){
	$('copy_div').hide();
    var tableObj = $('parent_table');
    $('copy_div').style.top = '0px';
    $('copy_div').style.left = '0px';
    $('copy_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('copy_div').style.height = getHeight()+'px';
    else
      $('copy_div').style.height = tableObj.offsetHeight+'px';

    $('copy_div').show();
    //for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showAlert(header,message){
    if(header==''){
    	tmp=message.split('Following errors found:');
        if(tmp.length>1){
        	header = 'Following errors found';
            message = tmp[1];
        }else{
        	header = 'Error';
        }
    }
    tmp=message.split('Following errors found:');
    if(tmp.length>1){
        message = tmp[1];
    }
    var tableObj = $('parent_table');
    $('alert_div').style.top = '0px';
    $('alert_div').style.left = '0px';
    $('alert_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('alert_div').style.height = getHeight()+'px';
    else
      $('alert_div').style.height = tableObj.offsetHeight+'px';
    $('alert_header').update(header);
    $('alert_message').update(message);
    $('alert_div').show();
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showConfirmation(header,message){
    var tableObj = $('parent_table');
    $('confirm_div').style.top = '0px';
    $('confirm_div').style.left = '0px';
    $('confirm_div').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('confirm_div').style.height = getHeight()+'px';
    else
      $('confirm_div').style.height = tableObj.offsetHeight+'px';
    $('conf_header').update(header);
    $('conf_message').update(message);
    $('confirm_div').show();
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showTwitterLogin(authurl){
    var tableObj = $('parent_table');
    $('twitter_login').style.top = '0px';
    $('twitter_login').style.left = '0px';
    $('twitter_login').style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $('twitter_login').style.height = getHeight()+'px';
    else
      $('twitter_login').style.height = tableObj.offsetHeight+'px';
    $('twitLoginBtn').href = authurl;
    $('twitter_login').show();
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    window.scroll(0,0);
}

function showLoader(message){
	$('loaderMessage').update(message);
    if ($('loader_div').style.display=='none') {
	    var tableObj = $('parent_table');
	    $('loader_div').style.top = '0px';
	    $('loader_div').style.left = '0px';
	    $('loader_div').style.width = tableObj.offsetWidth+'px';
	    if(getHeight()>tableObj.offsetHeight)
	      $('loader_div').style.height = getHeight()+'px';
	    else
	      $('loader_div').style.height = tableObj.offsetHeight+'px';
	    tt = document.documentElement.scrollTop + screen.height/2 - 150;
	    $('loaderTable').style.top = tt+'px';
	    $('loaderTable').style.left = (tableObj.offsetWidth/2-125)+'px';
	    Effect.Appear('loader_div',{duration:0.25});
	    window.scroll(0,0);
    }
}

function hideLoader(){
	if ($('loader_div').style.display!='none')
    	Effect.Fade('loader_div',{duration:0.0});
}

function showSelects(){
	for(i=0;i<$$('select').length;i++) $$('select')[i].show();
}

function paging(from)
{
	var thisURL = window.location.href;
    var re = /from\/[0-9]+/;
	thisURL = thisURL.replace(re, 'from/' + from);
	if (thisURL.indexOf('from/')==-1) {
        thisURL += '/from/' + from;
	}
    changePage(thisURL);
}

function paging2(from2)
{
	var thisURL = window.location.href;
    var re = /from2\/[0-9]+/;
	thisURL = thisURL.replace(re, 'from2/' + from2);
	if (thisURL.indexOf('from2/')==-1) {
        thisURL += '/from2/' + from2;
	}
    changePage(thisURL);
}

function changePage(url)
{
  window.location.href = url;
}

function selectAll(id)
{
    for(i=0;i<id.length;i++) id.options[i].selected = true;
}

function selectNone(id)
{
    for(i=0;i<id.length;i++) id.options[i].selected = false;
}

function selectCheckboxes(id,val){
    elements_array = $(id).getElements();
    for(i=0;i<elements_array.length;i++){
    	if(elements_array[i].type=="checkbox"){
        	elements_array[i].checked = val;
        }
    }
}

function k(ev)
{
    var KeyAscii;
    KeyAscii = ev.keyCode;
    if(KeyAscii==13) checkLogin();
    return;
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	return curtop;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}

function showDiv(id){
    var tableObj = $('parent_table');
    $(id).style.top = '0px';
    $(id).style.left = '0px';
    $(id).style.width = tableObj.offsetWidth+'px';
    if(getHeight()>tableObj.offsetHeight)
      $(id).style.height = getHeight()+'px';
    else
      $(id).style.height = tableObj.offsetHeight+'px';
    for(i=0;i<$$('select').length;i++) $$('select')[i].hide();
    $(id).show();
    window.scroll(0,0);
}

function doSearch(val)
{
    val = val.replace(/ /,'_');
    var thisURL = window.location.href;
    var re = /\/search\/[a-zA-Z0-9_]+/;
    if(val==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/search/' + escape(val));
	    if (thisURL.indexOf('search/')==-1) {
	        thisURL += '/search/' + escape(val);
	    }
    }
    changePage(thisURL);
}

function callOrder(val){
  	if(val==order){
        if(ordertype=='DESC') ordertype = 'ASC';
        else ordertype = 'DESC';
    }else ordertype = 'ASC';

    var thisURL = window.location.href;
    var re = /\/order\/[a-zA-Z0-9_]+/;
    var re2 = /\/ordertype\/[a-zA-Z0-9_]+/;
    if(val==""){
    	thisURL = thisURL.replace(re, '');
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re, '/order/' + escape(val));
    	thisURL = thisURL.replace(re2, '/ordertype/' + escape(ordertype));
	    if (thisURL.indexOf('order/')==-1) {
	        thisURL += '/order/' + escape(val);
	    }
	    if (thisURL.indexOf('ordertype/')==-1) {
	        thisURL += '/ordertype/' + escape(ordertype);
	    }
    }
    changePage(thisURL);
}

function callOrder3(val){
  	if(val==order){
        if(ordertype=='0') ordertype = '1';
        else ordertype = '0';
    }else ordertype = '1';

    var thisURL = window.location.href;
    var re = /\/order\/[a-zA-Z0-9_]+/;
    if(val==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/order/' + escape(val+'_'+ordertype));
	    if (thisURL.indexOf('order/')==-1) {
	        thisURL += '/order/' + escape(val+'_'+ordertype);
	    }
    }
    changePage(thisURL);
}

function doSearch2(val)
{
    val = val.replace(/ /,'_');
    var thisURL = window.location.href;
    var re = /\/search2\/[a-zA-Z0-9_]+/;
    if(val==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/search2/' + escape(val));
	    if (thisURL.indexOf('search2/')==-1) {
	        thisURL += '/search2/' + escape(val);
	    }
    }
    changePage(thisURL);
}

function callOrder2(val){
  	if(val==order2){
    	if(ordertype2=='DESC') ordertype2 = 'ASC';
        else ordertype2 = 'DESC';
    }else ordertype2 = 'ASC';

    var thisURL = window.location.href;
    var re = /\/order2\/[a-zA-Z0-9_]+/;
    var re2 = /\/ordertype2\/[a-zA-Z0-9_]+/;
    if(val==""){
    	thisURL = thisURL.replace(re, '');
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re, '/order2/' + escape(val));
    	thisURL = thisURL.replace(re2, '/ordertype2/' + escape(ordertype2));
	    if (thisURL.indexOf('order2/')==-1) {
	        thisURL += '/order2/' + escape(val);
	    }
	    if (thisURL.indexOf('ordertype2/')==-1) {
	        thisURL += '/ordertype2/' + escape(ordertype2);
	    }
    }
    changePage(thisURL);
}

function doFilter(){
	userid = $('filterFrm').userid.value;
	deleted = $('filterFrm').deleted.value;
	subfolderid = $('filterFrm').subfolderid.value;

    var thisURL = window.location.href;
    var re = /\/userid\/[a-zA-Z0-9_]+/;
    var re2 = /\/deleted\/[a-zA-Z0-9_]+/;
    var re3 = /\/subfolderid\/[a-zA-Z0-9_]+/;
    if(userid==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/userid/' + escape(userid));
	    if (thisURL.indexOf('userid/')==-1) {
	        thisURL += '/userid/' + escape(userid);
	    }
    }
    if(deleted==""){
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re2, '/deleted/' + escape(deleted));
	    if (thisURL.indexOf('deleted/')==-1) {
	        thisURL += '/deleted/' + escape(deleted);
	    }
    }
    if(subfolderid==""){
    	thisURL = thisURL.replace(re3, '');
    }else{
    	thisURL = thisURL.replace(re3, '/subfolderid/' + escape(subfolderid));
	    if (thisURL.indexOf('subfolderid/')==-1) {
	        thisURL += '/subfolderid/' + escape(subfolderid);
	    }
    }
    changePage(thisURL);
}

function doFilter2(){
	userid = $('filterFrm').userid.value;

    var thisURL = window.location.href;
    var re = /\/userid\/[a-zA-Z0-9_]+/;
    if(userid==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/userid/' + escape(userid));
	    if (thisURL.indexOf('userid/')==-1) {
	        thisURL += '/userid/' + escape(userid);
	    }
    }
    changePage(thisURL);
}

function doFilter3(){
	userid = $('filterFrm').userid.value;
	reason = $('filterFrm').reason.value;

    var thisURL = window.location.href;
    var re = /\/userid\/[a-zA-Z0-9_]+/;
    var re2 = /\/reason\/[a-zA-Z0-9_]+/;
    if(userid==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/userid/' + escape(userid));
	    if (thisURL.indexOf('userid/')==-1) {
	        thisURL += '/userid/' + escape(userid);
	    }
    }
    if(reason==""){
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re2, '/reason/' + escape(reason));
	    if (thisURL.indexOf('reason/')==-1) {
	        thisURL += '/reason/' + escape(reason);
	    }
    }
    changePage(thisURL);
}

function doFilter4(){
	userid = $('filterFrm').userid.value;
	status = $('filterFrm').status.value;
	categoryid = $('filterFrm').categoryId.value;

    var thisURL = window.location.href;
    var re = /\/userid\/[a-zA-Z0-9_]+/;
    var re2 = /\/status\/[a-zA-Z0-9_]+/;
    var re3 = /\/categoryid\/[a-zA-Z0-9_]+/;
    if(userid==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/userid/' + escape(userid));
	    if (thisURL.indexOf('userid/')==-1) {
	        thisURL += '/userid/' + escape(userid);
	    }
    }
    if(status==""){
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re2, '/status/' + escape(status));
	    if (thisURL.indexOf('status/')==-1) {
	        thisURL += '/status/' + escape(status);
	    }
    }
    if(categoryid==""){
    	thisURL = thisURL.replace(re3, '');
    }else{
    	thisURL = thisURL.replace(re3, '/categoryid/' + escape(categoryid));
	    if (thisURL.indexOf('categoryid/')==-1) {
	        thisURL += '/categoryid/' + escape(categoryid);
	    }
    }
    changePage(thisURL);
}

function doFilter5(){
	finished = $('filterFrm').finished.value;

    var thisURL = window.location.href;
    var re = /\/finished\/[a-zA-Z0-9_]+/;
    if(finished==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/finished/' + escape(finished));
	    if (thisURL.indexOf('finished/')==-1) {
	        thisURL += '/finished/' + escape(finished);
	    }
    }
    changePage(thisURL);
}


function doFilterUser(){
	usertype = $('filterFrm').usertype.value;
	if ($('filterFrm').status != undefined) {
		status = $('filterFrm').status.value;
	}
	else {
		status = '';
	}
	search = $('searchFrm').search.value;

    var thisURL = window.location.href;
    var re = /\/usertype\/[a-zA-Z0-9_]+/;
    var re2 = /\/status\/[a-zA-Z0-9_]+/;
    var re3 = /\/search\/[^\/]+/;
    if(usertype==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/usertype/' + escape(usertype));
	    if (thisURL.indexOf('usertype/')==-1) {
	        thisURL += '/usertype/' + escape(usertype);
	    }
    }
    if(status==""){
    	thisURL = thisURL.replace(re2, '');
    }else{
    	thisURL = thisURL.replace(re2, '/status/' + escape(status));
	    if (thisURL.indexOf('status/')==-1) {
	        thisURL += '/status/' + escape(status);
	    }
    }
    if(search==""){
    	thisURL = thisURL.replace(re3, '');
    }else{
    	thisURL = thisURL.replace(re3, '/search/' + escape(search.replace(' ','_')));
	    if (thisURL.indexOf('search/')==-1) {
	        thisURL += '/search/' + escape(search.replace(' ','_'));
	    }
    }
    changePage(thisURL);
}

function doFilterJobs(){
	origin = $('filterFrm').origin.value;
	country = $('filterFrm').country.value;
	feed = $('filterFrm').feed.value;
	if ($('filterFrm').status != undefined) {
		status = $('filterFrm').status.value;
	}
	
    var thisURL = window.location.href;
    var re = /\/origin\/[a-zA-Z0-9_]+/;
    if(origin==""){
    	thisURL = thisURL.replace(re, '');
    }else{
    	thisURL = thisURL.replace(re, '/origin/' + escape(origin));
	    if (thisURL.indexOf('origin/')==-1) {
	        thisURL += '/origin/' + escape(origin);
	    }
    }
    var re = /\/country\/[0-9]+/;
    if(country == ""){
    	thisURL = thisURL.replace(re, '');
    }
	else {
    	thisURL = thisURL.replace(re, '/country/' + escape(country));
	    if (thisURL.indexOf('country/')==-1) {
	        thisURL += '/country/' + escape(country);
	    }
    }
	var re = /\/feed\/[a-zA-Z0-9_]+/;
    if(feed == ""){
    	thisURL = thisURL.replace(re, '');
    }
	else {
    	thisURL = thisURL.replace(re, '/feed/' + escape(feed));
	    if (thisURL.indexOf('feed/')==-1) {
	        thisURL += '/feed/' + escape(feed);
	    }
    }
	if ($('filterFrm').status != undefined) {
		var re = /\/status\/[0-9]+/;
		if(status == ""){
			thisURL = thisURL.replace(re, '');
		}
		else {
			thisURL = thisURL.replace(re, '/status/' + escape(status));
			if (thisURL.indexOf('status/')==-1) {
				thisURL += '/status/' + escape(status);
			}
		}
	}
    changePage(thisURL);
}

function doFilterResumes(){
	country = $('filterFrm').country.value;

    var thisURL = window.location.href;
    var re = /\/country\/[0-9]+/;
    if(country == ""){
    	thisURL = thisURL.replace(re, '');
    }
	else {
    	thisURL = thisURL.replace(re, '/country/' + escape(country));
	    if (thisURL.indexOf('country/')==-1) {
	        thisURL += '/country/' + escape(country);
	    }
    }
    changePage(thisURL);
}

/* Search functions */
function keywordFocus(val,type) {
	if(val==1 && $('keywordSearch').value==type+' Title, Keyword') {
        $('keywordSearch').value = '';
        $('keywordSearch').removeClassName('formfileds-big');
        $('keywordSearch').addClassName('formfileds-verybig');
    }
    else if($('keywordSearch').value=='') {
        $('keywordSearch').removeClassName('formfileds-verybig');
        $('keywordSearch').addClassName('formfileds-big');
        $('keywordSearch').value = type+' Title, Keyword';
    }
}

function locationFocus(val) {
	if(val==1 && $('locationSearch').value=='City, '+state_word+' or '+zip_word) {
        $('locationSearch').value = '';
        $('locationSearch').removeClassName('formfileds-big');
        $('locationSearch').addClassName('formfileds-verybig');
    }
    else if($('locationSearch').value=='') {
        $('locationSearch').removeClassName('formfileds-verybig');
        $('locationSearch').addClassName('formfileds-big');
        $('locationSearch').value = 'City, '+state_word+' or '+zip_word;
    }
}

function jobSearch() {
	if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, '+state_word+' or '+zip_word) || ($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Job Title, Keyword')) {
        /*url = siteurl+'jobs/search';
        if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, State or Zip')) {
            url = url + '/location/'+formatStr($('locationSearch').value);
        }
        if(($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Job Title, Keyword')) {
            url = url + '/keyword/'+formatStr($('keywordSearch').value);
        }
		*/
	    showLoader('Please wait...');
 	    url = siteurl;
		flag = false;
        if(($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Job Title, Keyword')) {
			value = $('keywordSearch').value;
			tmp = value.split(',');
			if (tmp.length == 2) {
				value = tmp[0].capitalize();
				tmp[1] = tmp[1].replace(/ /g,'');
				if (tmp[1].length == 2) {
					value += ', '+tmp[1].toUpperCase();
				}
				else {
					value += ', '+tmp[1].capitalize();
				}
			}
			tmp = value.replace(/\-/g,'*9').replace(/ /g,'-');
            url = url + formatStr(tmp);
			flag = true;
        }
        if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, '+state_word+' or '+zip_word)) {
			if (flag) {
				url = url + '-jobs-';
			}
			value = $('locationSearch').value;
			tmp = value.split(',');
			if (tmp.length == 2) {
				value = tmp[0].capitalize();
				tmp[1] = tmp[1].replace(/ /g,'');
				if (tmp[1].length == 2) {
					value += ', '+tmp[1].toUpperCase();
				}
				else {
					value += ', '+tmp[1].capitalize();
				}
			}
            url = url + formatStr(value.replace(/ /g,'-'));
			if (!flag) {
				url = url + '-jobs';
			}
			window.location.href = url;
			return true;
        }
		window.location.href = url + '-jobs';
    }
    else {
       showAlert('Error','Please fill out location or keyword to search jobs.');
       return false;
    }
}

function jobSearchAdvanced() {
	$('locationSearch').value = $('advancedLocation').value;
	$('keywordSearch').value = $('advancedKeyword').value;
	if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, '+state_word+' or '+zip_word) || ($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Job Title, Keyword')) {
        showLoader('Please wait...');
		$('jobSearchFrm').distance.value = $('distanceAdv').value;
        $('jobSearchFrm').pageLength.value = $('pageLengthAdv').value;
        $('jobSearchFrm').timeposted.value = $('timepostedAdv').value;
        $('jobSearchFrm').order.value = $('orderAdv').value;
        $('jobSearchFrm').submit();
    }
    else {
       showAlert('Error','Please fill out location or keyword to search jobs.');
       return false;
    }
}

function resumeSearch() {
	if(($('locationSearch').value!='' && $('locationSearch').value!='City, '+state_word+' or '+zip_word) || ($('keywordSearch').value!='' && $('keywordSearch').value!='Resume Title, Keyword')) {
        /*url = siteurl+'resumes/search';
        if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, State or Zip')) {
            url = url + '/location/'+formatStr($('locationSearch').value);
        }
        if(($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Resume Title, Keyword')) {
            url = url + '/keyword/'+formatStr($('keywordSearch').value);
        }
		*/
	    showLoader('Please wait...');
		flag = false;
 	    url = siteurl;
        if(($('keywordSearch').value.strip()!='' && $('keywordSearch').value.strip()!='Resume Title, Keyword')) {
			value = $('keywordSearch').value;
			tmp = value.split(',');
			if (tmp.length == 2) {
				value = tmp[0].capitalize();
				tmp[1] = tmp[1].replace(/ /g,'');
				if (tmp[1].length == 2) {
					value += ', '+tmp[1].toUpperCase();
				}
				else {
					value += ', '+tmp[1].capitalize();
				}
			}
            url = url + formatStr(value.replace(/ /g,'-'));
			flag = true;
        }
        if(($('locationSearch').value.strip()!='' && $('locationSearch').value.strip()!='City, '+state_word+' or '+zip_word)) {
			if (flag) {
				url = url + '-resumes-';
			}
			value = $('locationSearch').value;
			tmp = value.split(',');
			if (tmp.length == 2) {
				value = tmp[0].capitalize();
				tmp[1] = tmp[1].replace(/ /g,'');
				if (tmp[1].length == 2) {
					value += ', '+tmp[1].toUpperCase();
				}
				else {
					value += ', '+tmp[1].capitalize();
				}
			}
            url = url + formatStr(value.replace(/ /g,'-'));
			if (!flag) {
				url = url + '-resumes';
			}
			window.location.href = url;
			return true;
        }
		window.location.href = url + '-resumes';
    }
    else {
       showAlert('Error','Please fill out location or keyword to search resumes.');
       return false;
    }
}

function resumeSearchAdvanced() {
    $('locationSearch').value = $('advancedLocation').value;
    $('keywordSearch').value = $('advancedKeyword').value;
	if(($('locationSearch').value!='' && $('locationSearch').value!='City, '+state_word+' or '+zip_word) || ($('keywordSearch').value!='' && $('keywordSearch').value!='Resume Title, Keyword')) {
        showLoader('Please wait...');
		$('resumeSearchFrm').distance.value = $('distanceAdv').value;
        $('resumeSearchFrm').pageLength.value = $('pageLengthAdv').value;
        $('resumeSearchFrm').timeposted.value = $('timepostedAdv').value;
        $('resumeSearchFrm').order.value = $('orderAdv').value;
        $('resumeSearchFrm').submit();
    }
    else {
       showAlert('Error','Please fill out location or keyword to search resumes.');
       return false;
    }
}

function supportSearch() {
    url = siteurl+'support/search';
	if($('supportKeyword').value.strip()!='') {
        if($('supportKeyword').value.strip()!='') {
            url = url + '/keyword/'+formatStr($('supportKeyword').value);
        }
        window.location.href = url;
    }
    else {
       showAlert('Error','Please fill out keyword to search questions.');
       return false;
    }
}

/* end search functions */

function checkEnter(e) {
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else keycode = e.keyCode;
	if(keycode == 13 && $$('.autosuggest').length==0){
        return true;
	}
    else {
		return false;
    }
}

function bugReport(){
    if( $('bugFrm').bugurl.value=='' || $('bugFrm').bugnotes.value==''){
        showAlert('Error',"You should specify url and description of the bug.");
        return false;
    }
    showLoader(loaderText);
    $('bugFrm').submit();
}

function bugResult() {
	hideLoader();
	showAlert('Message','Your report was successfully sent.');
	showSelects();
	$('bug_report').hide();
}

var closeCareer = 0;
var careerSended = 0;

function showCareer() {
	closeCareer = 0;
    if ($('career_div').style.display == 'none') {
	    Effect.Appear('career_div',{duration:0.2});
		if (!careerSended) {
			new Ajax.Request(siteurl+"ajax/increment_career", {method: 'post'});
			careerSended = 1;
		}
    }
}

function hideCareer() {
	closeCareer = 1;
    if ($('career_div').style.display != 'none') {
		var t = setTimeout(function() {
			if (closeCareer) Effect.Fade('career_div',{duration:0.2});
		}, 100);
	}
}

Event.onDOMReady(function(){
    if(/Gecko/.test(navigator.userAgent)) {
		add = 15;
	}
	else {
		add = 32;
	}

	if ($('career_link') != undefined) {
		pos = $('career_link').positionedOffset();
		$('career_div').setStyle({left: pos[0]+'px', top: (pos[1]+add)+'px'});
	}

	if ($('freecap') != undefined) {
		$('freecap').observe('click', function(event){
			$('freecap').src = baseurl+'plugins/secretcode/turing-image.php?rnd='+Math.random();
		});
	}
	if ($('freecap2') != undefined) {
		$('freecap2').observe('click', function(event){
			$('freecap2').src = baseurl+'plugins/secretcode/turing-image.php?rnd='+Math.random();
		});
	}

});

function setCityAutosuggest(cityId, countryId)
{
	if (countryId == 218 || countryId == 37) {
		var options = {
			script:siteurl+"index.php?method=ajax.getlocation&cityonly=1&countryId="+countryId,
			varname:"input"
		};
		var as = new AutoSuggest(cityId, options);
	}
}

function reloadCaptcha()
{
	$$('.captchaText').each(function(value){
		Effect.Fade(value,{duration:0.2, to:0.5});
	});
	new Ajax.Request(siteurl+"site/captcha", {method: 'get', onSuccess: function(transport){
        var response = transport.responseText.stripScripts();
        response = response.strip();
		$$('.captchaText').each(function(value){
			value.update(response);
			Effect.Appear(value,{duration:0, to:1.0});
		});
    }});
}

function backToMobile() 
{
	document.cookie = "isRegularSite=0";
	document.location = baseurl;
}

function recomendUrlCombine(urlBase, category, location)
{
	//category
	value = category;
	tmp = value.split(',');
	if (tmp.length == 2) {
		value = tmp[0].capitalize();
		tmp[1] = tmp[1].replace(/ /g,'');
		if (tmp[1].length == 2) {
			value += ', '+tmp[1].toUpperCase();
		}
		else {
			value += ', '+tmp[1].capitalize();
		}
	}
	tmp = value.replace(/\-/g,'*9').replace(/ /g,'-');
	url = urlBase + formatStr(tmp);
	url = url + '-jobs-';
	//location
	value = location;
	tmp = value.split(',');
	if (tmp.length == 2) {
		value = tmp[0].capitalize();
		tmp[1] = tmp[1].replace(/ /g,'');
		if (tmp[1].length == 2) {
			value += ', '+tmp[1].toUpperCase();
		}
		else {
			value += ', '+tmp[1].capitalize();
		}
	}
	url = url + formatStr(value.replace(/ /g,'-'));
	return url;
}

function checkJobs(url)
{
	showLoader();
	var result = false;
	new Ajax.Request(url,
	{
		asynchronous: false,
		method: 'get',
		onSuccess: function(transport){
			result = transport.responseJSON.result;
		}
	});
	hideLoader();
	return result;
}
