function photopage(classname, id, imgfrom, imgto, imgcur) {    

    var url = '../ajax/images.php';
    var pars = 'classname='+classname+'&id='+id+'&imgfrom='+imgfrom+'&imgto='+imgto+'&imgcur='+imgcur;
    
	var myAjax = new Ajax.Request(
        url, 
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimages(r)}});
       
    return false;
}

function restoreimages (r) {
    var ret=r.responseText;
    var imagesnav=$("imagesnav");
    imagesnav.innerHTML=ret;
}

function photoset (classname, id, imgcur) {    
    
    var url = '../ajax/imageplace.php';
    var pars = 'classname='+classname+'&id='+id+'&imgcur='+imgcur;
    
	var myAjax = new Ajax.Request(
        url, 
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimageplace(r)}});
       
    return false;    
}

function restoreimageplace(r) {    
    var ret=r.responseText;
    var imagesnav=$("imageplace");
    imagesnav.innerHTML=ret;
}

function reportError(request) {
    alert('Sorry. There was an error.');
}

function myshow(field, id) {
    
    var reshow=1;
    if (show_desc) {
        if (show_desc==id) var reshow=0;
    }
    
    if (reshow) {
    	var posy=getPosition(field)[1];
    	var posx=getPosition(field)[0];    	
    	var div=$(id);    	    	    	
    	div.style.position="absolute";
    	div.style.top=eval(posy-120)+"px";
    	div.style.left=eval(posx-210)+"px";    
    	div.style.display="block";  
    	var h=div.getHeight();  	
    	var w=div.getHeight();  	
    	div.style.top=eval(posy-h+10)+"px";
    	show_desc=id;
    }
}

function myhide(id) {
    var div=$(id);
    div.style.display="none";
    show_desc=0;
}

function getPosition(obj) {
    var o=obj; 
    var x=0, y=0; 
    while(o) { 
        x+=o.offsetLeft; 
        y+=o.offsetTop; 
        o=o.offsetParent; 
    } 
    return [x,y]; 
}

function checkcartform(form) {    
    var error="";
    var ch=0;
    for (var i=0; i<form.elements.length; i++) {
        var el=form.elements[i];
        if (el.type=="select-one") {
            if (el.selectedIndex==0) {                
                var t=$(el.name+"_name");
                error+="Please choose a "+t.innerHTML+"!\n";
            }
        }
    }
    
    if (isNaN(parseInt(form.qty.value)) || parseInt(form.qty.value)==0) error+="Incorrect Quantity!\n";                 
        
    if (error!="")  {
        alert ("Error: "+error);
        return false;
    }
    else return true;
}

function checkcartmodifyform(form) {    
    var error="";
    var ch=0;
    for (var i=0; i<form.elements.length; i++) {
        var el=form.elements[i];
        if (el.name.search("qty")!=-1) {
            if (isNaN(parseInt(el.value))) error+=el.value+" Incorrect Quantity!\n";                 
        }
    }
            
    if (error!="")  {
        alert ("Error: "+error);
        return false;
    }
    else return true;
}

function checkcheckform(form) {    
    var error="";
    var ch=0;
    for (var i=0; i<form.elements.length; i++) {
        var el=form.elements[i];
        if (el.name.search("address2")==-1 && el.name.search("promocode")==-1 && el.name.search("company")==-1 && el.name.search("s_company")==-1) {
            if (el.value=="") error+=el.name+" should not be empty!\n";                 
        }
    }
    if (checkEmail(form.email.value)==false) error+="Incorrect Email!\n";                         
    
    if (error!="")  {
        //alert ("Error: "+error);
        alert ("Error: all of the fields marked with an \"*\" are required. Please review the form and enter the missing information.");
        return false;
    }
    else return true;
}

var win;
function big_photo(f,w,h) {
    if (win) {
        win.close();        
    }
    
    win=window.open('../photo.php?f='+f, null, "width="+w+",height="+h+",toolbar=0,scrollbars=no,resizable=no");    
    return false;
}  

function makesubmit(form) {
    form.submit();    
}

function reprice(form, subset) {
    var pice_place=$("current_price");    
    var index=subset.selectedIndex;    
    var id=subset[index].value;    
    if (id>0) {
        var price=$("subset_"+id);        
        pice_place.innerHTML=price.value;
    }
}

function copy_info (form, chck) {    
    if (chck.checked==true) {        
        for (var i=0; i<form.elements.length; i++) {
            var el=form.elements[i];
            var shname='s_'+el.name;
            var shelem=document.getElementsByName(shname);
            if (shelem[0]) {
                shelem[0].value=el.value;
            }
        }
    }
}

function doselectship(form, ship) {
    var pice_place=$("ship_price_only");    
    var index=ship.selectedIndex;
    var id=ship[index].value;       
    if (id>0) {
        var price=$("shipprice_"+id);
        if (price) {
            var t=price.value;
            pice_place.innerHTML=format_number_ex(t, 2, '.');
        }
        else pice_place.innerHTML="0";
    }
    else pice_place.innerHTML="0";
}

function format_number_ex(n, c, d, t) {
  c = Math.abs(c) + 1 ? c : 2;
  d = d || ",";
  t = t || "";
  var m = /^(\d+)(\.\d+)?$/.exec(n + "");
  if (!m) {
    return n;
  }
  var s;
  var x = m[1].length % 3;
  if (x) {
    s = m[1].substr(0, x);
    if (m[1].length > 3) {
      s += t;
    }
  }
  else {
    s = "";
  }
  s += m[1].substr(x).replace(/(\d{3})(?=\d)/g, "$1" + t);
  if (c) {
    s += d;
    if (m.length > 2 && typeof(m[2]) == "string" && m[2].length > 0) {
      s += parseFloat(m[2]).toFixed(c).substr(2);
    }
    else {
      for (var i = 0; i < c; ++i) {
        s += '0';
      }
    }
  }
  return s;
}

function dochargeship() {
    var ship_price_only=$("ship_price_only");    
    var ship_price=$("ship_price");  
    var subtotal=$("subtotal");  
    var total_pay=$("total_pay");  
    
    var s1=subtotal.innerHTML;
    var s2=ship_price_only.innerHTML;
    
    var tmp=eval(s1)+eval(s2);
    tmp=format_number_ex(tmp, 2, '.');
    
    ship_price.innerHTML=tmp;
    total_pay.innerHTML=tmp;
}


function changebg(el, bg) {
	var e=$(el);	
	if (e) {		
		e.style.backgroundImage="url(/photos/document/big/"+bg+")";
	}
}

function changesrc(t,n) {    
    t.src="/img/"+n;
}