function setTheRightCastAssoc() {
	//alert('setTheRightCastAssoc');

	if (location.search) {
		var in_value = location.search.substring(1);
		var pairs = in_value.split('&');
		document.create_account.assoc_name.value = pairs[0];
		if (pairs[1]) { document.create_account.assoc_type.value = pairs[1]; }
 
		var name = 'right';
		WriteCookie(name, pairs[0], 1000 * 60 * 60 * 24 * 10);
	}
	else {
		document.create_account.assoc_name.value = 0;
	}
}

function WriteCookie (cookieName, cookieValue, expiry) {
	var expDate = new Date();
	expDate.setTime (expDate.getTime() + expiry);
    document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString() + "; path=/actors";
}
 
 
function checkName(theField) {
	var fldValue = theField;
	var lowercase = /[a-z]/;
	for (var i = 0 ; i < fldValue.length; i++) {
		var ch = fldValue.substring (i, i+1)
		var result = ch.match(lowercase);
		if (result) {
			to_submit = 1;
		}
		else {
			to_submit = 0;
			break;
		}
 
	}

	if (to_submit == 0) {
		return (true)
	}
	else {
		return (false)
	}
}
 
function empty (inputStr) {
	if (inputStr == "" || inputStr == null) {
		return true
	}
	return false
}
 
function JoinFormRequireInput(CheckForm){
/*
	if (empty(CheckForm.user_name.value)){
		var alertmsg = "Please fill in the URL blank.";
		alert(alertmsg);
		document.create_account.user_name.focus();
		return 0;
	}
*/
	if (empty(CheckForm.login_name.value)) {
		var alertmsg = "Please submit a user name.";
		alert(alertmsg);
		document.create_account.login_name.focus();
		return 0;
	}
	else if (empty(CheckForm.password.value)) {
		var alertmsg = "Please submit a password.";
		alert(alertmsg);
		document.create_account.password.focus();
		return 0;
	}
 
	else if (checkName(CheckForm.login_name.value)) {
		var alertmsg = "Your user name can only include lowercase letters.  No numbers, spaces, or special characters.  A good user name is your name without the spaces.\n\nYour user name is going to be used to create your TheRightCast URL so people can find you (i.e. http://www.therightcast.net/username).\n\nAs an example, if your name was Joe Smith you would type this into the box: joesmith";

		alert(alertmsg);
		return 0;
	}
	else if (CheckForm.agree_to_terms_of_service.checked == false) {
		var alertmsg = "Please read our Terms of Service and agree to them.";
		alert(alertmsg);
		return 0;
	}
	else{
		document.create_account.user_name.value = document.create_account.login_name.value;
		//alert('submitting form' + CheckForm.agree_to_terms_of_service.value);
		//return 0;
		CheckForm.submit()
	}
	
}

function newWindow (gotoURL,name,attributes) 
{
  msgWindow = window.open(gotoURL,name,attributes);
}
 

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

function check_email(which_email) {
 
	var i = 0;
	var the_test = 0;
 
	var testString = which_email;
 
	msg_alert= "Please use a valid email address.";
 
	if (testString.length < 8) {
		msg_alert = msg_alert + "\nYour email address is too short to be valid."
		the_test = 1;
	}
	if ((i = testString.indexOf ("@",1)) < 1) {
		msg_alert = msg_alert + "\nAll email addresses, must include the '@' sign.";
		the_test = 1;
	}
	if (testString.indexOf (".",i) <= i+2) {
		msg_alert = msg_alert + "\nThere must be at least 2 characters between the '@' sign and the dot '.'";
		the_test = 1;
	}
 
	if (the_test) {
		alert(msg_alert);
		return(true);
	}
	else {
		return(false);
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
function ActorLoginRequireInput(CheckForm){
	if (empty(CheckForm.login_name.value)) {
                var alertmsg = "Please submit a login name.";
                alert(alertmsg);
				CheckForm.login_name.focus();
        }
 
	else if (empty(CheckForm.password.value)) {
		var alertmsg = "Please submit a password.";
		alert(alertmsg);
		CheckForm.password.focus();
	}
 
	else{
		CheckForm.submit()
	}
	
}


function LoginRequireInput(CheckForm){
	if (check_email(CheckForm.email.value)) {
	CheckForm.email.focus();
	CheckForm.email.select();
	}
	else if (empty(CheckForm.login_name.value)) {
                var alertmsg = "Please submit a login name.";
                alert(alertmsg);
        }
 
	else if (empty(CheckForm.password.value)) {
		var alertmsg = "Please submit a password.";
		alert(alertmsg);
	}
 
	else{
		CheckForm.submit()
	}
	
}


///////////////////////////////////////////////////////////
// submitting to casting notices:

function submit_to_notice(form_value,the_what){
	document.actor_submit.project_id.value = form_value;
	document.actor_submit.what_to_do.value = the_what;
 
	window.open('http://therightcast.com/aall/blank.html','submit_window','scrollbars=yes,width=710,height=490');
	document.actor_submit.submit();
}
