﻿/**
 * $Id: main.js 2322 2008-02-05 13:32:51Z javer $
 *
 * @copyright Copyright (c) 2007-2008, Effective Solution Band Ltd, All rights reserved.
 * @url http://www.esb.com.ua
*/

function _$(id){
  return document.getElementById(id);
}

function showVacancy(obj, id) {
  var div = _$('vacancy_'+id);
  if(div.style.display!='none') {
    div.style.display = 'none';
    obj.innerHTML = localization.web_vacancy_show;
    obj.className = 'show_all';
  }
  else {
    div.style.display = '';
    obj.innerHTML = localization.web_vacancy_close;
    obj.className = 'close_all';
  }
}

function vendorsFilterGoto() {
  //var product_type = _$('filter_product_type').value;
  var country = _$('filter_country').value;
  var url = g_full_base_url + 'producers/';
  /*if(product_type != undefined && product_type.length>0) url += product_type + '/';
  else*/ url += 'all' + '/';
  if(country != undefined && country.length>0) url += country + '/';
  //alert(url);
  window.location.href = url;
}

/*function reloadCaptcha(){
_$('imgCaptha').src = g_base_url + 'captcha.php?' + Math.round(Math.random(0)*1000)+1;
}
*/

function reloadCaptchaLight(){
    _$('imgCaptha').src = g_base_url + 'captcha_light.php?' + Math.round(Math.random(0)*1000)+1;
}

function searchFilterGoto() {
  var product_type = _$('filter_product_type').value;
  var country = _$('filter_country').value;
  var url = g_full_base_url + 'search/filter/';
  if(product_type != undefined && product_type.length>0) url += product_type + '/';
  else url += 'all' + '/';
  if(country != undefined && country.length>0) url += country + '/';
  window.location.href = url;
}

function searchWordGoto(id) {
  var field = id;
  if(!id || id.length==0) field = 'word';
  var word = _$(field).value;
  var url = g_full_base_url + 'search/';
  if(word!=undefined && word.length>0) url += 'word/' + encodeURIComponent(word) + '/';
  window.location.href = url;
}

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}

function sendFeedbackForm()
{
//  var pattern_text = /^[^\s]+$/;
  var pattern_text = /^\s*$/;
  var pattern_email = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/;

  if(pattern_text.test(trim(_$('feedback_fio').value)))
  {
    alert(localization.web_feedback_error_fio);
    return false;
  }

  if(pattern_email.test(trim(_$('feedback_email').value)) === false)
  {
    alert(localization.web_feedback_error_email);
    return false;
  }

  if(pattern_text.test(trim(_$('feedback_subject').value)))
  {
    alert(localization.web_feedback_error_subject);
    return false;
  }

  if(pattern_text.test(trim(_$('feedback_message').value)))
  {
    alert(localization.web_feedback_error_message);
    return false;
  }

  if(pattern_text.test(trim(_$('security_code').value)))
  {
    alert(localization.web_feedback_error_security_code);
    return false;
  }

  return true;
}
