﻿function addOnload(newFunction) {
	var oldOnload = window.onload;
	
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	} 
}

addOnload(checkRequired);
addOnload(addImageRefresh);

function checkRequired() {
	document.contact.onsubmit = checkBlanks;
}

function checkBlanks() {
	allInputs = document.getElementsByTagName("*");
	for (i=0; i<allInputs.length; i++) {
	if (allInputs[i].className)
		if (allInputs[i].className.indexOf("req")>-1)
			if (allInputs[i].value == "") {
				alert("'"+allInputs[i].name+"' is required field. Please fill the form");
				allInputs[i].focus();
				return false;
				}
	}
	return true;
}

function addImageRefresh() {
	buttonRefresh = document.getElementById("refresh");
	buttonRefresh.style.cursor = "pointer";
	buttonRefresh.onclick = refreshImage;
}

function refreshImage() {
	imageNewLocation = document.numbers.src.substring(0,document.numbers.src.indexOf("php")+3);
	//alert(imageNewLocation);
	document.numbers.src = imageNewLocation + "?id=" + (new Date()).getTime();
	//alert(document.numbers.src);
}