
selected = new Array()
index = 0
MainVar = ''

function DoNews (newsID)
        {

                if (document.getElementById ("news-"+newsID).style.display == "block")
                        {document.getElementById ("news-"+newsID).style.display = "none";}
                        else {document.getElementById ("news-"+newsID).style.display = "block";}
        }

function OpenWindow(url,name,opt)
{
window.open(url,name,opt)
}


function statbar(txt) {
   window.status = txt;
}




function setpostvar(form,mod_name,mod_value) {
var postvar=''
   if(!document.moduls.postvars.value){document.moduls.postvars.value = ''}


if(document.moduls.postvars.value.indexOf(mod_name) == -1){
   for(i=0;i < mod_value;i++){
   if(document.moduls.postvars.value == '' && postvar == ''){
   postvar += mod_name
   }else{
   postvar += "&" + mod_name
        }
   							 }

   document.moduls.postvars.value += postvar
                                                          }else{
var length = document.moduls.postvars.value.length
var start_n = document.moduls.postvars.value.indexOf(mod_name)


   start_flag = start_n;

   for(i=start_n; i < length - 1; i++){

   and_index = document.moduls.postvars.value.indexOf('&',start_flag)
   if(and_index == -1){
                      first_str = document.moduls.postvars.value.substring(0,start_n-1)
                      document.moduls.postvars.value = first_str
                         for(i=0;i < mod_value;i++){
                                    if(i == 0 && start_n == 0)
                                    postvar += mod_name
                                    else
                                    postvar += "&" + mod_name
                                                   }
                                    document.moduls.postvars.value += postvar
                         statbar(document.moduls.postvars.value)
                         return;

                      }else{
   if(document.moduls.postvars.value.indexOf(mod_name,and_index) != -1){

                                                                       start_flag = document.moduls.postvars.value.indexOf(mod_name,and_index)
                                                                       }else{

                                                                       first_str = document.moduls.postvars.value.substring(0,start_n-1)
                                                                       last_str = document.moduls.postvars.value.substring(and_index,length)
                                                                       document.moduls.postvars.value = first_str

                                                                       for(i=0;i < mod_value;i++){
                                                                                  if(i == 0 && start_n == 0)
                                    											  postvar += mod_name
                                    											  else
                                                                                  postvar += "&" + mod_name

                                                                                               }
                                                                       document.moduls.postvars.value += postvar + last_str
                                                                       statbar(document.moduls.postvars.value)
                                                                       return;
                                                                            }
                           }


   									  }




                                                               }




statbar(document.moduls.postvars.value)
}

function check_register(){
if (document.order.rospis.checked) {
   return true
   }else {
      alert("Пожалуйста, подтвердите правильность введенных данных")
      return false}
}

function change_up_lift(){
if (document.order.ship_lift.selectedIndex == 1) {
    document.order.ship_price_podem.value = 0;
   }else if(document.order.ship_lift.selectedIndex == 0){
    document.order.ship_price_podem.value = document.order.up_lift_no.value;
   }else if(document.order.ship_lift.selectedIndex == 2){
    document.order.ship_price_podem.value = document.order.up_lift_pass.value;
   }
pereschitat()
}

function pereschitat(){
var summa_zakaza = parseFloat(document.order.summa_zakaza.value)
var dostavka = parseFloat(document.order.ship_price_dostavka.value)
var podem = parseFloat(document.order.ship_price_podem.value)
var sborka = parseFloat(document.order.ship_price_sborka.value)


var summa = summa_zakaza + dostavka + podem + sborka
if(document.order.ship_mne.value == "true"){
summa += parseFloat(document.order.k_mne.value)
}

if(document.order.ship_mvp.value == "true"){
summa += parseFloat(document.order.k_mvp.value)
}
if(document.order.ship_zf.value == "true"){
summa += parseFloat(document.order.k_zf.value)
}


document.order.ship_price_o.value = summa
}

function moveinto(theform, select1)
{
if (select1 != ''){

i = theform.select2.length
option0 = new Option(select1, select1)
theform.select2.options[i]=option0
set_text(theform)
display(theform)
createvar(theform)
					}
}

function remove(theform)
{
var i=theform.select2.selectedIndex
theform.select2.options[i] = null
set_text(theform)
display(theform)
createvar(theform)
}

function getkol(sel,searchSTR)
{
var len = sel.length
var kolvo = 0;
for (i=0; i <len; i++) {
	if (sel.options[i].text == searchSTR)
	{
	kolvo++
	}
}
return kolvo;
}



function set_text(theform)
{
var len = theform.select2.length
var i
for (i=0;i<len;i++)
{
var first = theform.select2.options[i].text
	if(!get(first)){
var kol = getkol(theform.select2,first)
set(first)
                   }
}
}

function display(theform){
theform.textarea.value = ''
var len = selected.length
var i
for (i=0;i<len;i++){
var kol = getkol(theform.select2,selected[i])
theform.textarea.value += selected[i] + " Количество - " + kol + "\n"
				   }
}

function display_select(theform)
{
theform.textarea.value = ''
var len = theform.select2.length
var i
for (i=0;i<len;i++){
var kol = getkol(theform.select2,theform.select2.options[i].text)
theform.textarea.value += theform.select2.options[i].text + " Количество - " + kol + "\n"
				   }
}

function set(first)
{
selected[index] = first
index++
}

function get(first)
{
var len = selected.length
var i = 0
for (i = 0; i <= len; i++){
	if (selected[i] == first){
    return true;
    					     }
						 }
return false;
}

function createvar(theform)
{
MainVar =""
var len = theform.select2.options.length
var i
for (i = 0; i < len ; i++)
{
	if (i == 0){MainVar += theform.select2.options[i].text}else{
    MainVar += "&" + theform.select2.options[i].text           }
}
theform.selitem.value = MainVar;
}