// SubMenu Toggle Control

var currentSubMenu = "";
var currentMenuItem = "";
var menuItemNormal = "";

function setCurrentMenuItem(item, normal) {
  if(currentMenuItem != MM_findObj(item)) {
    currentMenuItem.src = menuItemNormal;
    currentMenuItem = MM_findObj(item);
    menuItemNormal = normal;
  }
}

function toggleList(id) {
  list = document.getElementById(id);
  if (list.style.display == "inline") {
    list.style.display = "none";
  } else {
    if(currentSubMenu != "") {
      prev = document.getElementById(currentSubMenu);
      prev.style.display = "none";
    }
    list.style.display = "inline";
  }
  currentSubMenu = id;
}

function showMainItem(id) {
  MM_swapImage(id,'','images/mainnav_'+id+'-on.gif',1);
  setCurrentMenuItem(id,'images/mainnav_'+id+'-off.gif');
}

// Image Rollover

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {
    if(x!=currentMenuItem)
      x.src=x.oSrc;
  }
}

function MM_preloadImages() {
  var d=document;
  if(d.images){
    if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0) {
      d.MM_p[j]=new Image;
      d.MM_p[j++].src=a[i];
    }
  }
}

function MM_findObj(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n);
    return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr = new Array;
  for(i=0;i<(a.length-2);i+=3) {
    if ((x=MM_findObj(a[i]))!=null) {
      document.MM_sr[j++]=x;
      if(x!=currentMenuItem) {
        if(!x.oSrc) x.oSrc=x.src;
        x.src=a[i+2];
      }
    }
  }
}


//Preload Images

image1 = new Image();
image1.src = "images/butn_signup-on.gif";

image2 = new Image();
image2.src = "images/mainnav_signup-on.gif";

image3 = new Image();
image3.src = "images/mainnav_services-on.gif";

image4 = new Image();
image4.src = "images/mainnav_ourvision-on.jpg";

image5 = new Image();
image5.src = "images/mainnav_home-on.gif";

image6 = new Image();
image6.src = "images/mainnav_faq-on.gif";

image7 = new Image();
image7.src = "images/mainnav_contactus-on.gif";


//Open Browser Window

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}


//###################################
// FORM CHECKING
//###################################
function CheckContactUsForm()
{
	if( $F('name') == "" )
	{
		alert( "Please enter your Name" );
		$('name').focus();
		return false;
	}
	
	if( $F('email') == "" )
	{
		alert( "Please enter your Email Address" );
		$('email').focus();
		return false;
	}
	else if( !validEmail($F('email'), "Email Address") )
	{
		$('email').focus();
		return false;
	}
		
	if( $F('issue') == "" )
	{
		alert( "Please select the subject for your inquiry" );
		$('issue').focus();
		return false;
	}
	
	if( $F('comments') == "" )
	{
		alert( "Please enter your Message" );
		$('comments').focus();
		return false;
	}	
}

function CheckArtistContactUsForm()
{
	if( $F('name') == "" )
	{
		alert( "Please enter your Name" );
		$('name').focus();
		return false;
	}
	
	if( $F('from_address') == "" )
	{
		alert( "Please enter your Email Address" );
		$('from_address').focus();
		return false;
	}
	else if( !validEmail($F('from_address'), "Email Address") )
	{
		$('from_address').focus();
		return false;
	}
	
	if( $F('message') == "" )
	{
		alert( "Please enter your Message" );
		$('message').focus();
		return false;
	}
	
	return true;
}

