function selectUSvsCA(the_value,the_span_id){
	if(the_value=='US' || the_value=='CA'){
		document.getElementById(the_span_id+'_US').style.display='none';
		document.getElementById(the_span_id+'_CA').style.display='none';
		document.getElementById(the_span_id+'_OTHER').style.display='none';
		document.getElementById(the_span_id+'_'+the_value).style.display='block';	
	}else{
		document.getElementById(the_span_id+'_US').style.display='none';
		document.getElementById(the_span_id+'_CA').style.display='none';
		document.getElementById(the_span_id+'_OTHER').style.display='block';
	}
}

function showDateNowMini(theevent,user_id,username,first_photo,who,what,when,where){

	document.getElementById('datenow_mini_href2').href="javascript:profilePopup('message',"+user_id+");";
	document.getElementById('datenow_mini_href2').innerHTML='Send A Message to '+username;
	document.getElementById('datenow_mini_href2').style.fontWeight='bold';

	document.getElementById('datenow_mini_username').innerHTML=username;
	document.getElementById('datenow_mini_href').href="javascript:profilePopup('view',"+user_id+");";
	document.getElementById('datenow_mini_image').src="http://images.iamfreetonight.com/photos/small_thumb/"+first_photo;
	document.getElementById('datenow_mini_who').innerHTML=who;
	document.getElementById('datenow_mini_what').innerHTML=what;
	document.getElementById('datenow_mini_when').innerHTML=when;
	document.getElementById('datenow_mini_where').innerHTML=where;
	document.getElementById('datenow_mini').style.display='block';
	document.getElementById('datenow_mini').style.top=theevent.clientY+document.body.scrollTop-9;
	document.getElementById('datenow_mini').style.left=theevent.clientX+document.body.scrollLeft-360;
}

function hideNLDateNowMini(){
	document.getElementById('nl_datenow_mini').style.display='none';
}

function showNLDateNowMini(theevent,user_id,username,first_photo,who,what,when,where){
	
	document.getElementById('nl_datenow_mini_href2').href="/register.php";
	document.getElementById('nl_datenow_mini_href2').innerHTML='Send A Message to '+username;
	document.getElementById('nl_datenow_mini_href2').style.fontWeight='bold';	

	document.getElementById('nl_datenow_mini_username').innerHTML=username;
	document.getElementById('nl_datenow_mini_image').src="http://images.iamfreetonight.com/photos/small_thumb/"+first_photo;
	document.getElementById('nl_datenow_mini_who').innerHTML=who;
	document.getElementById('nl_datenow_mini_what').innerHTML=what;
	document.getElementById('nl_datenow_mini_when').innerHTML=when;
	document.getElementById('nl_datenow_mini_where').innerHTML=where;
	document.getElementById('nl_datenow_mini').style.display='block';
	document.getElementById('nl_datenow_mini').style.top=theevent.clientY+document.body.scrollTop-9;
	document.getElementById('nl_datenow_mini').style.left=theevent.clientX+document.body.scrollLeft-360;
}

function hideDateNowMini(){
	document.getElementById('datenow_mini').style.display='none';
}

function doNothing(){
}

function verify_account_delete(){
	if(confirm('Are you sure you want to delete you account forever?\n\nIf you only want to temporarily disable your account,\nyou can hide it by changing your privacy options.')){
		return confirm('In case you accidentally missed it, this can not be undone and will delete your account forever.\nIf you change your mind later, you will have to create a new account from scratch.\n Please click "OK" to delete your account forever, or "Cancel" to stop.');
	}else{
		return false;
	}
}
function alphanumeric(the_string){
	for(var j=0; j<the_string.length; j++){
		var the_char = the_string.charAt(j);
		var ccode = the_char.charCodeAt(0);
		if(!((ccode>47 && ccode<59) || (ccode>64 && ccode<91) || (ccode>96 && ccode<123) || ccode==95)){return false;}
	}
	return true;
}
function checkAvailibilityResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			if(http.responseText=="available"){
				available_username=document.getElementById('username').value;
				document.getElementById('user_availability').innerHTML='';
			}else{
				document.getElementById('user_availability').innerHTML='That username is already taken!<BR>Please try another name.';
				document.getElementById('username').focus();
				available_username='';
			}
		}
	}
}
function checkAvailibity(username){
	if(available_username!=username){
		if(!alphanumeric(document.getElementById('username').value)){
			available_username=document.getElementById('username').value;
			document.getElementById('username').focus();
			document.getElementById('user_availability').innerHTML='Please only use letters, numbers, or underscores<BR>"_" in choosing your IAmFreetonight.com username.';
		}else{
			http.open("GET", "/register.php?mode=AJAX&action=check_username&username="+username, true);
			http.onreadystatechange = checkAvailibilityResponse;
			http.send(null);
		}
	}
}


function updateFlirtsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('flirt_list').innerHTML=http.responseText;
			theheight=document.getElementById('content_table').clientHeight;
			thewidth=document.getElementById('content_table').clientWidth;
			window.resizeTo(thewidth+7,theheight+55);
		}
	}
}
function updateFlirts(flirt_category_id){
	flirt_category_id=encodeURIComponent(flirt_category_id);
	http.open("GET", "/members/view_profile.php?mode=AJAX&action=get_flirts&flirt_category_id="+flirt_category_id, true);
	http.onreadystatechange = updateFlirtsResponse;
	http.send(null);
}

function getHTTPObject(){
	var C=null;
	try{
		C=new ActiveXObject("Msxml2.XMLHTTP")
	}catch(e){
		try{
			C=new ActiveXObject("Microsoft.XMLHTTP")}
		catch(sc){
			C=null
		}
	}
	if(!C &&typeof XMLHttpRequest!="undefined"){
		C=new XMLHttpRequest()
	}
	return C
}
function returnCollege(collegeId,collegeName){
	window.opener.document.getElementById('college_display').value=collegeName;
	window.opener.document.getElementById('college_value').value=collegeId;
	window.opener.focus();
	window.close();
}
function showCollegeQuestions(showOrHide){
	if(showOrHide=="show"){
		document.getElementById('collegeQuestions').style.display='block';
		check_college='yes';
	}else{
		document.getElementById('collegeQuestions').style.display='none';
		check_college='no';
	}
}

