// JavaScript Document
			
var copyContactInfo = false
var nameCode = "";

function checkContactForm() {
	focusSet = false
	formGood = true;
	var firstName = document.getElementById('firstName')
	var lastName = document.getElementById('lastName')
	document.getElementById('firstNameLabel').style.color = "black"
	document.getElementById('lastNameLabel').style.color = "black"
	document.getElementById('emailLabel').style.color = "black"
	document.getElementById('subjectLabel').style.color = "black"
	document.getElementById('messageLabel').style.color = "black"
	//alert(user.user_id)
	if(user.user_id == undefined) {
		if(firstName.value.length == 0) {
			document.getElementById('firstNameLabel').style.color = "red"
			focusFix(firstName)
			//firstName.focus()
			focusSet = true;
			formGood = false;
		}
		if(lastName.value.length == 0) {
			document.getElementById('lastNameLabel').style.color = "red"
			if(!focusSet) {
				focusFix(lastName)
				//lastName.focus()
				focusSet = true;
				formGood = false;
			}
		}
		if(document.getElementById('senderEmailAddress').value.length == 0) {
			document.getElementById('emailLabel').style.color = "red"
			if(!focusSet) {
				focusFix(document.getElementById('senderEmailAddress'))
				//document.getElementById('senderEmailAddress').focus()
				focusSet = true;
				formGood = false;
			}
		}
	}
	if(document.getElementById('subject').value.length == 0) {
		document.getElementById('subjectLabel').style.color = "red"
		if(!focusSet) {
			focusFix(document.getElementById('subject'))
			//document.getElementById('subject').focus()
			focusSet = true;
			formGood = false;
		}
	}
	if(document.getElementById('message').value.length == 0) {
		document.getElementById('messageLabel').style.color = "red"
		if(!focusSet) {
			focusFix(document.getElementById('message'))
			//document.getElementById('message').focus()
			focusSet = true;
			formGood = false;
		}
	}
	if(checkSenderEmailAddress(document.getElementById('senderEmailAddress')) && formGood) {
		messageObject.firstName = firstName.value;
		messageObject.lastName = lastName.value;
		messageObject.senderEmailAddress = document.getElementById('senderEmailAddress').value;
		messageObject.subject = document.getElementById('subject').value;
		messageObject.message = document.getElementById('message').value;
		
		
		//alert(contactMode)
		switch(contactMode) {
			case "studio":
				messageObject.studio_id = studioInfoObject.studio_id;
				messageObject.member_id = 0;
				break;
			case "member":
				messageObject.studio_id = 0;
				messageObject.member_id = memberInfoObject.id;
				break;
		}
		
		
		
		
		sendContactMessage();
		return true;
	} else {
		return false;
	}
	 //alert(document.getElementById('message').value.length)
}

