﻿
function hide(id,end){
        if(document.getElementById(id)){
                node = document.getElementById(id);
				img = document.getElementById('n'+id);
				img2 = document.getElementById('f'+id);
				
                if (node.style.display == 'none'){
                        if (end==0){node.style.display='block';img.src='./pics/minus.gif';img2.src='./pics/fo.gif';}
                        else {node.style.display='block';img.src='./pics/minusend.gif';img2.src='./pics/fo.gif';}
                }else{
                        if (end==0){node.style.display='none';img.src='./pics/plus.gif';img2.src='./pics/fc.gif';}
                        else {node.style.display='none';img.src='./pics/plusend.gif';img2.src='./pics/fc.gif';}
                }     
        }       
}

function catClick(id){
    if(document.getElementById('main_foto_frame')){
        frame = document.getElementById('main_foto_frame');
        frame.src = 'goods.aspx?cat_id='+id;
        //document.getElementById('CatsPath').innerHTML = '<b> // '+ document.getElementById(id).innerHTML + ' </b>';
    }
}

function getCatName(elem){
   try{
         alert(document.getElementById('CatsPath').nodeName);
         alert(elem.tagName);
         return elem.nextSibling.firstChild.nodeValue;
   }catch (E) {
        return "";
   } 
}


function CatSearch(){
    if(document.getElementById('Search').value.length > 2){
         frame = document.getElementById('main_foto_frame');
         frame.src = 'search.aspx?search='+document.getElementById('Search').value;
    }else{
         alert("Длина строки поиска не может быть меньше 3 символов");
    }
}

function SetShowMiniatures(){
    if(document.getElementById('show_miniature')){
        if(document.getElementById('show_miniature').checked==true){
            document.getElementById('Miniatures').value='yes';
        }else{
            document.getElementById('Miniatures').value='no';
        }
        document.frm.submit();
    }
}


function filtClick(id){
    if(document.getElementById('filter_frame')){
        document.getElementById('filter_frame').style.height = 600;
        document.getElementById('filter_frame').style.display = 'block';
    }
}

//-------------------------------goods----------------------------//

function selected_articles(){
     cmp_goods = '';j=0;
     size = document.frm.cmp.length;   
           for(i=0; i<size; i++){
              if(document.frm.cmp[i] && document.frm.cmp[i].checked){
                  cmp_goods = cmp_goods + document.frm.cmp[i].value + ",";
                  j++;
              }
          }
     if(j > 1 && j < 11)return cmp_goods.substring(0, cmp_goods.length-1);
     else return '';

}

function cmp_open(){
    window.open('descriptionCmpPage.aspx?articles='+selected_articles(),"","");
}

function price_open(){
    window.open('http://price.sunrise.ru/index.aspx?article='+selected_articles(),"","");
}

//-------------------------desc----------------------------//
var iframe_timeout = 0;

function ComplaintClick(a){       
        PopUpClick('pop_up_complaint','term.sunrise.local/Complaint.aspx?type=noteDesc&goods='+a);
} 

function open_Complaint(width, height, content)
{
    ScrWindow=window.open("","","toolbar=no,location=no,left=0,top=0,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width="+width+",height="+height+"");
    if (ScrWindow != null && ScrWindow.opener == null) ScrWindow.opener=window;
    ScrWindow.document.open();
    ScrWindow.document.writeln ("<html><head><title>Обратная связь</title></head><body>"+content+"</body></html>");
    ScrWindow.document.close();
} 

function ComplaintSend(){
     if(document.frm.message.value.length > 0 && document.frm.contact.value.length > 0 && document.frm.SubscriptionGroup.value > 0){
        if(document.getElementById('pop_up_sourcecomplaint') && document.getElementById('pop_up_sourcecomplaint').contentWindow.document.getElementById('complaint')){
            document_iframe = document.getElementById('pop_up_sourcecomplaint').contentWindow.document;
            document_iframe.frm.SubscriptionGroup.value=document.frm.SubscriptionGroup.value;
            document_iframe.frm.contact.value=document.frm.contact.value;
            document_iframe.frm.message.value=document.frm.message.value;
            document.getElementById('pop_up_sourcecomplaint').contentWindow.document.frm.submit();
        }else{
            alert("Ошибка на странице, форма жалобы не доступна!");
        }
}else{
        alert("Выберите тип жалобы и заполните форму!");
     }
}

//-------------------------------big-foto--------------------------------//

function ShowBigFoto(img){
	MessageShow('<div style="cursor:hand; background: url('+img+') center no-repeat; width: 800px; height: 800px;"><IMG src="sdf.png"></div>', 0); 
}

function ShowSmallFoto(img){
	MessageShow('<div style="cursor:hand; background: url('+img+') center no-repeat; width: 200px; height: 200px;"><IMG src="sdf_s.png"></div>', 0); 
}

function SmallFotoClose(){
	MessageClose(); 
}

//------------------------basket---------------------------//

var basket_state = 1;

function b_put(id,s,p,a,n){
        c = document.getElementById('rid').value;
        document.getElementById('basketIfame').src='basketPage.aspx?GoodsId='+id+'&Series='+s+'&CategoryId='+c+'&Price='+p+'&Article='+a+'&Name='+n;
        basket_state = 0;    
        MessageShow('<div style="padding:15;"><b>В корзину добавлен товар<br/>'+n+'</b></div>', 500);  
}

function basketIframeOnload(){
        if(document.getElementById('basketIfame').contentWindow.document.getElementById('OrderInfo')){
                doc = document.getElementById('basketIfame').contentWindow.document.getElementById('OrderInfo').innerHTML;
                document.getElementById('basketIframeBody').innerHTML=doc;
        }else{
             document.getElementById('basketIframeBody').innerHTML='ошибка загрузки корзины';
        }
        //----------for opera------------------
        if(basket_state==0){ 
            document.getElementById('basketIfame').src='basketPage.aspx';
            basket_state=1;
        }
}

//-------------------------------check--------------------------------//
function checkQuantity(elem){
    str = elem.value;
    if(IsIntNum(str)==false && str.length > 0){
        alert("неправильный ввод: "+str);
        elem.value = 0;
    }
}

function IsIntNum(sText){
   ValidChars = "0123456789";
   IsNumber=true;
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) IsNumber = false;
   }
   return IsNumber; 
 }

function IsFloatNum(sText){
   ValidChars = "0123456789.,";
   IsNumber=true;
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1)  IsNumber = false;
   }
   return IsNumber;
 }

function CheckLength(elem, slength){
        str = elem.value;
        if(str.length > slength){
             alert("Длина введенной строки превышает допустимый размер в "+slength+" символов");
             elem.value = str.substring(0, slength);
        }
}

