function checkStreetWithNum(name,mes,form){
 var el = form[name];
 //var valid = new RegExp("^[ a-zA-Z0-9]+[ ]+[0-9]{1,}[a-zA-Z]{0,}$").exec(el.value);
 var valid = new RegExp("^[a-zA-Z0-9\ ]+[ ]+[0-9]{1,}[a-zA-Z]{0,}").exec(el.value);
  if((!valid)){
   alert(mes);
   Fat.fade_element(name);
   el.focus();
   return false;
 }
 return true;
}
function checkZipcode(name,mes,form){
 var el = form[name];
 var valid = new RegExp("^[0-9]{4}[ ]{0,1}[a-zA-Z]{2}$").exec(el.value);
  if((!valid)){
   alert(mes);
   Fat.fade_element(name);
   el.focus();
   return false;
 }
 return true;
}
function checkPhone(name,form,force){
 var el = form[name];
 var valid = new RegExp("^([0-9]{3}[-]{0,1}[0-9]{7})|([0-9]{2}[-]{0,1}[0-9]{8})$").exec(el.value);
  if((!valid && el.value != '')||(!valid && force)){
   alert(translation.invalid_phone);
   Fat.fade_element(name);
   el.focus();
   return false;
 }
 return true;
}
function checkJSDate(form,name,force){
 var el = form[name];
 var valid = new RegExp("^^[0-3][0-9][-]([0][0-9]|[1][0-2])[-][0-9]{4}$").exec(el.value);
 if((!valid && el.value != '')||(!valid && force)){
   alert("Invalid date format. example: dd-mm-yyyy");
   Fat.fade_element(name);
   el.focus();
   return false;
 }else if(valid){
    day =parseInt(el.value.substr(0,2),10);
    month = parseInt(el.value.substr(3,2),10)-1;
    year = el.value.substr(6,4);
    dteDate=new Date(year,month,day);
    if(month != dteDate.getMonth() || day != dteDate.getDate() || year != dteDate.getFullYear()){
      alert("Entered None existing date" );
      Fat.fade_element(name);
      el.focus();
      return false;
    }
 }
 return true;
}
function checkRadio(name,mes,form){
  var el = form[name];
  var sel = false;
  for(var i=0;i<el.length;i++){
    if(el[i].checked){
      sel = el[i].checked;
    }
  }
  if(!sel){
    alert(translation.noselect_radio);
    el[0].focus();
  }
  return sel;
}
function checkSelect(form,name,title,invalid){
  var el = form[name];
  if(el[el.selectedIndex].value == invalid){
    alert(title+": invalid Selection.");
    Fat.fade_element(name);
    el.focus();
    return false;
  }
  return true;
}
function validateFloatCheck(el,pos){
 el.value = el.value.replace(/[a-zA-Z,]+/ig,'');
 var valid = new RegExp("^[0-9]+[.]{0,1}[0-9]{0,"+pos+"}$").exec(el.value);
 if(!valid || el.value == ''){
   return false;
 }
 return true;
}
function validateFloat(el,pos){
 el.value = el.value.replace(/[a-zA-Z,]+/ig,'');
 var valid = new RegExp("^[0-9]+[.]{0,1}[0-9]{0,"+pos+"}$").exec(el.value);
 if(!valid && el.value != ''){
   el.value = el.value.substr(0,el.value.length-1);
 }
calcSubjects();
}
function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
}
function isInt(val){
  value =  new RegExp("^[0-9]{1,}$").exec(val);
  return value;
}
function isFloat(val){
  value =  new RegExp("^[0-9]+[.]{0,1}[0-9]{0,4}$").exec(val);
  return value;
}

