function template_printpage(page_id, popup_width) {
	var intWidth = parseInt(popup_width);
	var intHeight = 600;
	var intLeft = (screen.availWidth - intWidth - 10) / 2;
	var intTop  = (screen.availHeight - intHeight - 29) / 2;
	objWin = window.open("/includes/pages/module_print.asp?page_id=" + page_id, 'ViewPopup', 'left=' + intLeft + ',top=' + intTop + ',width=' + intWidth + ',height=' + intHeight + ',menubar=no,toolbar=no,location=no,status=yes,scrollbars=no,resizable=no');
}

function lightbox_maxwidth() {
	return document.documentElement.clientWidth;
}
function lightbox_maxheight() {
	return document.documentElement.clientHeight;
}
function lightbox_pictures()
{
	var elm_container = document.getElementById("t04_template_contentarea");
	if(elm_container) {
		var arr_elements = elm_container.getElementsByTagName("a");
		for(var i=0; i<arr_elements.length; i++){
			current_elm = arr_elements[i];
			current_rel = current_elm.getAttribute("rel");
			if(current_rel != null) {
				if(current_rel.indexOf("lightbox") == 0) {
					var this_id = current_elm.getAttribute("id");
					var this_img = "/files/gallery/" + this_id + "/" + (lightbox_maxwidth()-200) + "/" + (lightbox_maxheight()-200) + "/"
					this_img = this_img.replace("img_","")
					document.getElementById(this_id).href = this_img;					
				}
			}
		}
	}
}
function critical_message() {
	var msg = document.getElementById("critical_warning");
	if(msg) {
		$(msg).fadeOut(1000).fadeIn(1000)
		$(msg).animate({top: "50px"}, 1000);
		$(msg).animate({top: "0px"}, 750);
	}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function IsNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
}

function validateFrontendForm(e) {
	
	mai = /^[0-9a-zA-Z\.\_\-]+\@[0-9a-zA-Z\.\_\-]{1,}\.[a-zA-Z]{2,4}$/;
	phone = /([0-9]){8}$/gi;
	zip = /([0-9]){4}$/gi;
	var err = 0;
	var txt = "";
	
	// validate name
	if(e.fullname.value.length == 0) {
		e.fullname.style.border = "1px solid red";
		err++;
	} else {
		e.fullname.style.border = "1px solid #999";
	}
	// validate address
	if(e.address.value.length == 0) {
		e.address.style.border = "1px solid red";
		err++;
	} else {
		e.address.style.border = "1px solid #999";
	}
	// validate zip no
	if(zip.test(e.zipno.value) == false) {
		e.zipno.style.border = "1px solid red";
		err++;
	} else {
		e.zipno.style.border = "1px solid #999";
	}
	// validate city
	if(e.city.value.length == 0) {
		e.city.style.border = "1px solid red";
		err++;
	} else {
		e.city.style.border = "1px solid #999";
	}
	// validate city
	if(mai.test(e.email.value) == false) {
		e.email.style.border = "1px solid red";
		err++;
	} else {
		e.email.style.border = "1px solid #999";
	}
	// validate phone
	if(phone.test(e.phone.value) == false) {
		e.phone.style.border = "1px solid red";
		err++;
	} else {
		e.phone.style.border = "1px solid #999";
	}
	
	// update hidden security
	if(err == 0) {
		e.send.value = "true";
		e.submit();
	} else {
		e.send.value = "false";
	}
}
