
function SelectPhoneForCompare(id,img){
    var xhr = new createXHR();
    xhr.open('GET', './AjaxServer.aspx?action=AddPhoneToCompare&id=' + id + '&img='+img, true);
    xhr.onreadystatechange = function (){
        if (xhr.readyState == 4 && xhr.status == 200){
            if (xhr.responseText=="") return;
                eval(xhr.responseText);
            }
        };
    xhr.setRequestHeader('If-Modified-Since', 'Thu, 1 Jan 1970 00:00:00 GMT');
    xhr.setRequestHeader('Cache-Control', 'no-cache');
    xhr.send(null);
}


function ComparingPhones(phone1,file1,phone2,file2,phone3,file3){

    var img = document.getElementById("comparedImg1");
    img.style.visibility='hidden';
    try{
        if( file1 ){
            img.setAttribute("src",file1);
            img.style.visibility='visible';
        }
        CheckIfShown(phone1);
    }catch(e){}
    
    try{
        img = document.getElementById("comparedImg2");
        img.style.visibility='hidden';
        
        if( file2 ){    
            img.setAttribute("src",file2);
            img.style.visibility='visible';
        }
        CheckIfShown(phone2);
    }catch(e){
        img.style.visibility='hidden';
    }
    
    try{
      img = document.getElementById("comparedImg3");
      img.style.visibility='hidden';
      
      if( file3 ){  
        img.setAttribute("src",file3);
        img.style.visibility='visible';
      }
      CheckIfShown(phone3);
    }catch(e){
        img.style.visibility='hidden';
    }
    
}

function CheckIfShown(phoneId){
    var chk = document.getElementById('phone_'+phoneId+'_chk');
    if( chk == null ) return;
    chk.checked = true;
}

function ClearIconsList(boxId){
    var iconsBox = document.getElementById(boxId+"_icons");
    iconsBox.innerHTML = '';
}

function ShowIcon(boxId,iconId){
    var iconsBox = document.getElementById(boxId+"_icons");
    var icon = document.createElement("img");
    icon.setAttribute("width","18"); icon.setAttribute("height","18"); icon.setAttribute("hspace","2");
    icon.setAttribute("src","MvnoFile.aspx?file="+iconId);
    iconsBox.appendChild(icon);
}

function RemovePhoneFromCompare( phoneId ){
    var xhr = new createXHR();
    xhr.open('GET', './AjaxServer.aspx?action=RemovePhoneFromCompare&id=' + phoneId, true);
    xhr.onreadystatechange = function (){
        if (xhr.readyState == 4 && xhr.status == 200){
            if (xhr.responseText=="") return;
                eval(xhr.responseText);
            }
        };
    xhr.setRequestHeader('If-Modified-Since', 'Thu, 1 Jan 1970 00:00:00 GMT');
    xhr.setRequestHeader('Cache-Control', 'no-cache');
    xhr.send(null);
}

function PhoneCheckBoxClicked( chkId, phoneId, imgId ){

    var chk = document.getElementById(chkId);
    if( chk == null ) return;
    
    if( chk.checked == true )
        SelectPhoneForCompare(phoneId,imgId);
    else{
        RemovePhoneFromCompare(phoneId);
    }
}


function SelectLinkClicked( chkId, phoneId, imgId ){
    var chk = document.getElementById(chkId);
    if( chk == null ) return;
    
    chk.checked = !chk.checked;
    
    if( chk.checked == true )
        SelectPhoneForCompare(phoneId,imgId);
    else{
        RemovePhoneFromCompare(phoneId);
    }
}
