﻿function CreateBookmarkLink(){
	title = document.title;
	url = window.location;
	if (window.sidebar) { 
	    window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {
	    window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { 
	    return true; }
}

function ValidateCategory(x1,x2){
    x2.IsValid = !(x2.Value=='0' || x2.Value==null || x2.Value=='');
}

function ShowImage2(id,src){

    if(document.getElementById(id)!=null)
        document.getElementById(id).src=src;
}

function ShowPanel(id){
    var obj=document.getElementById(id);
    if(obj!=null)
        obj.style.display=(obj.style.display == 'none' ? '' : 'none');
}


function ShowWindow(url){
    window.open(url,null);    
}

function OpenWindow(url,params){
    window.open(url,'',params);
}

function CheckFeedBack(id1,id2){    
   document.getElementById(id1).disabled=(document.getElementById(id2).value=="" ? 'true' : '');
}

 function ShowBigPhoto(id){
    window.open('Gift-Photo'+obj[(curr_item+id)%(obj.length)]+'.aspx',null);    
}

function SetMainPhoto(id){
        
    document.getElementById('main_image').src='Gift-Medium-Photo'+obj[(curr_item+id)%(obj.length)]+'.aspx';
    var h=319;
    h/=prop[(curr_item+id)%(obj.length)];
    
    document.getElementById('main_image').style.height=h;
    document.getElementById('img_div1').style.height=h;
    document.getElementById('img_div1').style.top=-h;    
    document.getElementById('img_div3').style.height=h;   
  
}

function NextPhoto(n){
         
    curr_item+=n;
    
    if(obj.length==2){
        if(curr_item>1)
            curr_item=1;
        else if(curr_item<0)
            curr_item=0;
    }
    else{
        if(curr_item<0)
            curr_item+=obj.length;
        curr_item%=obj.length;
    }
    
    SetMainPhoto(0);

    
    //SetMainPhoto(0);
    
    if(obj.length<3) return;
    var o=document.getElementById('img_1');
    if(o!=null)
        o.src='Gift-Small-Photo'+obj[(curr_item-1+obj.length)%obj.length]+'.aspx';
    
    o=document.getElementById('img_2');
    if(o!=null)
        o.src='Gift-Small-Photo'+obj[(curr_item+1)%obj.length]+'.aspx';
}   

var curr_item=0;

var curr_id;
function ShowImagePanel(id){    
    if(curr_id != null && curr_id!='')
        document.getElementById(curr_id).style.display='none';
       
    curr_id=id;
    if(curr_id != null && curr_id!='')
        document.getElementById(curr_id).style.display='';
}

function ShowImage(id) {
    document.getElementById('or'+id).src="PhotoO"+id+".aspx";
}



function textBoxChangeTextFocus(id,text){
    var obj=document.getElementById(id);
    if(obj.value==text)
        obj.value='';
}

function textBoxChangeTextBlur(id,text){
    var obj=document.getElementById(id);
    if(obj.value=='')
        obj.value = text;
}


function _ShowPanel(id){
    var obj=document.getElementById(id);
    if(obj)
        obj.style.display='';
}

function _HidePanel(id){
    var obj=document.getElementById(id);
    if(obj)
        obj.style.display='none';
}
function SortClick(path,addParam,field,type){
	if(path.indexOf('?')>0) path+='&';
	else path+='?';
	
	window.location=path+'sort'+addParam+'='+field+'&stype'+addParam +'='+type;
}

function OpenCategoryPanel(id,id2){
    var obj=document.getElementById(id);
    var obj2=document.getElementById(id2);
    if(obj){
        obj.style.display=(obj.style.display=='none'?'':'none');
        obj2.src=(obj.style.display=='none'?'images/catalog_li_l1.gif':'images/catalog_li_l1_cur.gif');
    }      
}

var prev=0;
var currID=0;
function ShowItemImage(id,imageID,itemID){
    //var link=document.getElementById('img_a_'+prev);
    //link.className="";
    //link=document.getElementById('img_a_'+id);
    //link.className="cur";
    ///prev=id;
    
    document.getElementById('main_image').src='photos/'+itemID+'/'+imageID+'-b.jpg';    
    document.getElementById('main_image_l1').href='photos/'+itemID+'/'+imageID+'-original.jpg';    
    document.getElementById('main_image_l2').href='photos/'+itemID+'/'+imageID+'-original.jpg';    
    //currID=imageID;
}
function OpenItemImage(def,itemID){
    if(currID==0)  currID=def;
    window.open('photos/'+itemID+'/'+currID+'-original.jpg');
}

function ShowHideItem(id1,id2){
    document.getElementById(id2).style.display=id1.checked?'':'none';
}


 function getBounds(element)
 { 
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
 } 


 function showPopup(element,id)
 {
 document.getElementById('popup_block_img').src='';
  document.getElementById('popup_block_img').src='photos/'+id+'/main.jpg';
  var bounds = getBounds(element); 
  document.getElementById('popup_block').style.top = bounds.top + 10 + 'px';
  document.getElementById('popup_block').style.left = bounds.left + 10 + 'px';
  document.getElementById('popup_block').style.display = 'block';    
 }
 
 function hiddenPopup(element)
 {
  document.getElementById('popup_block').style.display = 'none'; 
 }