function postalcheck(postal_code){
	o = 0;
	if (isNaN(postal_code)) {o++};
	if (postal_code.length!=4) {o++};

	if (o == 0) { return true; }
	else { return false; }
}

function emailcheck(email) {
	a = email.lastIndexOf("@");
	b = email.lastIndexOf(".");
	c = email.indexOf(":");
	d = email.indexOf("/");
	e = email.substring(0,a);
	f = e.indexOf("@");
	g = email.substring(a+1,email.length);
	h = g.indexOf("[");
	i = g.indexOf("]");
	j = g.indexOf("<");
	k = g.indexOf(">");
	l = email.substring(a+1,b);
	m = email.substring(b+1,email.length);
	n = email.substring(0,a);
	o = 0;
	if ((email == null) || (email == "")) {o++};
	if (a > b) {o++};
	if (c != -1) {o++};
	if (d != -1) {o++};
	if (f != -1) {o++};
	if (h != -1) {o++};
	if (i != -1) {o++};
	if (j != -1) {o++};
	if (k != -1) {o++};
	if (l.length < 2) {o++};
	if (m.length < 2) {o++};
	if (n.length < 1) {o++};
	
	if (o == 0) { return true; }
	else { return false; }
}

function cellcheck(cellnumber) {
	var c=0;
        a = cellnumber.substring(0,1);
        if (isNaN(cellnumber)) {c++};
        if (cellnumber.length < 10) {c++};
		if (a=="0") {c++};

        if (c == 0) { 
			return true; 
		} else { 
			return false;
		}
}

function url_check(url){
var url_domain="";
var url_folders="";
			
        // Check correct start
		if (url.indexOf("http://")==0){
			url_rest=url.substring(7,url.length);
		} else if(url.indexOf("https://")==0){
			url_rest=url.substring(8,url.length);
		} else {
			return false;
		}
		
		// Get everything before the first /
		if (url_rest.indexOf("/")!=-1) {
			url_domain=url_rest.substring(0,url_rest.indexOf("/"));
			url_folders=url_rest.substring(url_rest.indexOf("/")+1,url_rest.length);
		} else {
			url_domain=url_rest;
		}
		
		// Split the domain name at the .
		var url_domain_array = url_domain.split(".");

		// Loop through the domain name and test for invalid characters
		for (var loop=0; loop < url_domain_array.length; loop++)
		{
   			// Check that only alphanumerical and - is accepted			
			var illegalChars = /[^A-Za-z0-9.-]/;
	    	if (illegalChars.test(url_domain_array[loop])) {return false; }
			
			// if the domain starts or ends with a -
			if (url_domain_array[loop].indexOf("-")==0) { return false; }
			if (url_domain_array[loop].lastIndexOf("-")==url_domain_array[loop].length-1) { return false; }
		}

		// Check that there is no spaces in the file folder URL
		if (url_folders.indexOf(" ")!=-1) { return false; }
		
		// Check that there is no ? in the folder URL
		if (url_folders.indexOf("?")!=-1) { return false; }
		
		// check that there is no & in the folder URL
		if (url_folders.indexOf("&")!=-1) { return false; }
		
return true;
}

// Check if string has the right extention (Used with file upload)
function check_extension(load_url, file_types){

err=0;

for (var a=0; a<file_types.length; a++){
	if (file_types[a]==load_url.substring(load_url.length - file_types[a].length)){
		err++;
	}
}

if (err==0){
	return false;
} else {
	return true;
}
}
