// JavaScript Document
/*====================================================================================================*/
function checkMobile(numObj,numberType)
{
	if( ( numObj.value == "" ) || ( !numObj.value.match(/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/i)) )
	{
		alert("Incorrect " + numberType + " number entered.\nAcceptable format xxx-xxx-xxxx.");
		return false;
	}
	return true;
}
/*====================================================================================================*/
/////////////////////////////////////////
function haveNum(str)   
   {
    for(i=0;i<str.length;i++)
	{
		if(str.charAt(i) >= '0' && str.charAt(i) <= '9') 
		   return false;
	}
	return true;
   }
/////////////////////////////////////////
function isAlpha(str)   
   {
    for(i=0;i<str.length;i++)
	{
		if(!( (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') || (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')  || str.charAt(i) == ' '))
		   return false;
	}
	return true;
   }
/////////////////////////////////////////   
function setFocus(field)
{
	field.focus();
	field.select();
	return false;
}   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsNumeric(strString)   
   {
   var strValidChars = ".0123456789";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function capitalize(str)
{
	return str.charAt(0).toUpperCase()+str.substr(1).toLowerCase();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showStates(countryCode)
{
	if(countryCode == 'US')
	{
		document.getElementById('CAProvinces').style.display = 'none';
		document.getElementById('Other').style.display = 'none';
		document.getElementById('USStates').style.display = 'inline';		
	}
	else if(countryCode == 'CA')
	{
		document.getElementById('USStates').style.display = 'none';
		document.getElementById('Other').style.display = 'none';				
		document.getElementById('CAProvinces').style.display = 'inline';		
	}
	else
	{
		document.getElementById('CAProvinces').style.display = 'none';		
		document.getElementById('USStates').style.display = 'none';
		document.getElementById('Other').style.display = 'inline';				
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_artist_join(x)
{
	if( x.act_name.value == "" || !isAlpha(x.act_name.value) ) 
	{
	   alert("Please type a valid act name!");
	   setFocus(x.act_name);
	}
	else if( x.contact_name.value == "" || !isAlpha(x.contact_name.value) ) 
	{
	   alert("Please type a valid contact name!");
	   setFocus(x.contact_name);
	}
	else if(!checkMobile(x.phone,'Phone'))
	{
	    setFocus(x.phone);
	}
	else if(!x.contact_email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Please type a valid Email!");
	    setFocus(x.contact_email);
	}
	else if(x.password.value.length < 6 ) 
	{
		alert("Password should have at least 6 characters");
	    setFocus(x.password);
	}
	else if( x.country.value == "US" && x.primState.value == "")
	{
		alert("Please select your state!");
	}
	else if( x.country.value == "CA" && x.primProvince.value == "")
	{
		alert("Please select your province!");
	}
	else if( x.country.value != "US" && x.country.value != "CA" && x.locality_region.value == "")
	{
		alert("Please type your locality/region!");
		setFocus(x.locality_region);
	}
	else if( x.city.value == "" || !isAlpha(x.city.value) ) 
	{
	   alert("Please type a valid city name!");
	   setFocus(x.city);
	}
	else if( x.postal_code.value == "" ) 
	{
	   alert("Please type your postal code!");
	   setFocus(x.postal_code);
	}
	else if( x.address.value == "" ) 
	{
	   alert("Please type your address!");
	   setFocus(x.address);
	}
	else if( x.vocals.value == "" ) 
	{
	   alert("Please select if you have Vocals & Music!");
	}
	else if( x.main_instrument.value == "" ) 
	{
	   alert("Please type your main instrument!");
	   setFocus(x.main_instrument);
	}
	else if( x.other_instruments.value == "" ) 
	{
	   alert("Please type your other instruments!");
	   setFocus(x.other_instruments);
	}
	else if( x.website_URL.value == "" ) 
	{
	   alert("Please type your website URL!");
	   setFocus(x.website_URL);
	}			
	else
	{
		x.email.value = x.email.value.toLowerCase();
		return true;
	}
 return false;	
}