function sendToFriend(message_code){
	var encurl=encodeURIComponent(window.location);
	message_code=encodeURIComponent(message_code);
	the_width=500;
	the_height=300;
	the_top=75;
	the_left=300;
	window.open('/send_to_friend.php?message_code='+message_code+'&url='+encurl,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,top='+the_top+',left='+the_left);
}

function memberAgreement(){
	window.open('/member_agreement.php','_blank','width=500,height=400,scrollbars=yes');
}
function checkForm(){
	var requiredMessage='';

	var requiredCollegeMessage='';
	var errorMessage='';
	var fieldName='';

	if(!alphanumeric(document.getElementById('username').value)){
		errorMessage+='Please only use letters, numbers, or underscores\n "_" in choosing your IAmFreetonight.com username.\n\n';
	}

	var fieldsToCheck=new Array("username","toconfirm_password","toconfirm_email","first_name","last_name","city","gender");
	for(var x=0;x<fieldsToCheck.length;x++){
		if(document.getElementById(fieldsToCheck[x]).value==''){
			fieldName=fieldsToCheck[x].replace("toconfirm_","");
			fieldName=fieldName.replace("_"," ");
			requiredMessage+='Please fill out the "'+fieldName+'"  fields.\n';
		}
	}
	
	if(document.getElementById('profile_country').value=='US'){
		if(document.getElementById('state').value==''){
			requiredMessage+='Please fill out the "state" field.\n';
		}
		if(document.getElementById('zip_code').value==''){
			requiredMessage+='Please fill out the "zip code" field.\n';
		}
	}
	if(document.getElementById('profile_country').value=='CA'){
		if(document.getElementById('province').value==''){
			requiredMessage+='Please fill out the "province" field.\n';
		}		
	}
	errorMessage+=requiredMessage;

	if(check_college=="yes"){
		var collegeFieldsToCheck=new Array("college_value");
		for(var y=0;y<collegeFieldsToCheck.length;y++){
			if(document.getElementById(collegeFieldsToCheck[y]).value==''){
				requiredCollegeMessage='Please fill out all college fields.\n';
			}
		}
	}
	errorMessage+=requiredCollegeMessage;

	var verifyFields=new Array("email","password");
	for(var z=0;z<verifyFields.length;z++){
		if(document.getElementById('toconfirm_'+verifyFields[z]).value!=document.getElementById('confirm_'+verifyFields[z]).value){
			errorMessage+='\nThe '+verifyFields[z]+'s you supplied do not match.\n';
		}
	}

	if(!document.getElementById('agreement_confirm').checked){
		errorMessage+='\nPlease confirm that you agree to our member agreement.';
	}

	if(errorMessage!=''){
		alert(errorMessage);
		return false;
	}else{
		return true;
	}

}

function showHideWidget(widget_id,user_id){
	widget_id=encodeURIComponent(widget_id);
	user_id=encodeURIComponent(user_id);
	if(document.getElementById('widget_body_'+widget_id).style.display=="none"){
		document.getElementById('widget_body_'+widget_id).style.display="block";
		document.getElementById('widget_title_'+widget_id).innerHTML="-";
		toggle_value="block";
	}else{
		document.getElementById('widget_body_'+widget_id).style.display="none";
		document.getElementById('widget_title_'+widget_id).innerHTML="+";
		toggle_value="none";
	}
}


function chooseCollege(){
	window.open('/college_select.php','_blank','width=300,height=200,scrollbars=yes');
}
function showHide(element_name){
	if(document.getElementById(element_name+'table').style.display=="none"){
		document.getElementById(element_name+'table').style.display="block";
		document.getElementById(element_name+'show').innerHTML="-";
	}else{
		document.getElementById(element_name+'table').style.display="none";
		document.getElementById(element_name+'show').innerHTML="+";
	}
}
function showHideSingle(hide_element_name,link_element_name,show_text,hide_text){
	if(document.getElementById(hide_element_name).style.display=="none"){
		document.getElementById(link_element_name).innerHTML=hide_text;
		document.getElementById(hide_element_name).style.display="block";
	}else{
		document.getElementById(link_element_name).innerHTML=show_text;	
		document.getElementById(hide_element_name).style.display="none";
	}
}
function showMessage(message_id,already_read){
	if(already_read=="no"){
		http.open("GET", "/members/mailbox.php?mode=AJAX&action=read&message_id="+message_id, true);
		http.onreadystatechange = showMessageResponse;
		http.send(null);
	}else{
		if(document.getElementById('message_'+message_id).style.display=="none"){
			document.getElementById('message_'+message_id).style.display="block";
		}else{
			document.getElementById('message_'+message_id).style.display="none";
		}
	}
}
function showMessageResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			if(document.getElementById('message_'+http.responseText).style.display=="none"){
				document.getElementById('message_'+http.responseText).style.display="block";
			}else{
				document.getElementById('message_'+http.responseText).style.display="none";
			}
		}
	}
}
function searchShow(element_name){
	document.getElementById('datenow_search').style.display='none';
	document.getElementById('people_search').style.display='none';
	document.getElementById('college_search').style.display='none';
	document.getElementById(element_name+'_search').style.display="block";

	document.getElementById('datenow_choice').style.display='none';
	document.getElementById('people_choice').style.display='none';
	document.getElementById('college_choice').style.display='none';
	document.getElementById(element_name+'_choice').style.display="block";
}
function popUp(the_page){
	the_width=700;
	the_height=500;
	the_top=50;
	the_left=100;
	window.open('/generic_page.php?page='+the_page,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,top='+the_top+',left='+the_left);
}
function questionMarkPopup(the_page){
	the_width=500;
	the_height=300;
	the_top=75;
	the_left=300;
	window.open('/members/question_mark.php?page='+the_page,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,top='+the_top+',left='+the_left);
}
function friendsPopup(user_id){
	user_id=encodeURIComponent(user_id);
	the_width=900;
	the_height=660;
	the_top=50;
	the_left=50;
	window.open('/members/view_profile.php?action=view&section=friends&user_id='+user_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=no,top='+the_top+',left='+the_left);
}
function datenowViewPopup(datenow_id){
	datenow_id=encodeURIComponent(datenow_id);
	window.open('/members/datenow_view.php?from=popup&datenow_id='+datenow_id,'_blank','width=500,height=400,scrollbars=yes,top=175,left=275');
}
function datenowDelete(datenow_id){
	datenow_id=encodeURIComponent(datenow_id);
	if(confirm('Are You Sure You Wish To Delete This Date Now?')){
		window.location='/members/datenow_my_schedule.php?action=delete&datenow_id='+datenow_id;
	}
}
function datenowPopup(from,who,what,where,when){
	who=encodeURIComponent(who);

	where=encodeURIComponent(where);
	what=encodeURIComponent(what);
	when=encodeURIComponent(when);
	window.open('/members/datenow_schedule.php?from='+from+'&what='+what+'&when='+when+'&who='+who+'&where='+where,'_blank','width=560,height=400,scrollbars=yes,top=175,left=275');
}
function datenowPrivatePopup(from,what,when,to){
	what=encodeURIComponent(what);
	to=encodeURIComponent(to);
	when=encodeURIComponent(when);
	window.open('/members/datenow_schedule.php?from='+from+'&what='+what+'&when='+when+'&to='+to,'_blank','width=560,height=400,scrollbars=yes,top=175,left=275');
}
function forgotPassword(){
	the_width=500;
	the_height=200;
	the_top=50;
	the_left=150;
	window.open('/forgot_password.php','_blank','width='+the_width+',height='+the_height+',scrollbars=no,top='+the_top+',left='+the_left);
}
function resendVerification(){
	the_width=500;
	the_height=200;
	the_top=50;
	the_left=150;
	window.open('/resend_verification.php','_blank','width='+the_width+',height='+the_height+',scrollbars=no,top='+the_top+',left='+the_left);
}
function changePassword(){
	the_width=500;
	the_height=200;
	the_top=50;
	the_left=150;
	window.open('/members/change_password.php','_blank','width='+the_width+',height='+the_height+',scrollbars=no,top='+the_top+',left='+the_left);
}
function profilePopup(action,user_id){
	user_id=encodeURIComponent(user_id);
	action=encodeURIComponent(action);
	if(action=="view"){
		the_width=900;
		the_height=660;
		the_top=50;
		the_left=50;
	}else if(action=="flirt"){
		the_width=650;
		the_height=200;
		the_top=50;
		the_left=150;
	}else if(action=="message"){
		the_width=750;
		the_height=400;
		the_top=50;
		the_left=150;
	}else{
		the_width=500;
		the_height=200;
		the_top=50;
		the_left=150;
	}
	window.open('/members/view_profile.php?action='+action+'&user_id='+user_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=no,resizable=yes,top='+the_top+',left='+the_left);
}

function replyPopup(user_id,message_id){
	user_id=encodeURIComponent(user_id);
	message_id=encodeURIComponent(message_id);
	the_width=750;
	the_height=400;
	the_top=250;
	the_left=250;
	window.open('/members/view_profile.php?action=message&user_id='+user_id+'&message_id='+message_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=no,resizable=yes,top='+the_top+',left='+the_left);
}

function checkPasswords(){
	if(document.getElementById('password').value!=document.getElementById('new_password').value){
		alert('Both Passwords Must Match!');
		return false;
	}else if(document.getElementById('password').value==''){
		alert('You New Password Must Not Be Blank!');
		return false;	
	}else{
		return true;
	}
}

function profilePopupFromAdmin(action,user_id){
	user_id=encodeURIComponent(user_id);
	action=encodeURIComponent(action);
	if(action=="view"){
		the_width=900;
		the_height=660;
		the_top=50;
		the_left=50;
	}else if(action=="flirt"){
		the_width=650;
		the_height=200;
		the_top=250;
		the_left=250;
	}else{
		the_width=500;
		the_height=200;
		the_top=250;
		the_left=250;
	}
	window.open('/members/view_profile.php?action='+action+'&user_id='+user_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=no,top='+the_top+',left='+the_left);
}
function addUserToInvite(email,id){
	var add_spot=0;

	var break_out="no";
	while(add_spot<10 && break_out=="no"){
		if(document.getElementById('email_'+add_spot).value==''){
			break_out="yes";
		}else{
			add_spot++;
		}

	}
	if(add_spot<10){
		document.getElementById('email_'+add_spot).value=email;
		document.getElementById('result_'+id).style.color="silver";
		document.getElementById('result_'+id).innerHTML=email+":<BR> <B>Added to Invite</B>";
		add_spot++;
	} else {
		alert('You may only add up to 10 friends at once.\n Please hit "submit" to invite the 10 you\'ve selected.');
	}
}
function modifySearch(element_name,new_value){
	document.getElementById('search_'+element_name).value=new_value;
	document.getElementById('search_'+element_name).value;
	document.getElementById('hidden_search').submit();
}
function showWingMen(the_value){
	document.getElementById('nowingmen').style.display='none';
	document.getElementById('1wingman').style.display='none';
	document.getElementById('manywingmen').style.display='none';
	if(the_value=="Single Date"){
		document.getElementById('nowingmen').style.display='block';
	}
	if(the_value=="Double Date"){
		document.getElementById('1wingman').style.display='block';
	}
	if(the_value=="Group Date"){
		document.getElementById('1wingman').style.display='block';
		document.getElementById('manywingmen').style.display='block';
	}
}

function showPublicOptions(check_value){
	if(!check_value){
		document.getElementById('public_options').style.display='none';
	} else {
		document.getElementById('public_options').style.display='block';
	}
}
function switchSection(element_name){
	var sectionArray = new Array("all","basic_information","appearance","interests","essays","friends","prefs","college","posts");
		for(var x=0;x<sectionArray.length;x++){
			document.getElementById(sectionArray[x]+"_tab").setAttribute("background","http://images.iamfreetonight.com/images/folder_tabs_03.gif");
			document.getElementById(sectionArray[x]+"_div").style.display="none";
		}
		document.getElementById(element_name+"_tab").setAttribute("background","http://images.iamfreetonight.com/images/folder_tabs_02.gif");
		document.getElementById(element_name+"_div").style.display="block";
}

function switchPicture(photo_id){
	document.getElementById("large_photo").setAttribute("src","http://images.iamfreetonight.com/photos/large_thumb/"+photo_id);
}

function mailboxSelectAll(){
	var theform=document.getElementById('mailbox_form');
	var number_done=0;
	var to_check;
	for(var x=0;x<theform.elements.length;x++){
		if(theform.elements[x].type=="checkbox"){
		 	if(number_done==0){
		 		to_check= !theform.elements[x].checked;
		 		number_done++;
		 	}
		 	theform.elements[x].checked=to_check;
		}
	}
}