// JavaScript Document


// This function checks if the username field
// is at least 6 characters long.
// If so, it attaches class="welldone" to the 
// containing fieldset.

function checkForLength(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 0) {
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}





// This function checks the email address to be sure
// it follows a certain pattern:
// blah@blah.blah
// If so, it assigns class="welldone" to the containing
// fieldset.

function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "notgood";
	}
}


///FEEBLE ATTEMPT TO VALIDATE FONENUMB... not nec- cause out of req.
//only check if there is 10 characters or more... simple.

function checkPhone(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 9 ) {
		fieldset.className = "welldone";
	} else {
		
		fieldset.className = "notgood";
	}
}

function checkSpam(whatYouTyped) {
	
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt=="10") {
		fieldset.className = "welldone";
	} else {
		
		fieldset.className = "notgood";
	}
}


// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.
/*
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
      fieldset.className = "notgood";
	  this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
     this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
}
addLoadEvent(prepareInputsForHints);*/

//to validate phone number



////////////////
//FINAL VALIDATION for advertising//
function validate_form_adv ( )
{
	OK = false;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.AdvertisingContactForm.email.value;
	var spamValue = "10";
	var spamLoc = document.AdvertisingContactForm.spam_loc.value;
	valid = true;

    if ( document.AdvertisingContactForm.name.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter your name.";
	
        valid = false;
    }
	else if ( document.AdvertisingContactForm.company.value == "" )
    {
		document.getElementById("form_errors").innerHTML = "Please enter your company.";
	
       
        valid = false;
    }
 	else if ( document.AdvertisingContactForm.title.value == "" )
    {
       document.getElementById("form_errors").innerHTML = "Please enter your title.";
	
        valid = false;
    }
	else  if ( reg.test(address) == false)
    {
        document.getElementById("form_errors").innerHTML = "Please enter your valid e-mail. (Don't worry we never spam.)";
		
        valid = false;
    }
		else  if (document.AdvertisingContactForm.spam_loc.value != "10")
    {
        document.getElementById("form_errors").innerHTML = "Robot says what?";
		
        valid = false;
    }
	
    return valid;

	
}

////////////////
//FINAL VALIDATION for locations//
function validate_form_loc ( )
{
	OK = false;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.LocationsContactForm.email.value;
	var spamValue = "10";
	var spamLoc = document.LocationsContactForm.spam_loc.value;
	valid = true;

    if ( document.LocationsContactForm.name.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter your name.";
	
        valid = false;
    }
	
	else  if ( reg.test(address) == false)
    {
        document.getElementById("form_errors").innerHTML = "Please enter your valid e-mail. (Don't worry we never spam.)";
		
        valid = false;
    }
		else  if (document.LocationsContactForm.spam_loc.value != "10")
    {
        document.getElementById("form_errors").innerHTML = "Robot says what?";
		
        valid = false;
    }
	
    return valid;

	
}


////////////////
//FINAL VALIDATION for CONTACT//


function validate_form ( ){
	
	OK = false;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.ContactForm.emailadd.value;
	
	var spamValue = "10";
	var spamLoc = document.ContactForm.spam_loc.value;
	valid = true;

    if ( document.ContactForm.fname.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter your first name.";
	
        valid = false;
    }
	else if ( document.ContactForm.lname.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter your last name.";
	
        valid = false;
    }
	 	else if ( document.ContactForm.title.value == "" )
    {
       document.getElementById("form_errors").innerHTML = "Please enter your title.";
	
        valid = false;
    }
	else  if ( reg.test(address) == false)
    {
        document.getElementById("form_errors").innerHTML = "Please enter your valid e-mail. (Don't worry we never spam.)";
		
        valid = false;
    }
	
	else if ( document.ContactForm.orgname.value == "" )
    {
		document.getElementById("form_errors").innerHTML = "Please enter your organization name.";
	
       
        valid = false;
    }


	else  if (document.ContactForm.spam_loc.value != "10")
    {
        document.getElementById("form_errors").innerHTML = "Robot says what?";
		
        valid = false;
    }
	
    return valid;

	
}




////////////////




//////////SIGNUP SHEET /// TEMP!

function validate_form_signup ( )
{
	
	OK = false;
	var reg_signup = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address_signup = document.SIGNUPForm.emailadd.value;
	
	var spamValue = "10";
	
	valid = true;

    if ( document.SIGNUPForm.name.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter the band or artist name.";
	
        valid = false;
    }
	else if ( document.SIGNUPForm.lable.value == "" )
    {
        document.getElementById("form_errors").innerHTML = "Please enter the Name of the Lable currently registered with AMI.";
	
        valid = false;
    }
	 	else if ( document.SIGNUPForm.publishing.value == "" )
    {
       document.getElementById("form_errors").innerHTML = "Please enter the Name of the Publishing company currently registered with AMI.";
	
        valid = false;
    }
	
	else if ( document.SIGNUPForm.mailing.value == "" )
    {
		document.getElementById("form_errors").innerHTML = "Please enter your full mailing address.";
	
       
        valid = false;
    }
	else  if ( reg_signup.test(address_signup) == false)
    {
        document.getElementById("form_errors").innerHTML = "Please enter your valid e-mail. (Don't worry we never spam.)";
		
        valid = false;
    }
	else if ( document.SIGNUPForm.contactnumber.value == "" )
    {
		document.getElementById("form_errors").innerHTML = "Please enter your current valid contact phone number.";
	
       
        valid = false;
    }
	
	



	
    return valid;

	
}




////////////////