// Studio
var contactMode = "studio";
function swapToContactForm() {
	//document.getElementById('clientsDisplay').innerHTML = ""
	switch(contactMode) {
		case "studio":
			contactName = studioInfoObject.studio
			break;
		case "member":
			contactName = memberInfoObject.user_display_name
			break;
	}
	document.getElementById('info').innerHTML = 
		"<div style='font-size:20px' align='center'>Contact "+contactName+"</div><br />"+
		"<form name=\"contact_studio_form\" action=\"/studio.php?studio_id="+studioInfoObject.studio_id+"\" method=\"post\" onSubmit='checkContactForm(); return false;'>"+
			"<table>"+
				"<tr>"+
					"<td colspan='2' id='statusMessage'>&nbsp;</td>"+
				"</tr>"+
				"<tr>"+
					"<td>&nbsp;</td>"+
					"<td><b>Your Info&nbsp;</b></td>"+
				"</tr>"+
				"<tr>"+
					"<td align='right' id='firstNameLabel'>First Name:&nbsp;</td>"+
					"<td><input id='firstName' name='firstName' type='text' style='width: 200px'/></td>"+
				"</tr>"+
				"<tr>"+
					"<td align='right' id='lastNameLabel'>Last Name:&nbsp;</td>"+
					"<td><input id='lastName' name='lastName' type='text' style='width: 200px'/></td>"+
				"</tr>"+
				"<tr>"+
					"<td id='emailLabel' align='right'>Email Address:&nbsp;</td>"+
					"<td>"+
						"<input id='senderEmailAddress' name='senderEmailAddress' type='text' style='width: 200px'/>"+
					"</td>"+
				"</tr>"+
				"<tr>"+
					"<td colspan='2'>&nbsp;</td>"+
				"</tr>"+
				"<tr>"+
					"<td>&nbsp;</td>"+
					"<td><b>Message Info&nbsp;</b></td>"+
				"</tr>"+
				"<tr>"+
					"<td id='subjectLabel' align='right'>"+
						"Subject:&nbsp;"+
					"</td>"+
					"<td>"+
						"<input id='subject' name='subject' type='text' style='width: 200px'/>"+
					"</td>"+
				"</tr>"+
				"<tr valign='top'>"+
					"<td id='messageLabel' align='right'>"+
						"Message:&nbsp;"+
					"</td>"+
					"<td>"+
						"<textarea id='message' name='message' style='width: 400px'></textarea>"+
					"</td>"+
				"</tr>"+
				"<tr valign='top'>"+
					"<td align='right'>"+
						"&nbsp;"+
					"</td>"+
					"<td>"+
						"<input id=\"send_message_button\" name=\"send_message\" type='submit' value='Send' />"+
					"</td>"+
				"</tr>"+
			"</table>"+
			"<input name='user_id' type='hidden' value='"+user.userID+"' />"+
		"</form>"
	//alert(user.firstName)
	if(user.first_name != undefined) {
		document.contact_studio_form.firstName.value = user.first_name
	}
	if(user.last_name != undefined) {
		document.contact_studio_form.lastName.value = user.last_name
	}
	if(user.email != undefined) {
		document.contact_studio_form.senderEmailAddress.value = user.email
	}
	if(user.user_id>0) {
		document.getElementById('firstName').disabled = true;
		document.getElementById('lastName').disabled = true;
		document.getElementById('senderEmailAddress').disabled = true;
		//document.getElementById('subject').focus()
		focusFix(document.getElementById('subject'))
	} else {
		//document.contact_studio_form.firstName.focus()
		focusFix(document.getElementById('firstName'))
		//document.getElementById('firstName').focus()
	}
}