function genPopOver(holder){
  if(!$(holder)){
    var text = '<div id=\"'+holder+'\" class=\"popover_container\" style=\"display:none;\"><div class=\"ajax_loader\"><img class=\"ajax_loader\" src=\"\/loader.gif\" alt=\"loading\" \/><\/div><\/div>'; //style=\"display:none;\"
    $('body').insert({Bottom:text});
    showPopOver(holder);
  }
  genPopOverBack();
}
function genPopOverBack(){
  ssize = getSize();
  var divs = $('body').select('div.popover_container');
  var back = '<div id=\"popover_back\" style=\"width:'+ssize[2]+'px;height:'+ssize[3]+'px;\"></div>';
  removePopOverBack();
  if(divs.length > 0){
    divs[0].insert({Before:back});
  }else{
    $('body').insert({Bottom:back});
  }
  resizePopOverBack();
}
function resizePopOverBack(){
 ssize = getSize();
 if($('popover_back')){
  $('popover_back').style.width = ssize[2]+'px';
  $('popover_back').style.height = ssize[3]+'px';
 }
}
function removePopOverBack(){
  if($('popover_back')){
    $('popover_back').remove();
  }
}
function clearPopOvers(){
  var divs = $('body').select('div.popover_container');
  for(var i=0;i<divs.length;i++){
   divs[i].remove();
  }
  removePopOverBack();
}
function closePopOver(holder){
 new Effect.Fade(holder,{duration:0.5,afterFinish:function(){$(holder).remove();removePopOverBack();}});
}
function showPopOver(holder){
 var ssize = getSize(); //Array(myWidth,myHeight,maxW,maxH,mode);
 $(holder).style.display = '';
 var height = $(holder).offsetHeight;
 var width = $(holder).offsetWidth;
 $(holder).style.display = 'none';
 var left = parseInt((ssize[0]-width)/2);
 $(holder).style.left = left+'px';
 var scrolltop = f_scrollTop();
 var top = parseInt(scrolltop)+parseInt(parseInt(ssize[1]-height)/2);
 $(holder).style.top = top+'px'; 
 $(holder).style.display ='';
 new Effect.Appear(holder,{duration:0.5});
}
var defaultheight = 300;
function resizePopOverHeight(id){
  el = $(id);
  var diffspace = 22;
  if(el.scrollHeight <= defaultheight){
    return '';
  }
  else if((el.scrollHeight-diffspace) < el.getHeight()){
    //el.style.height = el.scrollHeight+"px";
    new Effect.Morph(el,{style:'height:'+defaultheight+'px',afterFinish:function(){resizePopOverBack();}});
  }else{
    //el.style.height = el.scrollHeight+"px";
    defaultheight = el.getHeight()-diffspace;
    new Effect.Morph(el,{style:'height:'+(el.scrollHeight-(diffspace-4))+'px',afterFinish:function(){resizePopOverBack();}});
  } 
}
function renderSubCat(holder,id,n){

}
function shoppingCartPrev(form){
 form['step'].value = parseInt(form['step'].value)-1;
 form.action = '/shoppingcart';
 form.submit();
}
function shoppingCartNext(form){
 form['step'].value = parseInt(form['step'].value)+1;
 form.action = '/shoppingcart';
 form.submit();
}
/**
Author: Daniel
version:1.2 - 2010-05-28
Requirements:
- Prototype

Example implementation:
<input type="text" class="text date_input"  id="prod_date" name="prod_date" value=""/>
<img class="click vimg" onclick="cal1=new jsCal('jscalendar','cal1','prod_date');return false;" src="today.gif" alt="cal"/>
<img class="click vimg" onclick="if(window.cal1){cal1.closeCal();}$('prod_date').value='';" src="today_clear.gif" alt="clear"/>
<div class="clear"></div>
<div id="jscalendar" class="jscalendar_holder" style="display:none;"></div>
**/