function CheckSignUpForm()
{
	if( $F('login') == "" )
	{
		alert( "Please enter a Band Name" );
		$('login').focus();
		return false;
	}
	
	if( $F('pass') == "" )
	{
		alert( "Please enter a Password" );
		$('pass').focus();
		return false;
	}
	
	if( $F('pass2') == "" )
	{
		alert( "Please confirm your Password" );
		$('pass2').focus();
		return false;
	}
	
	if( $F('pass') != $F('pass2') )
	{
		alert( "The passwords you entered aren't the same. Please try again" );
		$('pass2').value = "";
		$('pass2').focus();
		return false;
	}
	
	if( $F('fname') == "" )
	{
		alert( "Please enter your First Name" );
		$('fname').focus();
		return false;
	}
	
	if( $F('lname') == "" )
	{
		alert( "Please enter your Last Name" );
		$('lname').focus();
		return false;
	}

	if( $F('phone_number') == "" )
	{
		alert( "Please enter your Phone Number" );
		$('phone_number').focus();
		return false;
	}

	if( $F('addr_street1') == "" )
	{
		alert( "Please enter your Address" );
		$('addr_street1').focus();
		return false;
	}
	
	if( $F('addr_city') == "" )
	{
		alert( "Please enter your City" );
		$('addr_city').focus();
		return false;
	}
	
	if( $F('addr_state') == "" )
	{
		alert( "Please select your State" );
		$('addr_state').focus();
		return false;
	}
	
	if( $F('addr_zip') == "" )
	{
		alert( "Please enter your Zip" );
		$('addr_zip').focus();
		return false;
	}
	
	if( $F('email') == "" )
	{
		alert( "Please enter your Email Address" );
		$('email').focus();
		return false;
	}
	else if( !validEmail($F('email'), "Email Address") )
	{
		$('email').focus();
		return false;
	}

	if( $F('billing_fname') == "" )
	{
		alert( "Please enter your Billing First Name" );
		$('billing_fname').focus();
		return false;
	}
	
	if( $F('billing_lname') == "" )
	{
		alert( "Please enter your Billing Last Name" );
		$('billing_lname').focus();
		return false;
	}
	
	if( $F('billing_address1') == "" )
	{
		alert( "Please enter your Billing Address" );
		$('billing_address1').focus();
		return false;
	}
	
	if( $F('billing_city') == "" )
	{
		alert( "Please enter your Billing City" );
		$('billing_city').focus();
		return false;
	}
	
	if( $F('billing_state') == "" )
	{
		alert( "Please select your State" );
		$('billing_state').focus();
		return false;
	}
	
	if( $F('billing_zip') == "" )
	{
		alert( "Please enter your Billing Zip" );
		$('billing_zip').focus();
		return false;
	}
	
	if( !$('agreement').checked )
	{
		alert( "Please review and agree to the Subscriber Agreement" );
		$('agreement').focus();
		return false;
	}
	
	return true;
}

function CheckCheckOutForm()
{
	if( $F('cardholder') == "" )
	{
		alert( "Please enter the name on your Credit Card" );
		$('cardholder').focus();
		return false;
	}

	if( $F('cardnumber') == "" )
	{
		alert( "Please enter your Credit Card Number" );
		$('cardnumber').focus();
		return false;
	}
	
	if( $F('cardexpmonth') == "" )
	{
		alert( "Please select your Credit Card's Expiration Month" );
		$('cardexpmonth').focus();
		return false;
	}
	
	if( $F('cardexpyear') == "" )
	{
		alert( "Please select your Credit Card's Expiration Year" );
		$('cardexpyear').focus();
		return false;
	}
	
	if( $F('cvmvalue') == "" )
	{
		alert( "Please enter the CCV number on your Credit Card" );
		$('cvmvalue').focus();
		return false;
	}
	
	return true;
}

function CheckMusicCheckOutForm()
{
	if( $F('cardholder') == "" )
	{
		alert( "Please enter the name on your Credit Card" );
		$('cardholder').focus();
		return false;
	}

	if( $F('cardnumber') == "" )
	{
		alert( "Please enter your Credit Card Number" );
		$('cardnumber').focus();
		return false;
	}
	
	if( $F('cardexpmonth') == "" )
	{
		alert( "Please select your Credit Card's Expiration Month" );
		$('cardexpmonth').focus();
		return false;
	}
	
	if( $F('cardexpyear') == "" )
	{
		alert( "Please select your Credit Card's Expiration Year" );
		$('cardexpyear').focus();
		return false;
	}
	
	if( $F('cvmvalue') == "" )
	{
		alert( "Please enter the CCV number on your Credit Card" );
		$('cvmvalue').focus();
		return false;
	}
	
	return true;
}