function showContactForm() {
	//nameCode = Math.floor(Math.random()*11000)
	nameCode = ""
	//alert('Contact Form')
			
	var yourInfo =
		"<tr>"+
			"<td id='senderNameLabel' align='right'>Your Name:&nbsp;</td>"+
			"<td><input tabIndex='81' id='senderName' name='senderName' type='text' value='' /></td>"+
		"</tr>"+
		"<tr>"+
			"<td id='senderEmailAddressLabel' align='right'>Your Email Address:&nbsp;</td>"+
			"<td><input tabIndex='82' id='senderEmailAddress' name='senderEmailAddress' type='text' value='' /></td>"+
		"</tr>";
	
	if(user.email != undefined) {
		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,"");
		}
		String.prototype.ltrim = function() {
			return this.replace(/^\s+/,"");
		}
		String.prototype.rtrim = function() {
			return this.replace(/\s+$/,"");
		}
		
		var name = user.first_name+" "+user.last_name
		name = name.trim()
		yourInfo =
			"<tr>"+
				"<td id='senderNameLabel' align='right'>Your Name:&nbsp;</td>"+
				"<td><input tabIndex='81' id='senderName' name='senderName' type='text' value='"+name+"' disabled='disabled' /></td>"+
			"</tr>"+
			"<tr>"+
				"<td id='senderEmailAddressLabel' align='right'>Your Email Address:&nbsp;</td>"+
				"<td><input tabIndex='82' id='senderEmailAddress' name='senderEmailAddress' type='text' value='"+user.email+"' disabled='disabled' /></td>"+
			"</tr>";
	}
	var contactForm = 
		"<div id='contactBody'>"+
			"<form name='contact_form' id='contact_form' onSubmit='return checkRegistrationContactForm()'>"+
				"<table>"+yourInfo+
					"<tr valign='top'>"+
						"<td id='senderMessageLabel' align='right'>Message:&nbsp;</td>"+
						"<td><textarea tabIndex='83' id='senderMessage' name='senderMessage' type='text'></textarea></td>"+
					"</tr>"+
					"<tr>"+
						"<td align='right'>&nbsp;</td>"+
						"<td><input tabIndex='84' id='sendButton' name='sendButton' type='submit' value='Send Message' /></td>"+
					"</tr>"+
					"<tr>"+
						"<td align='right'>&nbsp;</td>"+
						"<td id='statusMessage'>&nbsp;</td>"+
					"</tr>"+
				"</table>"+
			"</form>"+
		"</div>"
	contactFormPanel.setHeader("Contact Us");
	contactFormPanel.setBody(contactForm);
	//YAHOO.example.container.panel2.setFooter("End of Panel #2");
	contactFormPanel.render("doc");
	copyContactInfo = false
	if(copyContactInfo) {
		if(document.new_registration.first_name.value.length>0) {
			document.getElementById('senderName'+nameCode).value = document.new_registration.first_name.value
		}
		if(document.getElementById('last_name').value.length>0) {
			document.getElementById('senderName'+nameCode).value += " "+document.new_registration.last_name.value
		}
		if(document.getElementById('email').value.length>0) {
			document.getElementById('senderEmailAddress'+nameCode).value = document.new_registration.email.value
		}
	}
	contactFormPanel.show();
	//alert('hi')
	if(document.getElementById('senderMessage').value.length==0) {
		focusFix(document.getElementById('firstName'))
		//document.getElementById('firstName').focus()
		//contactFormPanel.focusFirst('senderMessage'+nameCode)
	}
	if(document.getElementById('senderEmailAddress').value.length==0) {
		focusFix(document.getElementById('senderEmailAddress'))
		//document.getElementById('senderEmailAddress').focus()
		//contactFormPanel.focusFirst('senderEmailAddress'+nameCode)
	}
	if(document.getElementById('senderName').value.length==0) {
		focusFix(document.getElementById('senderName'))
		//document.getElementById('senderName').focus()
		//contactFormPanel.focusFirst('senderName'+nameCode)
		//alert('hi')
	}
}
var loginConnectPass = false;
function showLoginForm() {
	var loginForm = 
		"<div id='contactBody'>"+
			"<fb:login-button perms='email, publish_stream, create_event, user_birthday, user_events, user_status, read_friendlists, offline_access, manage_pages'></fb:login-button><br /><br /><div style='font-size:x-large;'>or</div><br />"+
			"<form name='login_form' id='login_form' method='post' onSubmit='document.getElementById(\"loginButton\").disabled=true; return mainPageLogin();'>"+
				"<label>Email:</label><br />"+
				"<input id='email' onfocus='this.style.backgroundColor=\"#66FFCC\"' onblur='this.style.backgroundColor=\"white\"' name='email' type='text' value='' tabindex='31' style='font-size:x-large;' /><br /><br />"+
				"<label>Password:</label><br />"+
				"<input id='password' onfocus='this.style.backgroundColor=\"#66FFCC\"' onblur='this.style.backgroundColor=\"white\"' name='password' type='password' value='' tabindex='31' style='font-size:x-large;' /><br /><br />"+
				"<label style='cursor:pointer'><input id='remember_me' name='remember_me' type='checkbox' value=''/> Remember Me</label><br /><a href='#' onclick=\"contactFormPanel.hide(); viewPage(this, 'forgot_password', '', ''); return false; \" style='color:blue'>Forgot My Password</a><br /><br />"+
				"<input tabindex='33' type='submit' id='loginButton' value='Login' style='font-size:x-large;'/>"+
			"</form>"+
			"<div id='loginMessage' style='color:#FF0000'>&nbsp;</div>"+
		"</div>"
	contactFormPanel.cfg.queueProperty("width",300);!
	contactFormPanel.setHeader("MyStudioSessions.com Login");
	contactFormPanel.setBody(loginForm);
	//YAHOO.example.container.panel2.setFooter("End of Panel #2");
	contactFormPanel.render("doc");
	contactFormPanel.showEvent.subscribe(checkCookie);
	contactFormPanel.show();
	//checkCookie();
	FB.init({appId: '250772333390', status: true, cookie: true, xfbml: true}, '/xd_receiver.htm');
	//alert('hi')
	/*
	if(document.getElementById('senderMessage').value.length==0) {
		focusFix(document.getElementById('firstName'))
		//document.getElementById('firstName').focus()
		//contactFormPanel.focusFirst('senderMessage'+nameCode)
	}
	if(document.getElementById('senderEmailAddress').value.length==0) {
		focusFix(document.getElementById('senderEmailAddress'))
		//document.getElementById('senderEmailAddress').focus()
		//contactFormPanel.focusFirst('senderEmailAddress'+nameCode)
	}
	if(document.getElementById('senderName').value.length==0) {
		focusFix(document.getElementById('senderName'))
		//document.getElementById('senderName').focus()
		//contactFormPanel.focusFirst('senderName'+nameCode)
		//alert('hi')
	}
	*/
}
	
