function checkIfEmpty(field) {
 if (document.getElementById(field).value != "") {
   document.getElementById(field).style.backgroundColor = "#C0C0C0";
   return true;
 } else {
   alert(field + " is a mandatory field");
   document.getElementById(field).style.backgroundColor = "white";
   document.getElementById(field).focus();
	return false;
 }
}

function TestFileType(fileName) {
	var upFile = fileName.toLowerCase();
	if ((upFile.indexOf('.wma') != -1) || (upFile.indexOf('.mp3') != -1)) {
		return true;
	} else {
		alert("Please select a valid mp3 or wma song.");
		return false;
	}

	
		
}
	
function IsEmailValid(checkThisEmail) {
	var myEMailIsValid = true;
	var myAtSymbolAt = document.getElementById(checkThisEmail).value.indexOf('@');
	var myLastDotAt = document.getElementById(checkThisEmail).value.lastIndexOf('.');
	var mySpaceAt = document.getElementById(checkThisEmail).value.indexOf(' ');
	var myLength = document.getElementById(checkThisEmail).length;
	
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 ) 
	 {myEMailIsValid = false}
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt) 
	 {myEMailIsValid = false}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	
	if (myLength - myLastDotAt <= 2) 
	 {myEMailIsValid = false}
	
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1) 
	 {myEMailIsValid = false}
	
	
	if (myEMailIsValid == true) {
		document.getElementById(checkThisEmail).style.backgroundColor = "#C0C0C0";
		return true;
	} else {
    	alert("email is not correct");
    	document.getElementById(checkThisEmail).style.backgroundColor = "white";
		document.getElementById(checkThisEmail).focus();
		return false;
	}
}

function checkConditions(field){
    if (document.getElementById(field).value != "yes") {
	    alert("You have to agree the conditions ! \n Please type yes without quotes. ");
	    document.getElementById(field).style.backgroundColor = "white";
        return false;
    } else {
	    document.getElementById(field).style.backgroundColor = "#C0C0C0";
        return true;
    }
}
