
function sendMail() {
	var d = "rosalawrence";
	var a = ".com";
	var p = "mailto:";
	var n = "rosa";
	
	location.href = p + n + "@" + d + a;
}

function notEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return false;
    else
        return true;
}

function checkForm(f)
//elements named m_ .... are mandatory fields
{	
	var msg="";
	
	for(var i=0; i<f.elements.length; i++){
		var e = f.elements[i];
		if (e.name.substring(0,2)=='m_' && !e.disabled) {
			if (((e.type.substring(0,4)=='text'||e.type.substring(0,8)=='password') && e.value=='')||(e.type.substring(0,6)=='select' && e.selectedIndex==0)) {
				if (msg=="") {e.focus();}
				msg += "Please enter " + e.name.substring(2,999).replace(/_/g," ") + "\n";
			} 
		}
	}
	if (msg!="") {
		alert(msg);
		return false;
	}
	
	for(var i=0; i<f.elements.length; i++){
		var e = f.elements[i];
			if (e.name.substring(0,2)=='m_' && (e.name.indexOf('email') != -1) && notEmail(e.value)) {
			e.focus();
			alert("'"+e.value+"'"+' is not a valid e-mail address.');
			return false;
		}
	}

	if (f.Date_of_Course) {
		if (!date_is_valid(f.m_Date_of_Course_Day.value, f.m_Date_of_Course_Month.value, f.m_Date_of_Course_Year.value)) {
			alert("The date of Course entered is not a valid date, please correct");
			f.m_Date_of_Course_Day.focus();
			return false;
		}
		f.Date_of_Course.value = f.m_Date_of_Course_Year.value + '-' + f.m_Date_of_Course_Month.value + '-' + f.m_Date_of_Course_Day.value;
	}
	if(f.m_Confirm_Password) {
		if(f.m_Confirm_Password.value != f.m_Password.value) {
			alert("The passwords do not match please re-enter");
			f.m_Password.focus();
			return false;	
		}
	}
	if(f.rPlaces) {
		if(parseInt(f.m_Places.value) > parseInt(f.rPlaces.value)) {
			alert("We need to allcocate more places on this course for you.\nPlease call COGNITIS Training on +44 (0) 1565 750311\n\n");
			f.m_Places.focus();
			return false;	
		}
	}		
	// list of fields which if present in the form and filled in must be numbers > 0	
	return is_number(f.m_Fee) && is_number(f.m_Duration) && is_number(f.m_Places)
}


function date_is_valid(day, month, year) {
    var month_length = new Array( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
    if ( is_leap_year(year) )  month_length[2] = 29;
    if ( month < 1 || month > 12 ) return false;  
	if ( day < 1 || day > month_length[month] ) return false;
	return true;
}


function is_number(x) {
	if (x) {
		if(isNaN(x.value)|| x.value <0) {
			alert(x.name.substring(2,999).replace(/_/g," ") + " is not a valid number, please correct");
			x.focus();
			return false;
		}
	}
	return true;
}

    
function is_leap_year(year) {
    if ( (year%4) != 0 ) return false;          
    if ( (year%400) == 0 ) return true;            
    if ( (year%100) == 0 ) return false;                                 
    return true ;           
}

function confirmAction(url,msg) {
	if(confirm(msg)) location.href = url;
}

function checkTickBox (box,msg) {
	var e = document.getElementById(box);
	if(!e.checked) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function openPlainWindow (url,w,h) {	
	var X = 0;
	var Y = 0;
	if (screen.availWidth) {
		X = (screen.availWidth / 2) - (w / 2) - 5;
		Y = (screen.availHeight / 2) - (h / 2);
	} else {
		X = (800 / 2) - (w / 2) - 5;
		Y = (600 / 2) - (h / 2);
	}
	popupWindow = window.open(url, 'popUp', 'left=' + X + 
		'screenX=' + X + 'screenY=' + Y + ',top=' + Y + 
		',toolbar=no, scrollbars=no, resizable=no, directories=no, location=no, status=no' + 
		',height=' + h + ',width=' + w);
	popupWindow.focus();
}

function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu = function(){return false}