function sendMessage(){
	//alert('hi')
	document.getElementById('sendButton'+nameCode).disabled = true
	document.getElementById('statusMessage'+nameCode).style.color = "black"
	document.getElementById('statusMessage'+nameCode).innerHTML = ""
	var postData = 
	"&java=1"+
	"&send_message=1"+
	"&senderName="+document.getElementById('senderName'+nameCode).value+
	"&senderEmailAddress="+document.getElementById('senderEmailAddress'+nameCode).value+
	"&senderMessage="+document.getElementById('senderMessage'+nameCode).value
	//alert('hi');
	
	var div = document.getElementById('main_content');
	var handleSuccess = function(o){
	
		if(o.responseText !== undefined){
			response = o.responseText
			String.prototype.trim = function() {
				return this.replace(/^\s+|\s+$/g,"");
			}
			String.prototype.ltrim = function() {
				return this.replace(/^\s+/,"");
			}
			String.prototype.rtrim = function() {
				return this.replace(/\s+$/,"");
			}
			response = response.trim()
			//alert(response)
			if(response == "message sent.") {
				document.getElementById('contactBody').innerHTML = "Message sent. Thank you."
				//alert(o.responseText)
			}
		} else {
			//document.getElementById('sendButton'+nameCode).disabled = false
		}
	}
	
	var handleFailure = function(o){
		document.getElementById('sendButton'+nameCode).disabled = false
		document.getElementById('statusMessage'+nameCode).innerHTML = "Send Failed. Please try again."
		document.getElementById('statusMessage'+nameCode).style.color = "red"
		//div.innerHTML = "Something is wrong";
	}

	var callback =
	{
	  success: handleSuccess,
	  failure: handleFailure,
	  argument: ['foo','bar']
	};
	var sUrl = "/newmember.php"
	var message = "Settings:\n"
	//alert(postData);
	//alert("Setting Reminder\n"+message+"\n\n"+postData)
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

var messageObject = new Object

// Studio
function sendContactMessage(){
	// WORKS
	
	
	
	//alert('hi')
	//document.getElementById('sendButton'+nameCode).disabled = true
	//document.getElementById('statusMessage'+nameCode).style.color = "black"
	//document.getElementById('statusMessage'+nameCode).innerHTML = ""
	
	
	
	
	/*
	messageObject.firstName = document.getElementById('firstName').value;
	messageObject.lastName = document.getElementById('lastName').value;
	messageObject.senderEmailAddress = document.getElementById('senderEmailAddress').value;
	messageObject.subject = document.getElementById('subject').value;
	messageObject.message = document.getElementById('message').value;
	messageObject.studio_id = studioInfoObject.studio_id;
	*/
	
	name = messageObject.firstName+" "+messageObject.lastName
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}
	String.prototype.ltrim = function() {
		return this.replace(/^\s+/,"");
	}
	String.prototype.rtrim = function() {
		return this.replace(/\s+$/,"");
	}
	name = name.trim()
	
	
	
	
	var postData = 
	"&java=1"+
	"&send_message=1"+
	"&firstName="+messageObject.firstName+
	"&lastName="+messageObject.lastName+
	"&member_id="+messageObject.member_id+
	"&studio_id="+messageObject.studio_id+
	"&senderEmailAddress="+messageObject.senderEmailAddress+
	"&message="+messageObject.message+
	"&subject="+messageObject.subject
	
	document.getElementById('send_message_button').disabled = true;
	
	
	//alert('hi');
	
	//var div = document.getElementById('main_content');
	var handleSuccess = function(o){
	
		if(o.responseText !== undefined){
			response = o.responseText
			String.prototype.trim = function() {
				return this.replace(/^\s+|\s+$/g,"");
			}
			String.prototype.ltrim = function() {
				return this.replace(/^\s+/,"");
			}
			String.prototype.rtrim = function() {
				return this.replace(/\s+$/,"");
			}
			response = response.trim()
		
			if(response == "message sent.") {
				document.getElementById('info').innerHTML = "Message sent. Thank you."
				//alert(o.responseText)
			} else {
				var responseArray = response.split('<--js-->');
				document.getElementById('info').innerHTML = responseArray[1];
			}
		} else {
			//document.getElementById('sendButton'+nameCode).disabled = false
		}
	}
	var handleFailure = function(o){
		document.getElementById('sendButton'+nameCode).disabled = false
		document.getElementById('statusMessage'+nameCode).innerHTML = "Send Failed. Please try again."
		document.getElementById('statusMessage'+nameCode).style.color = "red"
		//div.innerHTML = "Something is wrong";
	}

	var callback =
	{
	  success: handleSuccess,
	  failure: handleFailure,
	  argument: ['foo','bar']
	};
	var sUrl = "/includes/java_http.php?java=1"
	var message = "Settings:\n"
	//alert(postData);
	//alert("Setting Reminder\n"+message+"\n\n"+postData)
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}
		