function CheckMusicSignUpForm()
{
	if( $F('login') == "" )
	{
		alert( "Please enter a Username" );
		$('login').focus();
		return false;
	}
	
	if( $F('pass') == "" )
	{
		alert( "Please enter a Password" );
		$('pass').focus();
		return false;
	}
	
	if( $F('pass2') == "" )
	{
		alert( "Please confirm your Password" );
		$('pass2').focus();
		return false;
	}
	
	if( $F('pass') != $F('pass2') )
	{
		alert( "The passwords you entered aren't the same. Please try again" );
		$('pass2').value = "";
		$('pass2').focus();
		return false;
	}
	
	if( $F('fname') == "" )
	{
		alert( "Please enter your First Name" );
		$('fname').focus();
		return false;
	}
	
	if( $F('lname') == "" )
	{
		alert( "Please enter your Last Name" );
		$('lname').focus();
		return false;
	}

	if( $F('phone_number') == "" )
	{
		alert( "Please enter your Phone Number" );
		$('phone_number').focus();
		return false;
	}

	if( $F('addr_street1') == "" )
	{
		alert( "Please enter your Address" );
		$('addr_street1').focus();
		return false;
	}
	
	if( $F('addr_city') == "" )
	{
		alert( "Please enter your City" );
		$('addr_city').focus();
		return false;
	}
	
	if( $F('addr_state') == "" )
	{
		alert( "Please select your State" );
		$('addr_state').focus();
		return false;
	}
	
	if( $F('addr_zip') == "" )
	{
		alert( "Please enter your Zip" );
		$('addr_zip').focus();
		return false;
	}
	
	if( $F('email') == "" )
	{
		alert( "Please enter your Email Address" );
		$('email').focus();
		return false;
	}
	else if( !validEmail($F('email'), "Email Address") )
	{
		$('email').focus();
		return false;
	}

	if( $F('billing_fname') == "" )
	{
		alert( "Please enter your Billing First Name" );
		$('billing_fname').focus();
		return false;
	}
	
	if( $F('billing_lname') == "" )
	{
		alert( "Please enter your Billing Last Name" );
		$('billing_lname').focus();
		return false;
	}
	
	if( $F('billing_address1') == "" )
	{
		alert( "Please enter your Billing Address" );
		$('billing_address1').focus();
		return false;
	}
	
	if( $F('billing_city') == "" )
	{
		alert( "Please enter your Billing City" );
		$('billing_city').focus();
		return false;
	}
	
	if( $F('billing_state') == "" )
	{
		alert( "Please select your State" );
		$('billing_state').focus();
		return false;
	}
	
	if( $F('billing_zip') == "" )
	{
		alert( "Please enter your Billing Zip" );
		$('billing_zip').focus();
		return false;
	}
	
	/*
	if( !$('agreement').checked )
	{
		alert( "Please review and agree to the Subscriber Agreement" );
		$('agreement').focus();
		return false;
	}
	*/

	return true;
}

//###################################
// UTILITIES
//###################################

// phone number - strip out delimiters and check for 10 digits
function checkPhone (strng)
{
    var error = "";
    if (strng == "")
        error = "Please enter a phone number.\n";

    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters and whitespace
    if (isNaN(parseInt(stripped)))
        error = "The phone number contains illegal characters.";

    if (!(stripped.length == 10))
        error = "The phone number is the wrong length. Make sure you included an area code.\n";

    if( error != "" )
    {
        alert( error );
        return false;
    }
    else
        return true;
}

function checkPassword(val)
{
    var error = "";
    if (val == "")
        error = "You didn't enter a password.\n";

    var strng = val.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters and whitespace
    //alert( strng );

    var illegalChars = /[\W_]+/; // check for non-alphanumeric chars
    var alphaChars = /[a-zA-Z]+/; // check for letters and numbers
    var numericChars = /[0-9]+/; // check for letters and numbers
    if (strng.length < 7)
    {
        error = "Your password must be at least 7 characters long.\n";
    }
    else if (!illegalChars.test(strng))
    {
        //error = "The password contains illegal characters.\n";
        error = "Your password must contain at least one non-alphanumeric character (!, @, _).\n";
    }
    else if (!alphaChars.test(strng))
    {
        //error = "The password contains illegal characters.\n";
        error = "Your password must contain at least one letter.\n";
    }
    else if (!numericChars.test(strng))
    {
        //error = "The password contains illegal characters.\n";
        error = "Your password must contain at least one number.\n";
    }
    /*
    else if (!((strng.search(/^[0-9a-zA-Z]+$/) > -1)))
        //&& (strng.search(/[A-Z]+/) > -1)
        //&& (strng.search(/[.!@#$*_-+]+/) > -1)
        //&& (strng.search(/[0-9]+/) > -1)))
    {
        error = "The password must be a combination of letters, numbers and characters.\n";
    }
    */
    
    if( error != "" )
    {
        alert( error );
        return false;
    }
    else
        return true;
}
  
