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-20)+"px";
    	div.style.left=eval(posx-20)+"px";    
    	div.style.display="block";
    	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]; 
}

var win;
function big_photo(f,w,h) {
    if (win) {
        win.close();        
    }
    w=w+50;
    h=h+50;
    win=window.open('../photo.php?f='+f, null, "width="+w+",height="+h+",toolbar=0,scrollbars=no,resizable=no");    
    return false;
}  

function viewImg(image_href){
      var xstr = 'scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,location=no,resizable=yes,width=160,height=160';
      var prodWindow = window.open(image_href, 'window'+Math.round(Math.random()*1000), xstr);
      if (prodWindow) prodWindow.focus();
}

function backToSite(){
	var prodWindow = window.opener;
	if (prodWindow){
		prodWindow.focus();
		window.close();
	}
}

function housePrew(url, dir_image, image_name){
    var house_prev = document.getElementById('house');
    house_prev.innerHTML = '<a href="/view_img.php?dir_image='+dir_image+'&amp;image_name='+image_name+'" target="_blank" onclick="viewImg(this.href); return false;"><img src="'+url+dir_image+'/medium/'+image_name+'" alt="" /></a>';
}



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 number_format(number, decimals, dec_point, thousands_sep){
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
 var i, z;
  if(eindex > -1){
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if(decimals != null){
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
  if(decimals != null && decimals > 0){
    for(i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if(thousands_sep != null && thousands_sep != ""){
  for (i = integer.length - 3; i > 0; i -= 3)
   integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  return sign + integer + fractional + exponent;
}


function getShippingMethod(method){  
	var pars="id="+method;
    var url = '../ajax/get_shipping_tax.php';
	var myAjax = new Ajax.Request(
       url, 
        {method: 'get', parameters: pars, onFailure: function(r){alert("Error:"+r.responseText)}, onException:function(r,err){alert("Exception:"+r.responseText+err)}, onSuccess: function(r){setShippingTax(r)}});         
}

function setShippingTax(r){  
    if (r.responseText) {
        var tax = r.responseText;               
		$('shipping_tax').update(tax);
		
		subt = $('subtotal').innerHTML;
		subt = parseFloat(subt);
		tax = parseFloat(tax);
		res = subt + tax;
		res = number_format(res, 2, '.', '');
		$('total_charge').update(res);
    };
}


function validate_email(email)
{ var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]", 'i');
  if (!reg.test(email)) return false;
  return true;
}

function trim(str)
{ var start_pos=0;
  var end_pos=str.length;
  
  for(start_pos=0;start_pos<end_pos;start_pos++)
    if(str.charAt(start_pos)!=' ') break;
 
 
  for(end_pos=end_pos-1;end_pos>0;end_pos--)
    if(str.charAt(end_pos)!=' ') break;
  
  if((start_pos==str.length)&&(end_pos==0)) return "";
  
  return str.substring(start_pos, end_pos+1);
}   

   
function validate_form(form)
{ var mess="";
  if(!trim(form.name.value)) mess+="The Name is empty.\n";
  if(!validate_email(trim(form.your_email.value))) mess+="Your E-Mail is not valid.\n";
  if(!validate_email(trim(form.email.value))) mess+="The Friend E-Mail is not valid.\n";
  if(!trim(form.comments.value)) mess+="The Inquiry is empty.\n";
  if(mess=='') return true;
  alert(mess);
  return false;
}