// 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;}
}

// WEDDING ENQUIRY FORM VALIDATION

function validateWeddingForm(nameID, emailID, dateDayID, dateMonthID, dateYearID, curD, curM, curY, 
							 venueID, artistsID, timesID, waltzID, guestsID) {
	
		if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
		if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
		if (datevalidation(dateDayID, dateMonthID, dateYearID, curD, curM, curY, 
						   'The date specified is invalid. Please enter a date starting from tomorrow.') == false ) {
			return false;}
		if (textvalidation(venueID, 'Please specify your Wedding Venue.') == false ) {return false;}
		if (selectvalidation(artistsID, 'Please select a band or solo artist from the drop down menu.') == false) {
			return false;}
		if (textvalidation(timesID, 
						   'Please enter booking times for the date specified. For example, from 3pm to 5pm.') == false) {
			return false;}
		if (textvalidation(waltzID, 'Please specify First Waltz.') == false ) {return false;}
		if (valuevalidation(guestsID, 1, 10000, 'i', 'Please specify the approximate number of guests.') == false ) {return false;}
		
}


// POP STAR PARY ENQUIRY FORM VALIDATION

function validatePopForm(nameID, emailID, dateDayID, dateMonthID, dateYearID, curD, curM, curY, recID, bdayID, invitesID) {
	
	if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
	if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
	if (datevalidation(dateDayID, dateMonthID, dateYearID, curD, curM, curY, 
					   'The date specified is invalid. Please enter a date starting from tomorrow.') == false ) {
		return false;}
	if (textvalidation(recID, 'Please specify the name of the recipient.') == false ) {return false;}
	if (textvalidation(bdayID, 'Please tell us what birthday is being celebrated. For example, 21st birthday, 50th birthday etc.') == false ) {return false;}
	if (valuevalidation(invitesID, 6, 20, 'i', 'Please specify the number of invitations. Minimum is 6 and maximum is 20') == false ) {return false;}

}

// MUSIC TUITION ENQUIRY FORM VALIDATION

function validateTuitionForm(nameID, emailID, serviceID, ageID, experienceID, suitDaysID, suitTimeID) {
	
	if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
	if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
	if (selectvalidation(serviceID, 'Please specify a service in which you are interested from the drop-down menu.') == false) {
			return false;}
	if (valuevalidation(ageID, 5, 150, 'i', 'Please specify a valid number for the age of the student.') == false ) {return false;}
	if (textvalidation(experienceID, 'Please specify any musical experience possessed by the student.') == false ) {return false;}
	if (textvalidation(suitDaysID, 'Please specify what days would suit best for tuition.') == false ) {return false;}
	if (selectvalidation(suitTimeID, 'Please specify what time of day would suit best for tuition from the drop-down menu.') == false) {
			return false;}
}

// KAROAKE MADE TO ORDER FORM VALIDATION

function validateKaraokeForm(nameID, emailID, titleID, artistID) {
	if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
	if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
	if (textvalidation(titleID, 'Please enter the title of your specific track.') == false ) {return false;}
	if (textvalidation(artistID, 'Please enter the artist name for your track.') == false ) {return false;}
}


// SPL AGENCY BOOKING FORM

function validateSPLForm(nameID, emailID, dateDayID, dateMonthID, dateYearID, curD, curM, curY, 
							 venueID, showID, functionID, tributeID, soloID, timesID) {
	
	if (textvalidation(nameID, 'Please enter your name.') == false ) {return false;}
	if (emailvalidation(emailID, 'Please enter a valid email address.') == false ) {return false;}
	if (datevalidation(dateDayID, dateMonthID, dateYearID, curD, curM, curY, 
						   'The date specified is invalid. Please enter a date starting from tomorrow.') == false ) {
			return false;}
		if (textvalidation(venueID, 'Please specify your Venue or Event.') == false ) {return false;}
		if (!(selectvalidation(showID) || selectvalidation(functionID) ||
			selectvalidation(tributeID) || selectvalidation(soloID))) {
			alert('Please select at least one act or band from the drop-down menus.');
			return false;}
		if (textvalidation(timesID, 
						   'Please enter booking times for the date specified. For example, from 3pm to 5pm.') == 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;}
}
}