var jsCal = Class.create();
jsCal.prototype  = {
	initialize: function (holder,uid,output){
		this.options = {
      	holder: holder,
      	uid: uid,
      	output: output,
        monthname:["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
        weekday:["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"],
        sel_date:new Date()
    	}
    	this.showSelDay();
	},
   Lz: function(x) { //Clean date 1 to 9 => 01...09
 			return (x < 0 || x >= 10 ? "" : "0") + x;
	},
	showToDay: function(){
		var cdate = new Date();
		this.showCal(cdate.getFullYear()+"-"+cdate.getMonth());
		var id = this.options.holder;
		if($(id).style.display=='none'){
			$(id).style.display='';
		}else{
			$(id).style.display='none';
		}
	},
  showSelDay: function(){
    var cval = $(this.options.output).value;
    var d = new Date();
    if(cval != ''){
      sval = cval.split("-");
      d.setDate(sval[0]);
      d.setMonth(sval[1]-1);
      d.setFullYear(sval[2]);
    }
    this.options.sel_date = d;
    this.showCal(d.getFullYear()+"-"+d.getMonth());
		var id = this.options.holder;
		if($(id).style.display=='none'){
			$(id).style.display='';
		}else{
			$(id).style.display='none';
    }
  },
	showCal: function(YrMo) {
		this.preshowCal();
		var MN, WD, LD, St, Dy, D = new Date(),pD=new Date(),nD=new Date(),wD=new Date();
		var T = YrMo.split(/\D+/), Yr = + T[0], Mo = + T[1];
		//Yr = D.getFullYear(),Mo=D.getMonth();
		MN = Mo < 0 || Mo > 11 ? Mo : this.options.monthname[Mo];
		today = D;
		pD.setFullYear(Yr, Mo, 0);
		D.setFullYear(Yr, Mo+1, 0);
		wD.setFullYear(Yr, Mo, 1);
		nD.setFullYear(Yr, Mo+1, 1);
		obj =this.options.uid; 
		St = "<div class=\"jsoptions\"><a class=\"jsclose\" href=\"#\" onclick=\""+obj+".closeCal();return false;\">X</a></div>"+
		"<table class=\"jscalendar\" cellpadding=\"0\" cellspacing=\"0\">"+
		"<tr class=\"yearholder\">"+
		"<td colspan=\"2\"><a class=\"nav navleft\" href=\"#\" onclick=\""+obj+".showCal('"+(D.getFullYear()-1)+"-"+D.getMonth()+"');return false;\"><<\/a><\/td>"+
		"<td colspan=\"3\" style=\"text-align:center;\">" + Yr + "<\/td>"+
		"<td colspan=\"2\"><a class=\"nav navright\" href=\"#\" onclick=\""+obj+".showCal('"+(D.getFullYear()+1)+"-"+D.getMonth()+"');return false;\" >><\/a><\/td>"+
		"<\/tr>"+
		"<tr class=\"monthholder\">"+
		"<td colspan=\"2\"><a class=\"nav navleft\" href=\"#\" onclick=\""+obj+".showCal('"+pD.getFullYear()+"-"+pD.getMonth()+"');return false;\"><<<\/a><\/td>"+
		"<td colspan=\"3\" class=\"monthheader\" style=\"text-align:center;\">"+  MN + "<\/td>"+
		"<td colspan=\"2\"><a class=\"nav navright\" href=\"#\" onclick=\""+obj+".showCal('"+nD.getFullYear()+"-"+nD.getMonth()+"');return false;\" >>><\/a><\/td><\/tr>"+
		"<tr class=\"dayholder\">"+
		"<td class=\"day weekend\">"+this.options.weekday[0]+"<\/td><td class=\"day\">"+this.options.weekday[1]+
    "<\/td><td class=\"day\">"+this.options.weekday[2]+"<\/td><td class=\"day\">"+this.options.weekday[3]+
    "<\/td><td class=\"day\">"+this.options.weekday[4]+"<\/td><td class=\"day\">"+this.options.weekday[5]+
    "<\/td><td class=\"day weekend\">"+this.options.weekday[6]+"<\/td><\/tr><tr>";
		WD = wD.getDay();
		eWD = D.getDay()+1;
		LD = D.getDate();
		Mo = D.getMonth()
		PLD =pD.getDate();
		//alert(LD+"\n"+PLD+"\n"+WD+"\n"+pD+"\n"+wD+"\n"+D+"\n"+nD);
		PLD=PLD-(WD-1);
		for (Dy = 0; Dy < WD; ++Dy) {
			pD.setDate(PLD+Dy);		       	
			St += "<td><a class=\"prevmonth\" href=\"#\" onClick=\""+obj+".updateCal('"+pD+"');return false;\">"+pD.getDate()+"<\/a><\/td>";
		}
		today = new Date();
		today = today.getFullYear().toString()+today.getMonth().toString()+today.getDate().toString();
		for (Dy = 1; Dy <= LD; Dy++) {
			D.setFullYear(Yr,Mo,Dy);
			St += "<td><a class=\"curmonth";
			if ((""+D.getFullYear()+D.getMonth()+D.getDate()) == today ){	St += ' today'; }	
      if ( D.getFullYear() == this.options.sel_date.getFullYear() && D.getMonth() == this.options.sel_date.getMonth() && D.getDate() == this.options.sel_date.getDate()){St += ' cur_date_selected';}
			St += "\" href=\"#\" onClick=\""+obj+".updateCal('"+D+"');return false;\">"+this.Lz(Dy)+"<\/a><\/td>";
			if (++WD % 7 == 0) { St += "<\/tr><tr>"; }
 		}
		D.setFullYear(Yr, Mo+2, 0);
		Yr = nD.getFullYear(),Mo = nD.getMonth(),eind = 7-eWD;
 		for (Dy = 0; Dy < eind; Dy++) {
			nD.setFullYear(Yr,Mo,Dy+1);
			St += "<td><a class=\"nextmonth\" href=\"#\" onClick=\""+obj+".updateCal('"+nD+"');return false;\">"+this.Lz(Dy+1)+"<\/a><\/td>";
	  }
 		$(this.options.holder).innerHTML=St+"<\/tr><\/table>";
		this.postshowCal();
	},
	updateCal: function(val){
		this.preupdateCal(val);
	 	D = new Date(val);
	 	this.postupdateCal(val);
	 	retval=this.Lz(D.getDate())+"-"+this.Lz(D.getMonth()+1)+"-"+D.getFullYear();
		return $(this.options.output).value=retval;
	},
	preupdateCal: function(val){	},
	postupdateCal: function(val){
		var id = this.options.holder;
		if($(id).style.display==''){ $(id).style.display='none'; }else{ $(id).style.display=''; }
	},
	preshowCal: function(){	},
	postshowCal: function(){	},
	closeCal: function(){
		var id = this.options.holder;
		$(id).style.display='none';
		return false;
	}
};
function showProdPreview(target,src,index){
 $(target).src = src;
 return false;
}
function checkCart(form){
 if(form.amount.value == ''){
   alert(translation.empty_amount);
   return false;
  }
return true;
}
function showProdHSPreview(el){
var splits =  el.src.split("/");
var index = splits[splits.length-2];
obj = document.getElementById('prod_thumb_holder_'+index);
hs.expand(obj,galleryOptions);
}