function checkRegistrationContactForm() {
	focusSet = false
	formGood = true;
	document.getElementById('senderNameLabel'+nameCode).style.color = "black"
	document.getElementById('senderEmailAddressLabel'+nameCode).style.color = "black"
	document.getElementById('senderMessageLabel'+nameCode).style.color = "black"
	//if(user.userID == 0) {
	if(document.getElementById('senderName'+nameCode).value.length == 0) {
		document.getElementById('senderNameLabel'+nameCode).style.color = "red"
		focusFix(document.getElementById('senderNameLabel'+nameCode))
		//document.getElementById('senderName'+nameCode).focus()
		focusSet = true;
		formGood = false;
	}
	if(document.getElementById('senderEmailAddress'+nameCode).value.length == 0) {
		document.getElementById('senderEmailAddressLabel'+nameCode).style.color = "red"
		if(!focusSet) {
			focusFix(document.getElementById('senderEmailAddress'+nameCode))
			//document.getElementById('senderEmailAddress'+nameCode).focus()
			focusSet = true;
			formGood = false;
		}
	}
	//}
	if(document.getElementById('senderMessage'+nameCode).value.length == 0) {
		document.getElementById('senderMessageLabel'+nameCode).style.color = "red"
		if(!focusSet) {
			focusFix(document.getElementById('senderMessage'+nameCode))
			//document.getElementById('senderMessage'+nameCode).focus()
			focusSet = true;
			formGood = false;
		}
	}
	if(checkSenderEmailAddress(document.getElementById('senderEmailAddress'+nameCode)) && formGood) {
		sendMessage();				
		return false;
	} else {
		//alert('hi')
		return false;
	}
	 //alert(document.getElementById('message').value.length)
}

function checkSenderEmailAddress(e){

	emailAddressEntered = false;
	document.getElementById('statusMessage').innerHTML = "&nbsp;"
	var returnval=emailfilter.test(e.value)
	
	if (returnval==false){
		//alert("Please enter a valid email address.")
		emailAddressEntered = false;
		document.getElementById('statusMessage').style.color = "#FF0000"
		document.getElementById('statusMessage').innerHTML = "Please enter a valid email address."
		focusFix(document.getElementById('senderEmailAddress'))
		//alert('hi');
		//e.select()
	} else {
		emailAddressEntered = true;
		//document.getElementById('loginMessage').style.color = "#00FF00"
		//document.getElementById('loginMessage').innerHTML = "Email Ok."
	}
	return returnval
}
/*
function checkSenderEmailAddress(e){
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	emailAddressEntered = false;
	document.getElementById('statusMessage'+nameCode).innerHTML = "&nbsp;"
	//alert('here')
	var returnval=emailfilter.test(e.value)
	
	if (returnval==false){
	//alert('here')
		//alert("Please enter a valid email address.")
		emailAddressEntered = false;
		document.getElementById('statusMessage'+nameCode).style.color = "#FF0000"
		document.getElementById('statusMessage'+nameCode).innerHTML = "Please enter a valid email address."
		document.getElementById('senderEmailAddressLabel'+nameCode).style.color = "red"
		//alert('hi');
		//e.select()
	} else {
	//alert('there')
		emailAddressEntered = true;
		document.getElementById('senderEmailAddressLabel'+nameCode).style.color = "black"
		//document.getElementById('loginMessage').style.color = "#00FF00"
		//document.getElementById('loginMessage').innerHTML = "Email Ok."
	}
	return returnval
}
*/