/* NULL */
function valid_entry(str,error)
{	if(str.length <= 0)
	{	if(error)
		{	alert(error);
		}
		else
		{	alert('null');
		}
		return false;
	}
	return true;
}

/* VALID MATCH */
function valid_match(str_1,str_2,error)
{	if(str_1 != str_2)
	{	if(error)
		{	alert(error);
		}
		return false;
	}
	return true;
}

/* VALID DATE */
function valid_date(date_dd,date_mm,date_yyyy,error)
{	var obj_date=new Date(''+(date_mm)+'-'+date_dd+'-'+date_yyyy+'');
	if(date_dd!=obj_date.getDate())
	{	if(error)
		{	alert(error);
		}
		return false;
	}
	if((date_mm-1)!=obj_date.getMonth())
	{	if(error)
		{	alert(error);
		}
		return false;
	}
	if(date_yyyy!=obj_date.getFullYear())
	{	if(error)
		{	alert(error);
		}
		return false;
	}
	return true;
} 

/* EMAIL */
function valid_email(str,error)
{	if(str.length > 0)
	{	var regex = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/;
		if(!regex.test(str))
		{	if(error)
			{	alert(error);
			}
			else
			{	alert('invalid email');
			}
			return false;
		}
	}
	return true;
}

/* VALID FILE URI */
function valid_file_uri(str,error)
{	if(str.length > 0)
	{	var regex= /^([A-Z]:\\[^/:\*\?<>\|]+\.\w{2,6})|(\\{2}[^/:\*\?<>\|]+\.\w{2,6})$/;
		if(!regex.test(str))
		{	if(error)
			{	alert(error);
			}
			else
			{	alert('invalid file path');
			}
			return false;
		}
		return true;
	}
}

/* MALICIOUS CHARACTERS */
function valid_bad(str,error)
{	var regex = /^([1-zA-Z0-1@.\s]{1,255})/;
	if(!regex.test(str))
	{	if(error)
		{	alert(error);
		}
		return false;
	}
	return true;
}

/* PRINT WINDOW */

function print_window()
{	bV = parseInt(navigator.appVersion);
	if (bV >= 4)
	{	window.print();
	}
	else
	{	alert("Sorry, this feature is only available in Internet browsers versions 4 or higher. Please download the latest version of your Internet browser.");
	}
}

/* BOOKMARK */

function bookmark_window()
{	bV = parseInt(navigator.appVersion);
	if (bV >= 4)
	{	window.external.AddFavorite('http://www.pltp.co.uk','PLTP, Preston Learning Together Partnership');
	}
	else
	{	alert("Sorry, this feature is only available in Internet browsers versions 4 or higher. Please download the latest version of your Internet browser.");
	}
}

/* NEW WINDOW */

function new_window(file,width,height)
{	file_window = window.open(file, 'file_window', 'width='+width+', height='+height+', scrollbars=no');
	file_window.focus();
}

/* LAUNCH */

function launch(url)
{	launch_window = window.open(url, 'launch_window', 'width=660, height=480, scrollbars=yes');
	launch_window.focus();
}

/* CONFIRM DELETE */

function confirm_delete(url)
{	var valid_confirm=confirm("Are you sure you want to delete?");
	if(valid_confirm)
	{	location.href=url;
	}
}

/* VALID APPLY */

function valid_apply()
{	if(!valid_entry(apply.id.value,'System error, please try again later'))
	{	return false;
	}
	if(!valid_entry(apply.name.value,'Please enter your name'))
	{	return false;
	}
	if(!valid_entry(apply.telephone.value,'Please enter your contact telephone number'))
	{	return false;
	}
	return true;
}