/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function OpenWin(imf,num) {
myWin1= window.open(imf, 
num, "width=690,height=520,status=no,toolbar=no,resizable=no,scrollbars=yes,menubar=no");}  
function submit_form() { 
 document.cont.submit(); 
}  // end of the 'OpenWin(imf,num)' function

function OpenWin2(imf,num) {
myWin1= window.open(imf, 
num, "width=690,height=290,status=no,toolbar=no,resizable=no,scrollbars=yes,menubar=no");}  
function submit_form() { 
 document.cont.submit(); 
}  // end of the 'OpenWin(imf,num)' function

function OpenWin3(imf,num) {
myWin1= window.open(imf, 
num, "width=300,height=200,status=no,toolbar=no,resizable=no,scrollbars=yes,menubar=no");}  
function submit_form() { 
 document.cont.submit(); 
}  // end of the 'OpenWin(imf,num)' function



function mOvr(src,clrOver) 
{
 if (!src.contains(event.fromElement)) 
 {
   src.style.cursor = 'hand';
   src.bgColor = clrOver;
   src.background='';
  }
}

function mOut(src,clrIn) 
{
 if (!src.contains(event.toElement)) 
 {
  src.bgColor = clrIn;
  src.background="images/i2.gif";
 }
}

function mClk(src) 
{
 if(event.srcElement.tagName=='TD')
 {
   src.children.tags('a')[0].click();
 }
}

var AD=Array();var AD_id=Array();var AL=Array();var AL_id=Array();var AM=Array();var AM_id=Array();var AT=Array();var AT_id=Array();var AZ=Array();var AZ_id=Array();var BA=Array();var BA_id=Array();var BE=Array();var BE_id=Array();var BG=Array();var BG_id=Array();var CH=Array();var CH_id=Array();var CN=Array();var CN_id=Array();var CY=Array();var CY_id=Array();var CZ=Array();var CZ_id=Array();var DE=Array();var DE_id=Array();var DK=Array();var DK_id=Array();var EE=Array();var EE_id=Array();var ES=Array();var ES_id=Array();var FI=Array();var FI_id=Array();var FR=Array();var FR_id=Array();var GB=Array();var GB_id=Array();var GE=Array();var GE_id=Array();var GI=Array();var GI_id=Array();var GR=Array();var GR_id=Array();var HR=Array();var HR_id=Array();var HU=Array();var HU_id=Array();var IE=Array();var IE_id=Array();var IL=Array();var IL_id=Array();var IR=Array();var IR_id=Array();var IT=Array();var IT_id=Array();var KG=Array();var KG_id=Array();var KZ=Array();var KZ_id=Array();var LI=Array();var LI_id=Array();var LT=Array();var LT_id=Array();var LU=Array();var LU_id=Array();var LV=Array();var LV_id=Array();var MC=Array();var MC_id=Array();var MD=Array();var MD_id=Array();var MK=Array();var MK_id=Array();var NL=Array();var NL_id=Array();var NO=Array();var NO_id=Array();var PL=Array();var PL_id=Array();var PT=Array();var PT_id=Array();var RO=Array();var RO_id=Array();var SE=Array();var SE_id=Array();var SI=Array();var SI_id=Array();var SK=Array();var SK_id=Array();var TJ=Array();var TJ_id=Array();var TM=Array();var TM_id=Array();var TR=Array();var TR_id=Array();var UZ=Array();var UZ_id=Array();var VA=Array();var VA_id=Array();var YU=Array();var YU_id=Array();var BY=Array('Брестская','Витебская','Гомельская','Гродненская','Минская','Могилевская');

var BY_id=Array(116,115,117,118,114,119);

var RU=Array('Агинский Бурятский','Адыгея','Алтай','Алтайский','Амурская','Архангельская','Астраханская','Байконур','Башкортостан','Белгородская','Брянская','Бурятия','Владимирская','Волгоградская','Вологодская','Воронежская','Дагестан','Еврейская','Ивановская','Ингушская','Иркутская','Кабардино-Балкарская','Калининградская','Калмыкия','Калужская','Камчатская','Карачаево-Черкесская','Карелия','Кемеровская','Кировская','Коми','Коми-Пермяцкий','Корякский','Костромская','Краснодарский','Красноярский','Курганская','Курская','Ленинградская','Липецкая','Магаданская','Марий Эл','Мордовия','Московская','Мурманская','Ненецкий','Нижегородская','Новгородская','Новосибирская','Омская','Оренбургская','Орловская','Пензенская','Пермская','Приморский','Псковская','Ростовская','Рязанская','Самарская','Саратовская','Саха (Якутия)','Сахалинская','Свердловская','Северная Осетия-Алания','Смоленская','Ставропольский','Таймырский','Тамбовская','Татарстан','Тверская','Томская','Тульская','Тыва','Тюменская','Удмуртская','Ульяновская','Усть-Ордынский Бурятский','Хабаровский','Хакасия','Ханты-Мансийский','Челябинская','Чеченская','Читинская','Чувашская','Чукотский','Эвенкийский','Ямало-Ненецкий','Ярославская');