function validEmail(e, t)
{	
	var emailStr = e;

	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\*\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="([^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + specialChars + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{	alert("Your "+ t +" seems incorrect. Please check @ and .'s!");
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null)
	{	alert("Please do not use any symbols (ie. quotes or asterisks) other than @ in your "+ t +".");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{  for (var i=1;i<=4;i++)
		  {	if (IPArray[i]>255)
			{	alert("Destination IP address is invalid!");
				return false;
			}
		}
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	{	alert("Your "+ t +" domain name doesn't seem to be valid.");
		return false;
	}			

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{	alert("Your "+ t +" must end in a three-letter domain, or two letter country.");
		return false;
	} 

	var Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (domArr[domArr.length-1].length == 2 || domArr[domArr.length-1].length == 3)
	{	for (var i = 0; i < domArr[domArr.length-1].length; i++)
		{	if (Chars.indexOf(domArr[domArr.length-1].charAt(i)) == -1)
			{	alert("The domain name can only contain letters.");
				return false;
			}
		}
	}

	if (len<2 || len>3)
	{   alert("Your "+ t +" is missing a hostname!");
	   return false;
	}
	
	return true;
}

function validNums(n, t)
{	if (n == "")
	{	alert("Please enter a number in "+ t +".")
		return false;
	}
	else
	{	var Chars = "0123456789";
		for (var i = 0; i < n.length; i++)
		{	if (Chars.indexOf(n.charAt(i)) == -1)
			{	alert ("Please enter only numbers in "+ t +".")
				return false
			}
		}
	}
	
	return true;
}

function validName(n, t)
{	if (n == "")
	{	alert("Please enter your "+ t +".")
		return false;
	}
	else
	{	var Chars = "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		for (var i = 0; i < n.length; i++)
		{	if (Chars.indexOf(n.charAt(i)) == -1)
			{	alert ("Please enter a valid "+ t +".")
				return false
			}
		}
	}
	
	return true;
}

function validZip(z, t) {
	if (z == "")
	{	alert("Please fill in your "+ t +".");
		return false; 
	}
	else
	{	// check to see that the value contains at least 5 numbers
		if (z.length < 5)
		{	alert ("Please enter at least 5 numbers into the "+ t +" field.");
			return false;
		}
		// check to see that the value contains either 5 or 10 numbers
		if (z.length > 5 && z.length < 10)
		{	alert ("Please enter either your 5-digit "+ t +" OR your 10-digit "+ t +" including the 4 digit extension (12345-1234) into the "+ t +" field.");
			return false;
		}
		// check to see that the value contains only numbers and possibly a hyphen
		var nums = "0123456789-";
		for (var i = 0; i < z.length; i++)
		{	if (nums.indexOf(z.charAt(i)) == -1)
			{	alert ("Please enter only numbers into the "+ t +" field.");
				return false;
			}
		}
		// check to see if the 6th character is a hyphen
		if (z.length == 10)
		{	if (z.charAt(5) != "-")
			{	alert("Please make sure that your "+ t +" is properly formatted. (12345-1234)");
				return false;
			}
		}
	}
	return true;
}

//###################################
// used to restrict text field user input to alpha chars only
//###################################
function AlphaOnly(f)
{
    var re = /^[a-zA-Z]*$/;
    if (!re.test(f.value))
    {
        f.value = f.value.replace(/[^a-zA-Z]/g,"");
        return false;
    }
    
    return true;
}

//###################################
// used to restrict text field user input to numeric chars only
//###################################
function NumbersOnly(f)
{
    var re = /^[0-9]*$/;
    if (!re.test(f.value))
    {
        f.value = f.value.replace(/[^0-9]/g,"");
        return false;
    }
    
    return true;
} 
