// FILENAME: 	UIFunctions.js
// PURPOSE:		User interface functions
// AUTHOR:		Kal Sabir (Orion Blue)
// CREATED:		October 2006


// Pop-up function

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// GENERAL FORM VALIDATION

function validateGeneralForm(nameID, emailID, messageID) {
	if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
	if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
	if (textvalidation(messageID, 'Please enter a message.') == false ) {return false;}
}




// ENQUIRY FORM VALIDATION HELPER FUNCTIONS 


function selectvalidation(elementID, alertbox) {
		if (document.getElementById(elementID).value=="null"){
			if (alertbox) {alert(alertbox);} 
			return false;
		} else {
			return true;
		}
}


function datevalidation(dayID, monthID, yearID, curD, curM, curY, alertbox) {
	
	if (document.getElementById(yearID).value == curY) {
			if (document.getElementById(monthID).value < curM) {
				if (alertbox) {alert(alertbox);}
				return false;
			}
			if ((document.getElementById(monthID).value == curM) && (document.getElementById(dayID).value <= curD)) {
				if (alertbox) {alert(alertbox);}
				return false;
			}
	}
}

function textvalidation(elementID, alertbox) {
		if (document.getElementById(elementID).value==""){
			if (alertbox) {alert(alertbox);} 
			return false;
		} else {
			return true;
		}
}
			
	
function emailvalidation(elementID, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.

	value = document.getElementById(elementID).value;
	if (value==""){
		if (alertbox) {alert(alertbox);} 
		return false;
	}
	
	with (value) {
		apos=value.indexOf("@"); 
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
			{if (alertbox) {alert(alertbox);} return false;}
		else {return true;}
	}
}

function valuevalidation(elementID, min, max, datatype, alertbox)
{
// Value Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.

value = document.getElementById(elementID).value;
with (value)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

