function switchImage_2( imgNum)
{
        var form = document.pack;
        var twin = document.getElementById( "twin");
        var standart = document.getElementById( "standart");      
        toggle( form, imgNum);           
        if( imgNum==SINGLE) {
            toggle( form, TWIN);
            standart.style.display = "block";
            twin.style.display = "none";
            document.terminals[0].checked = true;
        }
        if( imgNum==TWIN) {
            toggle( form, SINGLE);
            standart.style.display = "none";
            twin.style.display = "block";
            document.twin_terminals[0].checked = true;
            twinFormChanged();
        }
        if( imgNum == PAY_ALL)
        {
            toggle( form, PAY_LOAN);
        }
        if( imgNum == PAY_LOAN)
        {
            toggle( form, PAY_ALL);
        }
        if( imgNum==ANT60) {
            toggle( form, ANT90);
        }
        if( imgNum==ANT90) {
            toggle( form, ANT60);
        }
        count_cost();          
}                   
function twinFormChanged()
{
    var a = document.twin_terminals;
    var checkedCount=0;
    for( i = 0; i < a.length; i++) {
        if( a[i].checked) {
            if( checkedCount == 2)
                a[i].checked=false;
            else
                checkedCount++;
        }
    }
    if( checkedCount == 0) {
        a[0].checked=true;
        checkedCount++;
    }
    for( i = 0; i < a.length; i++) {
        document.getElementById( "descr"+i).innerHTML="";
        if( checkedCount == 1 && a[i].checked) {
            document.getElementById( "descr"+i).innerHTML=" ( 2шт)";
        }
    }
    count_cost();
}
function count_cost()
{ 
         var hardware=0;
         var a;
         var tname="";
                  
         /** количество выбранных моделей терминалов */
         var terminalsCount = 0;
                   
         if( buttons[TWIN])
             a = document.twin_terminals;
         else
             a = document.terminals;
         for( i=0; i < a.length; i++) {
             if( a[i].checked) {
                 terminalsCount++;
                 tname+= ( terminalsCount>1?" + ":"")+a.elements[i].value;
                 hardware+=terminals_cost[i];
             }
         }
         
         document.pack.terminal_name.value = tname;
         
         //переменная hardware (может и не факт, что минус 50руб.)        
         if( buttons[TWIN]) {
               if( terminalsCount == 1)
                   hardware *= 2;
               hardware -= 50;
         }
         if( buttons[ANT90])
             hardware+=300;
         /**
         *    Если выбран комплект TWIN, цены умножаются на 2
         **/
         var twinCoeff = buttons[TWIN]?2:1;         
         //вычислеине минимального авансового платежа сумма*на курс валюты* на колличесвто терммналов          
         var min_advance=Math.ceil((exchange[11])*twinCoeff);         
         //активация карточки
         var activateCard = Math.ceil((exchange[9])*twinCoeff);
         //стоимость установки
         var mount = exchange[(buttons[TWIN]==1?8:7)];                
         //=====================================================================================================
         //вывод на странице
         //=====================================================================================================
         //amount.innerHTML=software;
         activate.innerHTML= activateCard;
         advance.innerHTML=min_advance;
         mounting.innerHTML=mount;
         set.innerHTML=hardware;
         pack.cost_hardware.value=hardware;
         pack.cost_activate.value=activateCard;
         pack.cost_advance.value=min_advance;
         pack.cost_mount.value=mount;
         pack.cost_overall.value=hardware+activateCard+min_advance+mount;
         if( buttons[PAY_ALL])
         {
             hardwaremountloan.style.display = 'none';
             hardwaremountall.style.display = 'block';
             inszusammen.innerHTML = hardware+activateCard+min_advance+mount;
         }
         else
         {
             hardwaremountloan.style.display = 'block';
             hardwaremountall.style.display = 'none';             
             inszusammen.innerHTML = activateCard+min_advance;
         }
         //=====================================================================================================          
}

function check_order()
{
    with(document.order) {
    	filled=firstname.value.length*lastname.value.length*middlename.value.length*city.value.length*phone.value.length;
    }
    
    check_email=checkemail(document.order.email.value);
    if(filled && check_email) {
    	return true;
    } else {
    	mess1="";
    	mess2="";
    	if(!filled)	
    		mess1='Заполните обязательные поля.\n';    	
    	if(!check_email) 
    		mess2='Неправильно введен e-mail.';        
        alert(mess1+mess2);
        return false;
     }//~else somthing wrong
}

function checkemail(str)
{                         
    if(str=="")
        return true;   
    else {
        var testresults;
        var filter=/^([\w-]+(\.[\w-]+)*)@(([\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(\.[a-z]{2})?)$/i;
        if (filter.test(str))                                       
            testresults=true;       
        else                                           
            testresults=false;        
        return (testresults);
    }//~else
 }
 