function onFormSubm()
{
	var path='/catalog/'+$('#dVName').val()+'/'+$('#dPage').val()+'/'+$('#dShow').val()+'/'+$('#dSort').val()+'/';
	window.location=path;
	return false;
}

function onFormSubmStac()
{
	var path='/staccatalog/'+$('#dVName').val()+'/'+$('#dPage').val()+'/'+$('#dShow').val()+'/'+$('#dSort').val()+'/';
	window.location=path;
	return false;
}

function onFormCDMASubm()
{
    var path='/cdmacatalog/'+$('#dVName').val()+'/'+$('#dPage').val()+'/'+$('#dShow').val()+'/'+$('#dSort').val()+'/';
    window.location=path;
    return false;
}

function setExven(el)
{
	var id=el.options[el.selectedIndex].value;
	var ve=document.getElementById('ve');
	if(id==0)
    {
         ve.name='';
        ve.checked='0';
    }else{
        ve.name='search[vendors]['+id+']';
        ve.checked='checked';}
    
}

function getBrowserInfo()
{
	var t,v = undefined;
	if (window.opera) t = 'Opera';
	else if (document.all)
	{
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	}
	else if (navigator.appName) t = 'Netscape';
	return {type:t,version:v};
}
 
function bookmark(a)
{
	var url = window.document.location;
	var title = window.document.title;
	var b = getBrowserInfo();
	if (b.type == 'IE' && 9 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
	else if (b.type == 'Opera')
	{
		a.href = url;
		a.rel = "sidebar";
		a.title = url+','+title;
		return true;
	}
	else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
	return false;
}

//Поиск
function showSrh()
{
	$("#shr_p1").hide();
	$(".shr_p2").fadeIn("slow");
}
function hideSrh()
{
    $("#shr_p1").show();
    $(".shr_p2").fadeOut("slow");
for(var i=33; i<=55; ++i)
{
	if(document.forms.search.elements[i].type=='checkbox')
	{
		document.forms.search.elements[i].checked=false;
	}else if(document.forms.search.elements[i].type=='text')
	{
		document.forms.search.elements[i].value='';	
	}
}
	
}


//Прайсы
function counter( a , p )
{
    $.get("/redirect.html", { a: a, p: p } );
}
function showCommentForm( phoneId )
{
$.get("/ajax/addComment.php", { phoneId : phoneId },
  function(data){
    $("#addComment").html(data);
    $(".add_bot").hide();
    $(".add_hide").show();
  });
}
function hideCommentForm()
{
    $(".add_bot").show();
    $(".add_hide").hide();
    $("#addComment").html('');
}

function showMistakeForm( phoneId )
{
$.get("/ajax/addMistake.php", { phoneId : phoneId },
  function(data){
    $("#addMistake").html(data);
  });
}


// Сравнение
$(document).ready(
function ()
{
    $("#ph1").change(function (){
        changeModel( $(this).val() , $("#sph1") );
    });
    $("#ph2").change(function (){
        changeModel( $(this).val() , $("#sph2") );
    });
    if($("#ph3")&&$("#ph3")!=undefined)
    {
         $("#ph3").change(function (){
        changeModel( $(this).val() , $("#sph3") );
        });
    }
});
function changeModel( vendorId , selObj )
{
	if (cdma)
	{
		$.get("/ajax/compare.php",{ vendorId: vendorId, cdma: 1}, function(data){
		selObj.html(data);
		});
	}
	else
	{
		$.get("/ajax/compare.php",{ vendorId: vendorId}, function(data){
			selObj.html(data);
		});
	}
}

function changeNoteModel( vendorId , selObj )
{
	$.get("/ajax/notecompare.php",{ vendorId: vendorId }, function(data){
		$("#sn" + selObj).html(data);
	});
}

function ChModel()
{
	if (!$('#sph1').val())
	{
		alert("Выберите первый телефон для сравнения");
		$('#sph1').focus();
		return false;
	}
	if (!$('#sph2').val())
	{
		alert("Выберите второй телефон для сравнения");
		$('#sph2').focus();
		return false;
	}
	var str = '/compare.html?p1=' + $('#sph1').val() + '&p2=' + $('#sph2').val()
	if ($('#sph3') != undefined && $('#sph3').val() != undefined)
	{
		if (!$('#sph3').val())
		{
			alert("Выберите третий телефон для сравнения");
			$('#sph3').focus();
			return false;
		}
		str += '&p3=' + $('#sph3').val();
	}
	if (cdma)
		str += '&cdma=1';
	window.location = str;
}

function ChangeModel()
{
	if (!$('#sn1').val())
	{
		alert("Выберите первый телефон для сравнения");
		$('#sn1').focus();
		return false;
	}
	if (!$('#sn2').val())
	{
		alert("Выберите второй телефон для сравнения");
		$('#sn2').focus();
		return false;
	}
	var str = '/notecompare.html?n1=' + $('#sn1').val() + '&n2=' + $('#sn2').val()
	if ($('#sn3') != undefined && $('#sn3').val() != undefined)
	{
		if (!$('#sn3').val())
		{
			alert("Выберите третий телефон для сравнения");
			$('#sph3').focus();
			return false;
		}
		str += '&n3=' + $('#sn3').val();
	}
	window.location = str;
}

function ChangeStacModel()
{
	if (!$('#scph1').val())
	{
		alert("Выберите первый телефон для сравнения");
		$('#scph1').focus();
		return false;
	}
	if (!$('#scph2').val())
	{
		alert("Выберите второй телефон для сравнения");
		$('#scph2').focus();
		return false;
	}
	var str = '/staccompare.html?sp1='+$("#scph1").val()+'&sp2='+$("#scph2").val()
	if ($('#scph3')!=undefined&&$('#scph3').val()!=undefined)
	{
		if (!$('#scph3').val())
		{
			alert("Выберите третий телефон для сравнения");
			$('#scph3').focus();
			return false;
		}
		str += '&sp3=' + $('#scph3').val();
	}
	window.location = str;
}
// Выбор в блоке поиска по словам

function changeSelectModel( vendorId , selObj , phoneId )
{
    $.get("/ajax/select.php",{ vendorId: vendorId , phoneId: phoneId }, function(data){
      selObj.html(data);
    });
}
function changeSelectUrl( phoneRewUrl )
{
    window.location.href = '/phone/'+phoneRewUrl+'.html';
}

function StacModelLoad(vendorId, selObj)
{
	$.get("/ajax/staccompare.php",{ vendorId: vendorId }, function(data){
		$("#scph" + selObj).html(data);
	});
}


// СМС
function chengeSMSLen()
{
   var text=$("#SMSText").val();
   
   if($('#SMSLeght').val() == '')
   {
      $("#SMSLeght").val(70);
   }
   var limit = $("#SMSLeght").val();
   
   if(text.length > limit )
   {
      $("#SMSText").val( text.substring(0,limit) );
      $("#SMSTextLeght").html( '0' );
   }
   else
   {
      $("#SMSTextLeght").html( limit-text.length ); 
   }
}
function liFormat (row, i, num) {
    var result = row;
    return result;
}
function selectItem(li) {
    if( li == null ) var sValue = '';
    if( !!li.extra ) var sValue = li.extra[2];
    else var sValue = li.selectValue;
document.getElementById("keywordsinp").focus();
document.getElementById("keywords").submit();
    //alert("Выбрана запись с ID: " + sValue);
}
function Aut()
{
    $("#keywordsinp").autocomplete("/ajax/autocomplete.php", {
    delay:10,
    minChars:2,
    matchSubset:false,
    autoFill:false,
    matchContains:1,
    cacheLength:0,
    selectFirst:false,
    formatItem:liFormat,
    maxItemsToShow:17,
    onItemSelect:selectItem
});
}
$(document).ready(function(){

// --- Автозаполнение ---




// --- Автозаполнение2 ---


// --- Автозаполнение2 ---

    if (!cdma)
    {
        if (stac)
            SetStacCompare(0, '');
        else
		{
			if (note)
	            SetNoteCompare(0, '');
			else
    	        SetCompare(0, '');
		}
    }
    else
    {
        SetCDMACompare(0, '');
    }
});

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ';path=/'+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function SetCompare(id,name)
{
    if(document.getElementById('fixed').style.display=='none')
    {
        document.getElementById('fixed').style.display='block';
    }
    var c1,c2,c3,err=0;
    c1= getCookie('p1');
    c2= getCookie('p2');
    c3= getCookie('p3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(id!=0)
    {
    if(c1[0]!=''&&c1[0]==id)
    {
       setCookie('p1','',5);
       c1[0]='';
       if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c2[0]!=''&&c2[0]==id)
    {
       setCookie('p2','',5);
       c2[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c3[0]!=''&&c3[0]==id)
    {
       setCookie('p3','',5);
       c3[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    {
    if(c1[0]!=''&&c3[0]!=''&&c2[0]!='')
    {
        err=1;
    }else
    {
        if(c1[0]=='')
        {
             setCookie('p1',id+','+name,5);
             c1[0]=id;
             c1[1]=name;
        }else if(c2[0]=='')
        {
             setCookie('p2',id+','+name,5);
             c2[0]=id;
             c2[1]=name;
        }else if(c3[0]=='')
        {
             setCookie('p3',id+','+name,5);
             c3[0]=id;
             c3[1]=name;
        } 
    }
    }
    }
    var c=0;
    var str='';
    if(c1[0]==''&&c3[0]==''&&c2[0]=='')
        document.getElementById('fixed').style.display='none';
    else
    {    
    document.getElementById('fcont').innerHTML='';
    if(c1[0]!='')
    {
        document.getElementById('fcont').innerHTML='<div><div class="left">'+c1[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCompare('+c1[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c1[0]+',';
        ++c;
    }
    if(c2[0]!='')
    {
    document.getElementById('fcont').innerHTML+='<div><div class="left">'+c2[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCompare('+c2[0]+',\'\')" title="Закрыть" /></div></div>'; 
       str+=c2[0]+',';
       ++c;
    }
    if(c3[0]!='')
    {
        document.getElementById('fcont').innerHTML+='<div><div class="left">'+c3[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCompare('+c3[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c3[0];
        ++c;
    }else
        str+='0';
    if(err==1)
        document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Не более 3х телефонов!';
    if(c==1)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Выберите еще 1 или 2 телефона'; 
    }
    if(c==2)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" />'; 
    } 
    document.getElementById('fcont').innerHTML+='<br class="clear" /><br /><input type="button" onclick="Compare('+str+')" value="Сравнить">'; 
    }
}
function Compare(p1,p2,p3)
{
    if(!p2)
    {
        //alert('Для сравнения необходимо выбрать 2-3 телефона.');
    return;
    }var str='/compare.html?p1='+p1+'&p2='+p2;
    setCookie('p1','');
    setCookie('p2','');
    if(p3!=undefined)
    {
         str+='&p3='+p3;
         setCookie('p3','');
    }
    window.location=str;
}
function ClearCompare()
{
    if(document.getElementById('fixed').style.display=='block')
    {
        document.getElementById('fixed').style.display='none';
    }
    c1= getCookie('p1');
    c2= getCookie('p2');
    c3= getCookie('p3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(c1[0]!='')
    {
       setCookie('p1','',5);
       if(document.getElementById('chp'+c1[0])!=undefined)
        document.getElementById('chp'+c1[0]).checked=false;
       if(document.getElementById('chi'+c1[0])!=undefined)
        document.getElementById('chi'+c1[0]).checked=false;    
    }
    if(c2[0]!='')
    {
       setCookie('p2','',5);
        if(document.getElementById('chp'+c2[0])!=undefined)
        document.getElementById('chp'+c2[0]).checked=false;
       if(document.getElementById('chi'+c2[0])!=undefined)
        document.getElementById('chi'+c2[0]).checked=false;    
    }
    if(c3[0]!='')
    {
       setCookie('p3','',5);
        if(document.getElementById('chp'+c3[0])!=undefined)
        document.getElementById('chp'+c3[0]).checked=false;
       if(document.getElementById('chi'+c3[0])!=undefined)
        document.getElementById('chi'+c3[0]).checked=false;    
    }
}
function Vote(phone, vote)
{
    var votes=getCookie('votes');
    votes=votes.split(',');
    for(i=0; i<votes.length; ++i)
    {
        if(votes[i]==phone)
            return;
    }
    votes[votes.length]=phone;
    votes=votes.join(',');
    setCookie('votes',votes,1);
    $.post("/ajax/addVote.php", { phoneId : phone, pvote: vote },
  function(data){
      var str='';      
      var star=parseInt(data);
      for(i=0; i<5; ++i)
      {
          if(i!=0)
            str+='&nbsp;';
          if(i<star)
            str+='<img height="13" width="15" alt="" src="/misc/img/star_full.gif">'; 
         else
            str+='<img height="13" width="15" alt="" src="/misc/img/star_empty.gif">'; 
      }
      if(document.getElementById('rates'+phone))
        document.getElementById('rates'+phone).innerHTML=str;
      if(document.getElementById('ratee'+phone))
        document.getElementById('ratee'+phone).innerHTML=str;
      
  });

}

function StacVote(phone, vote)
{
    var votes=getCookie('votes');
    votes=votes.split(',');
    for(i=0; i<votes.length; ++i)
    {
        if(votes[i]==phone)
        return;
    }
    votes[votes.length]=phone;
    votes=votes.join(',');
    setCookie('votes',votes,1);
    $.post("/ajax/addStacVote.php", { phoneId : phone, pvote: vote },
  function(data){
      var str='';      
      var star=parseInt(data);
      for(i=0; i<5; ++i)
      {
          if(i!=0)
            str+='&nbsp;';
          if(i<star)
            str+='<img height="13" width="15" alt="" src="/misc/img/star_full.gif">'; 
         else
            str+='<img height="13" width="15" alt="" src="/misc/img/star_empty.gif">'; 
      }
      if(document.getElementById('rates'+phone))
        document.getElementById('rates'+phone).innerHTML=str;
      if(document.getElementById('ratee'+phone))
        document.getElementById('ratee'+phone).innerHTML=str;
      
  });

}

function hiVote(phone,vote,pre,pre2)
{
    if(pre2==undefined)
    pre2='';
      for(i=1; i<=5; ++i)
      {
          if(i<=vote)
          {
              document.getElementById(pre+phone+'_'+i).src='/misc/img/star_full'+pre2+'.gif';
          }else
          {
              if(vote+1>=i+0.3&& vote+1<=i+0.6)
              document.getElementById(pre+phone+'_'+i).src='/misc/img/star_half.gif';
              else
              document.getElementById(pre+phone+'_'+i).src='/misc/img/star_empty.gif';
          }
      }
}



function getStacCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function SetStacCompare(id,name)
{
    if(document.getElementById('fixed').style.display=='none')
    {
        document.getElementById('fixed').style.display='block';
    }
    var c1,c2,c3,err=0;
    c1= getStacCookie('sp1');
    c2= getStacCookie('sp2');
    c3= getStacCookie('sp3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(id!=0)
    {
    if(c1[0]!=''&&c1[0]==id)
    {
       setStacCookie('sp1','',5);
       c1[0]='';
       if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c2[0]!=''&&c2[0]==id)
    {
       setStacCookie('sp2','',5);
       c2[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c3[0]!=''&&c3[0]==id)
    {
       setStacCookie('sp3','',5);
       c3[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    {
    if(c1[0]!=''&&c3[0]!=''&&c2[0]!='')
    {
        err=1;
    }else
    {
        if(c1[0]=='')
        {
             setStacCookie('sp1',id+','+name,5);
             c1[0]=id;
             c1[1]=name;
        }else if(c2[0]=='')
        {
             setStacCookie('sp2',id+','+name,5);
             c2[0]=id;
             c2[1]=name;
        }else if(c3[0]=='')
        {
             setStacCookie('sp3',id+','+name,5);
             c3[0]=id;
             c3[1]=name;
        } 
    }
    }
    }
    var c=0;
    var str='';
    if(c1[0]==''&&c3[0]==''&&c2[0]=='')
        document.getElementById('fixed').style.display='none';
    else
    {    
    document.getElementById('fcont').innerHTML='';
    if(c1[0]!='')
    {
        document.getElementById('fcont').innerHTML='<div><div class="left">'+c1[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetStacCompare('+c1[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c1[0]+',';
        ++c;
    }
    if(c2[0]!='')
    {
    document.getElementById('fcont').innerHTML+='<div><div class="left">'+c2[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetStacCompare('+c2[0]+',\'\')" title="Закрыть" /></div></div>'; 
       str+=c2[0]+',';
       ++c;
    }
    if(c3[0]!='')
    {
        document.getElementById('fcont').innerHTML+='<div><div class="left">'+c3[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetStacCompare('+c3[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c3[0];
        ++c;
    }else
        str+='0';
    if(err==1)
        document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Не более 3х телефонов!';
    if(c==1)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Выберите еще 1 или 2 телефона'; 
    }
    if(c==2)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" />'; 
    } 
    document.getElementById('fcont').innerHTML+='<br class="clear" /><br /><input type="button" onclick="StacCompare('+str+')" value="Сравнить">'; 
    }
}
function StacCompare(p1,p2,p3)
{
    if(!p2)
    {
        //alert('Для сравнения необходимо выбрать 2-3 телефона.');
    return;
    }var str='/staccompare.html?sp1='+p1+'&sp2='+p2;
    setStacCookie('sp1','');
    setStacCookie('sp2','');
    if(p3!=undefined)
    {
         str+='&sp3='+p3;
         setStacCookie('sp3','');
    }
    window.location=str;
}
function ClearStacCompare()
{
    if(document.getElementById('fixed').style.display=='block')
    {
        document.getElementById('fixed').style.display='none';
    }
    c1= getStacCookie('sp1');
    c2= getStacCookie('sp2');
    c3= getStacCookie('sp3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(c1[0]!='')
    {
       setStacCookie('sp1','',5);
       if(document.getElementById('chp'+c1[0])!=undefined)
        document.getElementById('chp'+c1[0]).checked=false;
       if(document.getElementById('chi'+c1[0])!=undefined)
        document.getElementById('chi'+c1[0]).checked=false;    
    }
    if(c2[0]!='')
    {
       setStacCookie('sp2','',5);
        if(document.getElementById('chp'+c2[0])!=undefined)
        document.getElementById('chp'+c2[0]).checked=false;
       if(document.getElementById('chi'+c2[0])!=undefined)
        document.getElementById('chi'+c2[0]).checked=false;    
    }
    if(c3[0]!='')
    {
       setStacCookie('sp3','',5);
        if(document.getElementById('chp'+c3[0])!=undefined)
        document.getElementById('chp'+c3[0]).checked=false;
       if(document.getElementById('chi'+c3[0])!=undefined)
        document.getElementById('chi'+c3[0]).checked=false;    
    }
}

function setStacCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ';path=/'+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}



function getCDMACookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function SetCDMACompare(id,name)
{
    if(document.getElementById('fixed').style.display=='none')
    {
        document.getElementById('fixed').style.display='block';
    }
    var c1,c2,c3,err=0;
    c1= getCDMACookie('cdp1');
    c2= getCDMACookie('cdp2');
    c3= getCDMACookie('cdp3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(id!=0)
    {
    if(c1[0]!=''&&c1[0]==id)
    {
       setStacCookie('cdp1','',5);
       c1[0]='';
       if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c2[0]!=''&&c2[0]==id)
    {
       setStacCookie('cdp2','',5);
       c2[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c3[0]!=''&&c3[0]==id)
    {
       setStacCookie('cdp3','',5);
       c3[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    {
    if(c1[0]!=''&&c3[0]!=''&&c2[0]!='')
    {
        err=1;
    }else
    {
        if(c1[0]=='')
        {
             setCDMACookie('cdp1',id+','+name,5);
             c1[0]=id;
             c1[1]=name;
        }else if(c2[0]=='')
        {
             setCDMACookie('cdp2',id+','+name,5);
             c2[0]=id;
             c2[1]=name;
        }else if(c3[0]=='')
        {
             setCDMACookie('cdp3',id+','+name,5);
             c3[0]=id;
             c3[1]=name;
        } 
    }
    }
    }
    var c=0;
    var str='';
    if(c1[0]==''&&c3[0]==''&&c2[0]=='')
        document.getElementById('fixed').style.display='none';
    else
    {    
    document.getElementById('fcont').innerHTML='';
    if(c1[0]!='')
    {
        document.getElementById('fcont').innerHTML='<div><div class="left">'+c1[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCDMACompare('+c1[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c1[0]+',';
        ++c;
    }
    if(c2[0]!='')
    {
    document.getElementById('fcont').innerHTML+='<div><div class="left">'+c2[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCDMACompare('+c2[0]+',\'\')" title="Закрыть" /></div></div>'; 
       str+=c2[0]+',';
       ++c;
    }
    if(c3[0]!='')
    {
        document.getElementById('fcont').innerHTML+='<div><div class="left">'+c3[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetCDMACompare('+c3[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c3[0];
        ++c;
    }else
        str+='0';
    if(err==1)
        document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Не более 3х телефонов!';
    if(c==1)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Выберите еще 1 или 2 телефона'; 
    }
    if(c==2)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" />'; 
    } 
    document.getElementById('fcont').innerHTML+='<br class="clear" /><br /><input type="button" onclick="CDMACompare('+str+')" value="Сравнить">'; 
    }
}
function CDMACompare(p1,p2,p3)
{
    if(!p2)
    {
        //alert('Для сравнения необходимо выбрать 2-3 телефона.');
    return;
    }var str='/compare.html?cdma=1&p1='+p1+'&p2='+p2;
    setCDMACookie('cdp1','');
    setCDMACookie('cdp2','');
    if(p3!=undefined)
    {
         str+='&p3='+p3;
         setStacCookie('cdp3','');
    }
    window.location=str;
}
function ClearCDMACompare()
{
    if(document.getElementById('fixed').style.display=='block')
    {
        document.getElementById('fixed').style.display='none';
    }
    c1= getCDMACookie('cdp1');
    c2= getCDMACookie('cdp2');
    c3= getCDMACookie('cdp3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(c1[0]!='')
    {
       setStacCookie('cdp1','',5);
       if(document.getElementById('chp'+c1[0])!=undefined)
        document.getElementById('chp'+c1[0]).checked=false;
       if(document.getElementById('chi'+c1[0])!=undefined)
        document.getElementById('chi'+c1[0]).checked=false;    
    }
    if(c2[0]!='')
    {
       setStacCookie('cdp2','',5);
        if(document.getElementById('chp'+c2[0])!=undefined)
        document.getElementById('chp'+c2[0]).checked=false;
       if(document.getElementById('chi'+c2[0])!=undefined)
        document.getElementById('chi'+c2[0]).checked=false;    
    }
    if(c3[0]!='')
    {
       setStacCookie('cdp3','',5);
        if(document.getElementById('chp'+c3[0])!=undefined)
        document.getElementById('chp'+c3[0]).checked=false;
       if(document.getElementById('chi'+c3[0])!=undefined)
        document.getElementById('chi'+c3[0]).checked=false;    
    }
}

function setCDMACookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ';path=/'+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function checkRadios() {
 var el = document.comm_form.elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
itemchecked = true;
break;
}
   }
   if(!itemchecked) {
    if(el[i].focus)
     el[i].focus();
return false;
   }
  }
 }
 return true;
} 

function CheckForm()
{
    if (!document.getElementById("name").value)
    {
        alert('Введите Ваше имя.');
        document.getElementById("name").focus();
        return false;
    }
    if (!document.getElementById("comments").value)
    {
        alert('Введите текст комментария.');
        document.getElementById("comments").focus();
        return false;
    }
    if (!$("#captcha").val())
    {
        alert('Введите текст с картинки.');
        $("#captcha").focus();
        return false;
    }
    if (!checkRadios())
    {
        alert('Поставьте оценку телефону.');
        return false;
    }
    return true;
}

function checklimit(e)
{
    if (!e)
        e = window.event;
    if (current.value.length > 400 && e.keyCode != 116 && e.keyCode != 9 && e.keyCode != 18 && e.keyCode != 16 && e.keyCode != 122 && e.keyCode != 46 && e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40 && e.keyCode != 33)
        return false;
    return true;
}


function hinVote(note, vote, pre, pre2)
{
    if(pre2==undefined)
    pre2='';
      for(i=1; i<=5; ++i)
      {
          if(i<=vote)
          {
              document.getElementById(pre+note+'_'+i).src='/misc/img/star_full'+pre2+'.gif';
          }else
          {
              if(vote+1>=i+0.3&& vote+1<=i+0.6)
              document.getElementById(pre+note+'_'+i).src='/misc/img/star_half.gif';
              else
              document.getElementById(pre+note+'_'+i).src='/misc/img/star_empty.gif';
          }
      }
}


function nVote(note, vote)
{
    var votes=getCookie('votes');
    votes=votes.split(',');
    for(i=0; i<votes.length; ++i)
    {
        if(votes[i]==note)
            return;
    }
    votes[votes.length]=note;
    votes=votes.join(',');
    setCookie('votes',votes,1);
    $.post("/ajax/addnoteVote.php", { noteId : note, pvote: vote },
  function(data){
      var str='';      
      var star=parseInt(data);
      for(i=0; i<5; ++i)
      {
          if(i!=0)
            str+='&nbsp;';
          if(i<star)
            str+='<img height="13" width="15" alt="" src="/misc/img/star_full.gif">'; 
         else
            str+='<img height="13" width="15" alt="" src="/misc/img/star_empty.gif">'; 
      }
      if(document.getElementById('rates'+note))
        document.getElementById('rates'+note).innerHTML=str;
      if(document.getElementById('ratee'+note))
        document.getElementById('ratee'+note).innerHTML=str;
      
  });

}

/*function setSearchCookie(name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function setSearchCookie(name, value, props) {
   props = props || {}
	    var exp = props.expires
	    if (typeof exp == "number" && exp) {
	        var d = new Date()
	        d.setTime(d.getTime() + exp*1000)
	        exp = props.expires = d
	    }
	    if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }
	 
	    value = encodeURIComponent(value)
	    var updatedCookie = name + "=" + value
	    for(var propName in props){
        updatedCookie += "; " + propName
	        var propValue = props[propName]
	        if(propValue !== true){ updatedCookie += "=" + propValue }
	    }
	    document.cookie = updatedCookie
	 
}

function deleteCookie(name) {
	    setCookie(name, null, { expires: -1 })
}*/






function SetNoteCompare(id,name)
{
    if(document.getElementById('fixed').style.display=='none')
    {
        document.getElementById('fixed').style.display='block';
    }
    var c1,c2,c3,err=0;
    c1= getCookie('n1');
    c2= getCookie('n2');
    c3= getCookie('n3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(id!=0)
    {
    if(c1[0]!=''&&c1[0]==id)
    {
       setCookie('n1','',5);
       c1[0]='';
       if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c2[0]!=''&&c2[0]==id)
    {
       setCookie('n2','',5);
       c2[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    if(c3[0]!=''&&c3[0]==id)
    {
       setCookie('n3','',5);
       c3[0]='';
        if(document.getElementById('chp'+id)!=undefined)
        document.getElementById('chp'+id).checked=false;
       if(document.getElementById('chi'+id)!=undefined)
        document.getElementById('chi'+id).checked=false;    
    }else
    {
    if(c1[0]!=''&&c3[0]!=''&&c2[0]!='')
    {
        err=1;
    }else
    {
        if(c1[0]=='')
        {
             setCookie('n1',id+','+name,5);
             c1[0]=id;
             c1[1]=name;
        }else if(c2[0]=='')
        {
             setCookie('n2',id+','+name,5);
             c2[0]=id;
             c2[1]=name;
        }else if(c3[0]=='')
        {
             setCookie('n3',id+','+name,5);
             c3[0]=id;
             c3[1]=name;
        } 
    }
    }
    }
    var c=0;
    var str='';
    if(c1[0]==''&&c3[0]==''&&c2[0]=='')
        document.getElementById('fixed').style.display='none';
    else
    {    
    document.getElementById('fcont').innerHTML = '';
    if(c1[0]!='')
    {
        document.getElementById('fcont').innerHTML='<div><div class="left">'+c1[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetNoteCompare('+c1[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c1[0]+',';
        ++c;
    }
    if(c2[0]!='')
    {
    document.getElementById('fcont').innerHTML+='<div><div class="left">'+c2[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetNoteCompare('+c2[0]+',\'\')" title="Закрыть" /></div></div>'; 
       str+=c2[0]+',';
       ++c;
    }
    if(c3[0]!='')
    {
        document.getElementById('fcont').innerHTML+='<div><div class="left">'+c3[1]+'</div><div class="right"> <img src="/misc/img/delete_ico.png" width="12" height="12" onclick="SetNoteCompare('+c3[0]+',\'\')" title="Закрыть" /></div></div>'; 
        str+=c3[0];
        ++c;
    }else
        str+='0';
    if(err==1)
        document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Не более 3х ноутбуков!';
    if(c==1)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" /><br />Выберите еще 1 или 2 ноутбука'; 
    }
    if(c==2)
    {
         document.getElementById('fcont').innerHTML+='<br class="clear" />'; 
    } 
    document.getElementById('fcont').innerHTML+='<br class="clear" /><br /><input type="button" onclick="NoteCompare('+str+')" value="Сравнить">'; 
    }
}
function NoteCompare(n1,n2,n3)
{
    if(!n2)
    {
        //alert('Для сравнения необходимо выбрать 2-3 телефона.');
    return;
    }var str='/notecompare.html?n1='+n1+'&n2='+n2;
    setCookie('n1','');
    setCookie('n2','');
    if(n3!=undefined)
    {
         str+='&n3='+n3;
         setCookie('n3','');
    }
    window.location=str;
}
function ClearNoteCompare()
{
    if(document.getElementById('fixed').style.display=='block')
    {
        document.getElementById('fixed').style.display='none';
    }
    c1= getCookie('n1');
    c2= getCookie('n2');
    c3= getCookie('n3');
    c1=c1.split(',');
    c2=c2.split(',');
    c3=c3.split(',');
    if(c1[0]!='')
    {
       setCookie('n1','',5);
       if(document.getElementById('chp'+c1[0])!=undefined)
        document.getElementById('chp'+c1[0]).checked=false;
       if(document.getElementById('chi'+c1[0])!=undefined)
        document.getElementById('chi'+c1[0]).checked=false;    
    }
    if(c2[0]!='')
    {
       setCookie('n2','',5);
        if(document.getElementById('chp'+c2[0])!=undefined)
        document.getElementById('chp'+c2[0]).checked=false;
       if(document.getElementById('chi'+c2[0])!=undefined)
        document.getElementById('chi'+c2[0]).checked=false;    
    }
    if(c3[0]!='')
    {
       setCookie('n3','',5);
        if(document.getElementById('chp'+c3[0])!=undefined)
        document.getElementById('chp'+c3[0]).checked=false;
       if(document.getElementById('chi'+c3[0])!=undefined)
        document.getElementById('chi'+c3[0]).checked=false;    
    }
}
