	// JavaScript Document
var preloaded = false;

function isEmpty(inputStr) { 
	return ( null == inputStr || "" == inputStr ) 
}

function IsNumeric(strString) {
	
		//  check for valid numeric strings	
   		var strValidChars = "0123456789.-";
   		var strChar;
   		var blnResult = true;

   		if (strString.length == 0) return false;

   		//  test strString consists of valid characters listed above
   		for (i = 0; i < strString.length && blnResult == true; i++) {
      		strChar = strString.charAt(i);
     		 if (strValidChars.indexOf(strChar) == -1) {
         		blnResult = false;
         	 }
      	}
			
  		return blnResult;
}

function hide_value(el) {
	/* Hide search value on focus*/
	if(el.V) {
		if (el.value == el.V) {
			el.value = '';
		}
	} else {
		el.V = el.value;
		el.value = '';
	}
}
   
	
function ReadCookie(cookieName) {
	 var theCookie=""+document.cookie;
	 var ind=theCookie.indexOf(cookieName);
	 if (ind==-1 || cookieName=="") return ""; 
	 var ind1=theCookie.indexOf(';',ind);
	 if (ind1==-1) ind1=theCookie.length; 
	 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function maxChars(ta, count) {
	return (ta.value.length < count);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 	return true;					
}
		
function validateContactForm() {
		
		var contact_us_name = document.getElementById("contact_us_name");
		var contact_us_email = document.getElementById("contact_us_email");
		var contact_us_query = document.getElementById("contact_us_query");

		if (isEmpty(contact_us_name.value)) {alert('Please provide your name');return false;}
		
		if (isEmpty(contact_us_email.value)) {alert('Please provide an email address');return false;}
		if (!echeck(contact_us_email.value)) {alert('Please provide a valid email address');return false;}

		if (isEmpty(contact_us_query.value)) {alert('Please provide a query or comment');return false;}
			
		//Take out this and return 'true' when in production
		//alert('Form is validated and can now be submitted')
		return true;
}

function validateNewsletterForm() {
		
		var email = document.getElementById("Email");
		var conditions_chbx = document.getElementById("Conditions");
		
		if (isEmpty(email.value)) {alert('Please provide your email address');return false;}
		if (!echeck(email.value)) {alert('Please provide a valid email address');return false;}
		if (!conditions_chbx.checked) {alert('Please check the box to confirm that you have read our Privacy Policy.');return false;}
		
		return true;
}

function showOptionalField(cat_id) {
	
	if (cat_id != '') {
		var site_category = document.getElementById('site_category');
		site_category.value = cat_id;
		
		//get hidden span fields
		var standard_fields = document.getElementById('standard_fields');
		
		//Standard optional fields
		var optional_field_all = document.getElementById('optional_field_all');
		
		//Specific optional fields
		var optional_field_6 = document.getElementById('optional_field_6');
		var optional_field_9 = document.getElementById('optional_field_9');
		var optional_field_10 = document.getElementById('optional_field_10');
		var optional_field_15 = document.getElementById('optional_field_15');
		var optional_field_16 = document.getElementById('optional_field_16');
		var optional_field_17 = document.getElementById('optional_field_17');
		
		//Not voting awards
		var optional_field_13 = document.getElementById('optional_field_13');
		var optional_field_14 = document.getElementById('optional_field_14');
		var optional_field_18 = document.getElementById('optional_field_18');
		var optional_field_19 = document.getElementById('optional_field_19');
		
		var verification_field = document.getElementById('verification_field');
		var submit_field = document.getElementById('submit_field');
		var submit_field_1 = document.getElementById('submit_field_1');
		
		
		/* labels to be defined */
		var site_url_label = document.getElementById('site_url_label');
		var site_name_label = document.getElementById('site_name_label');
		var site_maincontact_company_label = document.getElementById('site_maincontact_company_label');
		var site_maincontact_company_small = document.getElementById('site_maincontact_company_small');
		var site_maincontact_role_small = document.getElementById('site_maincontact_role_small');
		
		//Turn off all fields first
		standard_fields.className = 'span_on';
		optional_field_all.className = 'span_on';
		optional_field_6.className = 'span_off';
		optional_field_9.className = 'span_off';
		optional_field_10.className = 'span_off';
		optional_field_15.className = 'span_off';
		optional_field_16.className = 'span_off';
		optional_field_17.className = 'span_off';
		
		optional_field_13.className = 'span_off';
		optional_field_14.className = 'span_off';
		optional_field_18.className = 'span_off';
		optional_field_19.className = 'span_off';

		
		verification_field.className = 'span_off';
		submit_field.className = 'span_off';
		submit_field_1.className = 'span_off';
		
		//Turn on a particular <span> to show options by Category
		//alert(cat_id)
		switch(cat_id) {
		
			case '6': 
				//campaign
				standard_fields.className = 'span_on';
				optional_field_6.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Website URL / Campaign link:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
				
			break;
			
			case '9': 
				//design development agency
				standard_fields.className = 'span_on';
				optional_field_9.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Agency Website URL:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
				
			break;
			
			case '10': 
				//Interactive Entertainment
				standard_fields.className = 'span_on';
				optional_field_10.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Website URL / Link(s) to app in iTunes, Ovi or other app store:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
				
			break;

			case '15': 
				//The Graduate
				standard_fields.className = 'span_on';
				optional_field_15.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of entry / Your name:';
				site_url_label.innerHTML = 'Website or Portfolio URL:';
				site_maincontact_company_label.innerHTML = 'Place of Employment:';
				site_maincontact_company_small.innerHTML = 'If applicable';
				site_maincontact_role_small.innerHTML = 'Mr/Mrs/Ms/Miss (please specify)';
			break;
			
			case '16': 
				//Digital Editor
				standard_fields.className = 'span_on';
				optional_field_16.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Website or Portfolio URL:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
			break;
			
			case '17': 
				//Mobile Application
				standard_fields.className = 'span_on';
				optional_field_17.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_off';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Link(s) to app in iTunes, Ovi or other app store:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
				
			break;
			
			case '13': 
				//Big Mouth
				standard_fields.className = 'span_off';
				optional_field_13.className = 'span_on';
				verification_field.className = 'span_off';
				submit_field.className = 'span_off';
				submit_field_1.className = 'span_off';
				optional_field_all.className = 'span_off';
			break;
			
			case '14':
				//Online Community
				standard_fields.className = 'span_off';
				optional_field_14.className = 'span_on';
				verification_field.className = 'span_off';
				submit_field.className = 'span_off';
				submit_field_1.className = 'span_off';
				optional_field_all.className = 'span_off';
			break;
			
			case '18': 
				//Internet Hero
				standard_fields.className = 'span_off';
				optional_field_18.className = 'span_on';
				verification_field.className = 'span_off';
				submit_field.className = 'span_off';
				submit_field_1.className = 'span_off';
				optional_field_all.className = 'span_off';
			break;
			
			case '19':
				//Grand Prix
				standard_fields.className = 'span_off';
				optional_field_19.className = 'span_on';
				verification_field.className = 'span_off';
				submit_field.className = 'span_off';
				submit_field_1.className = 'span_off';
				optional_field_all.className = 'span_off';
			break;
			
			default:
				//standard form
				standard_fields.className = 'span_on';
				verification_field.className = 'span_on';
				submit_field.className = 'span_on';
				submit_field_1.className = 'span_on';
				optional_field_all.className = 'span_on';
				
				site_name_label.innerHTML = 'Name of Entry:';
				site_url_label.innerHTML = 'Website URL:';
				site_maincontact_company_label.innerHTML = 'Company:';
				site_maincontact_company_small.innerHTML = '';
				site_maincontact_role_small.innerHTML = 'CEO/Owner/MD/Marketing Manager/Other (please specify)';
		
		}//End Switch
		
	}else{
		return;	
	}
	
}

	
function showGSAField(id) {
	
	// id = 1 [Tutor voting student]
	// id = 2 [Manager voting student]
	// id = 3 [Student voting student]
	
	var GSA22_option_1 = document.getElementById('GSA22_option_1');	//Tutor voting student and Manager voting student
	var GSA22_option_2 = document.getElementById('GSA22_option_2');	//Student voting student
		
	//Turn all off first
	GSA22_option_1.className = 'span_off';
	GSA22_option_2.className = 'span_off';
		
	if (id != '') {
		
		if (id == '1' || id == '2' ) {
			var GSA22_option = document.getElementById('GSA22_option_1');	//Chosen option		
		}
		
		if (id == '3') {
			var GSA22_option = document.getElementById('GSA22_option_2');	//Chosen option		
		}

		//Turn designated one on
		GSA22_option.className = 'span_on';	
	}
	
}

		  
function displayOptionalField(cat_id) {
	
	var site_category = document.getElementById('site_category');
	site_category.value = cat_id;
	
	//get hidden span fields
	var standard_fields = document.getElementById('standard_fields');
	var optional_field_15 = document.getElementById('optional_field_15');
	var optional_field_7 = document.getElementById('optional_field_7');
	var optional_field_21 = document.getElementById('optional_field_21');
	var optional_field_3 = document.getElementById('optional_field_3');
	var optional_field_20 = document.getElementById('optional_field_20');
	var optional_field_22 = document.getElementById('optional_field_22');
	var optional_field_23 = document.getElementById('optional_field_23');
	var optional_field_24 = document.getElementById('optional_field_24');
	
	var verification_field = document.getElementById('verification_field');
	var submit_field = document.getElementById('submit_field');
	
	//Turn off all fields first
	standard_fields.className = 'span_off';
	optional_field_15.className = 'span_off';
	optional_field_7.className = 'span_off';
	optional_field_21.className = 'span_off';
	optional_field_3.className = 'span_off';
	optional_field_20.className = 'span_off';
	optional_field_22.className = 'span_off';
	optional_field_23.className = 'span_off';
	optional_field_24.className = 'span_off';
		
	verification_field.className = 'span_off';
	submit_field.className = 'span_off';
	
	//Turn on a particular <span> to show options by Category
	//alert(cat_id)
	switch(cat_id) {
	
		case '15': 
			//web design agency
			standard_fields.className = 'span_on';
			optional_field_15.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
		break;
		
		case '7': 
		//interactive marketing
			standard_fields.className = 'span_on';
			optional_field_7.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
		break;
		
		case '20': 
			//Peoples Choice
			standard_fields.className = 'span_off';
			optional_field_20.className = 'span_on';
			verification_field.className = 'span_off';
			submit_field.className = 'span_off';
		break;
		
		case '21': 
			//best mobile content
			standard_fields.className = 'span_on';
			optional_field_21.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
		break;
		
		case '22': 
			//Apprentice
			standard_fields.className = 'span_off';	//Turn off standard field
			optional_field_22.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
		break;
		
		case '23': 
			//Internet Hero
			standard_fields.className = 'span_off';
			optional_field_23.className = 'span_on';
			verification_field.className = 'span_off';
			submit_field.className = 'span_off';
		break;
		
		case '24': 
			//Grand Prix
			standard_fields.className = 'span_off';
			optional_field_24.className = 'span_on';
			verification_field.className = 'span_off';
			submit_field.className = 'span_off';
		break;
		
		case '3':
			//Charity
			standard_fields.className = 'span_on';
			optional_field_3.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
		break;
		
		default:
			//standard form
			standard_fields.className = 'span_on';
			verification_field.className = 'span_on';
			submit_field.className = 'span_on';
	
	}
	
}

function val_email(id) {
	
	var obj = document.getElementById(id);
	
	if (!isValidEmail(obj.value))	 {
		alert('This is not a valid email address');	
		obj.value = '';
		return false;
	}
	
	return true;
	
	
}


function val_numeric(obj) {
	
	if (!IsNumeric(obj.value))	 {
		alert('Numeric entry only please');	
		obj.value = '';
		obj.focus();
		return false;
	}
	
	return true;
	
	
}

function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}


function IsNumeric(sText) {
	
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