var RU_id=Array(26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,57,56,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113);

var UA=Array('Крым','Винница','Волынь','Днепропетровск','Донецк','Житомир','Закарпатье','Запорожье','Ивано-Франковск','Киев','Кировоград','Луганск','Львов','Николаев','Одесса','Полтава','Ровно','Сумы','Тернополь','Харьков','Херсон','Хмельницк','Черкасы','Чернигов','Черновцы','Луцк');

var UA_id=Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26);

function changeRegions(country,region,sel)
{
  for(i=1;i<region.length;i++)
  {
   region.options[i] = null;
   i--;
  }

  if(country.selectedIndex == 0)
   return;

  if(eval(country.options[country.selectedIndex].value).length==0)
  {
   document.getElementById(region.name).disabled='true';
  }else
  {
   document.getElementById(region.name).disabled='';
  }        

  if(country.selectedIndex != 0)
  {
   var arr = eval(country.options[country.selectedIndex].value);
   var arr_id = eval(country.options[country.selectedIndex].value+"_id");
   for(i=0;i<arr.length;i++)
   {
    region.options[region.length] = new Option(arr[i],arr[i]);
    if(arr_id[i]==sel)
    {
     region.selectedIndex=i+1;
    }
   }
  } 
}

function getCountry(country,region){
  if((country.options[country.selectedIndex].value == "UA") || (country.options[country.selectedIndex].value == "RU"))
  {
    document.getElementById(region).style.display = 'block';
  }else
  {
    document.getElementById(region).style.display = 'none';
  }
} 

function checkEmpty(){
 var fields = new Array("cargoWeight","cargoVolume");
 var messages = new Array("тоннаж","объем");
 for (var i=0;i<fields.length;i++)
 {
   if (eval("document.frmAddTrans." + fields[i])) 
   {
     if (eval("document.frmAddTrans." + fields[i] + ".value") == "") 
     {
      alert("Внимание: Вы забыли указать " + messages[i]);
      eval("document.frmAddTrans." + fields[i] + ".focus()");
      return false
     }
   }   
 }
 var fields = new Array("transTypeID","countryFromID","countryToID");
 var messages = new Array("тип кузова","страну","страну");
 for (var i=0;i<fields.length;i++)
 {
   if (eval("document.frmAddTrans." + fields[i])) 
   {
    if (eval("document.frmAddTrans." + fields[i] + ".selectedIndex") == 0) 
    {
      alert("Внимание: Вы забыли указать " + messages[i]);
      eval("document.frmAddTrans." + fields[i] + ".focus()");
      return false
     }
    }   
   }
  var fields = new Array("userCompanyTitle","userCity","userContact","userPhone1Country","userPhone1City","userPhone1Number");
  var messages = new Array("название комапнии","город","контактное лицо","код страны","код города","телефонный номер");
  for (var i=0;i<fields.length;i++)
  {
    if (eval("document.frmAddTrans." + fields[i])) 
    {
     if (eval("document.frmAddTrans." + fields[i] + ".value") == "") 
     {
       alert("Внимание: Вы забыли указать " + messages[i]);
       eval("document.frmAddTrans." + fields[i] + ".focus()");
       return false
      }
     }   
   }
  var fields = new Array("userTypeID","userCountryID");
  var messages = new Array("тип пользователя","страну");
  for (var i=0;i<fields.length;i++)
  {
    if (eval("document.frmAddTrans." + fields[i])) 
    {
     if (eval("document.frmAddTrans." + fields[i] + ".selectedIndex") == 0) 
     {
       alert("Внимание: Вы забыли указать " + messages[i]);
       eval("document.frmAddTrans." + fields[i] + ".focus()");
       return false
     }
    }   
  }
 return true;
}


function check_regform()  {
  var re1 = /^[\w\-\_]+$/i;
  var re2 = /^[\d]+$/i;
  var re3 = /^([\w\-\_]+\.)*[\w\-\_]+@([\w-]+\.)+[A-Za-z]{2,4}$/i;
  var re4 = /^[\d]*$/i;
  var re5 = /^[\d\-\ ]+$/i;
  var re6 = /^[\d\-\ ]*$/i;

  if (document.regform.name.value=='')
  {
    alert('Введите Название вашей компании ');
    return
  }else if(document.regform.name.value.length < 3){
    alert('Некорректное Название вашей компании.');
    return
  }

  if (document.regform.uraddr.value=='')
  {
    alert('Введите Юридический адрес');
    return
  }

  if (!re3.test(document.regform.email2.value) && document.regform.email2.value != ''){
    alert('Некорректный e-mail.');
    return
  }

  if (document.regform.contname.value=='')
  {
    alert('Введите Контактное лицо');
    return
  }

  if (document.regform.phone.value == '')
  {
    alert('Введите Телефоны');
    return
  }
  if (document.regform.addr.value == '')
  {
    alert('Введите Почтовый адресс');
    return
  }
  if (document.regform.okpo.value == '')
  {
    alert('Введите ОКПО');
    return
  }

  document.regform.submit();
}

