///****************** GENERAL FUNCTIONS ****************

function MM_callJS(jsStr) { //v2.0
 return eval(jsStr)
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}



function makePOSTRequest(url, parameters, functionName) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = functionName;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
}




function open_modal(modal,getVar,getVar2,getVar3) {
	


if (modal == "Help") {
GB_showCenter('Help', '../../../Help_modal.php#' + getVar,400,650);	
}

if (modal == "ExternalSiteBadge_modal") {
GB_showCenter('Badges for your site', '../../../ExternalSiteBadge_modal.php',400,650);	
}

if (modal == "PWReset") {
GB_showCenter('Password Reset', '../../../PasswordReset_modal.php', 300, 350);
}

if (modal == "Delete_comment") {
GB_showCenter('Comments', '../../../Content_modal_delete_comment.php?uid=' + getVar + '&au=' + getVar2,320,400);	
}	

if (modal == "Delete_bookmark") {
GB_showCenter('Bookmarks', '../../../Profile_modal_delete_bookmark.php?uid=' + getVar,300,400);	
}	

if (modal == "Invite") {
GB_showCenter('Invite', '../../../Invite.php', 450, 625);	
}

if (modal == "profile_search_error") {
GB_showCenter('Cannot find this profile', '../../../Profile_search_error.php',300,350);		
}

if (modal == "Profile_create_challenge") {
GB_showCenter('Challenge Friend', '../../../Challenges_modal_create_challenge.php',400,500);	
}

if (modal == "Profile_add_comment") {
GB_showCenter('Box', '../../../Profile_modal_comment.php?profile=' + getVar,330,450);	
}

if (modal == "Profile_visits") {
GB_showCenter('Visitors', '../../../Profile_modal_visits.php?profile=' + getVar, 350, 600);	
}

if (modal == "Profile_change_quote") {
GB_showCenter('Quote / motto', '../../../Profile_modal_quote.php',260,380);	
}

if (modal == "Profile_picture_update") {
GB_showCenter('Update picture', '../../../Profile_modal_picupdate.php',400,730);
}

if (modal == "Profile_edit_detail") {
GB_showCenter('Edit details', '../../../Profile_modal_editdetail.php',400,500);
}

if (modal == "Profile_edit_privacy") {
GB_showCenter('Edit details', '../../../Profile_modal_editdetail.php?t=6',400,500);
}

if (modal == "Profile_edit_friends") {
GB_showCenter('Edit Friends', '../../../Profile_modal_editfriends.php');
}

if (modal == "Profile_new_challenge") {
GB_showCenter('New Challenge', '../../../Challenges_modal_newchallenge_1.php?chaltype=' + getVar,400,600);
}

if (modal == "Profile_skip_challenge") {
GB_showCenter('Skip Challenge', '../../../Challenges_modal_skip.php?name=' + getVar + '&chalid=' + getVar2,300,450);
}

if (modal == "Profile_add_friend") {
GB_showCenter('Add Friend', '../../../Content_modal_addfriend.php?add_friend=' + getVar);
}

if (modal == "Profile_mail_compose") {
GB_showCenter('My Mail', '../../../Profile_modal_compose.php?name=' + getVar,400,700);
}

if (modal == "Profile_new_group") {
if (getVar==2) {
var usethis = document.getElementById("Ngroupname").value;
GB_showCenter('New Group', '../../../Profile_modal_new_group.php?name=' + usethis);
}
else {
GB_showCenter('New Group', '../../../Profile_modal_new_group.php');
}
}

if (modal == "Flag_content") {
GB_showCenter('Flag Content', '../../../Content_modal_fc.php?name=' + getVar + '&chalid=' + getVar2,300,350);
}

if (modal == "Group_Profile_new_challenge") {
	if (getVar2==0) {
GB_showCenter('Group Challenge', '../../../Group_modal_newchallenge_1.php?name=' + getVar,400,600);
	}
	else {
GB_showCenter('Group Challenge', '../../../Group_modal_newchallenge_1.php?name=' + getVar + '&chaltype=' + getVar2,400,600);
	}
}

if (modal == "GroupProfile_invite_friends") {
GB_showCenter('Invite Friends', '../../../Group_modal_invite_friends.php?name=' + getVar,400,900);
}

if (modal == "GroupProfile_add_comment") {
GB_showCenter('Invite Friends', '../../../Group_modal_comment.php?profile=' + getVar,400,500);
}

if (modal == "GroupProfile_mail_administrators") {
	if (getVar2==1) {
GB_showCenter('Group Mail', '../../../Group_modal_mailgroupadmin.php?name=' + getVar + '&joinReq=1',300,350);
	}
	else {
GB_showCenter('Group Mail', '../../../Group_modal_mailgroupadmin.php?name=' + getVar,400,500);
	}
}

if (modal == "Group_skip_challenge") {
GB_showCenter('Skip Challenge', '../../../Group_modal_skip.php?name=' + getVar + '&chalid=' + getVar2,270,450);
}

if (modal == "GroupProfile_leave_group") {
GB_showCenter('Group Mail', '../../../Group_modal_leave_group.php?name=' + getVar,400,600);
}

if (modal == "GroupProfile_create_challenge") {
GB_showCenter('Challenge Group', '../../../Group_modal_create_challenge.php',400,500);	
}

if (modal == "GroupProfile_open_administration") {
if (getVar2==2) {
GB_showCenter('Group Administration', '../../../Group_modal_administrate.php?name=' + getVar + '&action=picupdate',400,600);
}
else if (getVar2==3) {
GB_showCenter('Group Administration', '../../../Group_modal_administrate.php?name=' + getVar + '&action=quote',400,600);
}
else {
GB_showCenter('Group Administration', '../../../Group_modal_administrate.php?name=' + getVar,400,600);
}
}

if (modal == "GroupCC_add_text") {
GB_showCenter('Edit Content', '../../../Group_modal_add_text.php?name=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "GroupCC_add_image") {
GB_showCenter('Edit Content', '../../../Group_modal_add_image.php?name=' + getVar + '&chalid=' + getVar2,400,600);
}


if (modal == "GroupCC_add_video") {
GB_showCenter('Edit Content', '../../../Group_modal_add_video.php?name=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "GroupCC_view_video") {
GB_showCenter('View Content', '../../../Group_modal_view_video.php?name=' + getVar + '&chalid=' + getVar2 + '&vidno=' + getVar3,440,500);
}

if (modal == "GroupCC_add_comment") {
GB_showCenter('Group Content', '../../../GroupCC_modal_comment.php?profile=' + getVar + '&chalid=' + getVar2);
}

if (modal == "GroupCC_archive") {
GB_showCenter('Group Content', '../../../GroupCC_modal_complete.php?profile=' + getVar + '&chalid=' + getVar2 + '&type=a');
}

if (modal == "GroupCC_publish") {
GB_showCenter('Group Content', '../../../GroupCC_modal_complete.php?profile=' + getVar + '&chalid=' + getVar2 + '&type=p',380,500);
}

if (modal == "MyCC_add_image") {
GB_showCenter('Edit Content', '../../../Content_modal_add_image.php?name=' + getVar + '&chalid=' + getVar2,700,900);
}

if (modal == "MyCC_add_text") {
GB_showCenter('Edit Content', '../../../Content_modal_add_text.php?name=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "GroupCC_delete_text") {
GB_showCenter('Edit Content', '../../../Group_modal_delete_text.php?uid=' + getVar + '&au=' + getVar2,200,400);	
}

if (modal == "MyCC_add_video") {
GB_showCenter('Edit Content', '../../../Content_modal_add_video.php?name=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "MyCC_view_video") {
GB_showCenter('View Content', '../../../Content_modal_view_video.php?name=' + getVar + '&chalid=' + getVar2 + '&vidno=' + getVar3,440,500);
}

if (modal == "MyCC_add_comment") {
GB_showCenter('Player Content', '../../../Content_modal_comment.php?profile=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "MyCC_add_friend") {
GB_showCenter('Player Content', '../../../Content_modal_addfriend.php?add_friend=' + getVar);
}

if (modal == "MyCC_complete") {
GB_showCenter('Player Content', '../../../Content_modal_complete.php?profile=' + getVar + '&chalid=' + getVar2,400,600);
}

if (modal == "MyMail_reply") {
GB_showCenter('Reply', '../../../Mail_modal_reply_1.php?ident=' + getVar + '&group=' + getVar2,400,600);
}

if (modal == "MyMail_view") {
GB_showCenter('Reply', '../../../Mail_modal_view.php?ident=' + getVar,400,600);
}

if (modal == "MyMail_add_friend") {
GB_showCenter('MyProfile', '../../../Content_modal_addfriend.php?add_friend=' + getVar,400,500);
}

if (modal == "MyMail_accept_friend") {
GB_showCenter('MyProfile', '../../../Mail_modal_friendaccept.php?accept=' + getVar);
}

if (modal == "MyMail_accept_group") {
GB_showCenter('My Mail', '../../../Mail_modal_groupaccept.php?accept=' + getVar);
}

if (modal == "MyMail_ask_group_to_join") {
GB_showCenter('Groups', '../../../Mail_modal_user_join_request.php?group=' + getVar);
}

if (modal == "MyMail_ask_user_to_join") {
GB_showCenter('Groups', '../../../Mail_modal_group_join_request.php?user=' + getVar);
}

if (modal == "MyMail_accept_community_challenge") {
GB_showCenter('Accept', '../../../Mail_modal_accept_community_challenge.php?chalID=' + getVar);
}



}



function bookmark(page,user,chalid) {
var poststr = "page=" + page + "&user=" + user + "&chalid=" + chalid;
makePOSTRequest('./php/Bookmark_script.php', poststr, bookmark_ready_state);	
}

function bookmark_ready_state() {
///Checks completion
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {

			if (http_request.responseText==1) {
			document.getElementById("bookmarkOK").style.display='inline';
			document.getElementById("bookmarkREQUEST").style.display='none';
			}
			else {
				alert(http_request.responseText);
			alert("umm.. this doesn't appear to be working right now... we'll fix it soon!");	
			}
			
			
		}
	}
	

}




///****************** MAIN HEADER ****************

function reset_password(a) {
GB_showCenter('Reset Your Password', '../../../PasswordReset_modal.php');
}





///****************** MAIN FOOTER ****************

function ContactFrm_validate_email() {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById('sndEmail').value;
   if(reg.test(address) == false) {
      return false;
   }
}


function ContactFrm_ready_state() {


	///Whilst processing
	if (http_request.readyState != 4) {
		document.getElementById('MessageProgress').innerHTML = '<img src="/images/global/loading.gif" alt="Loading..." title="Sending Email" />';
	}
	
	///Checks completion
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
		
		
			if (http_request.responseText==1) {
			document.getElementById('MessageProgress').innerHTML = '<p class="cMessage1">There seems to have been a problem with field entry, try sending again</p>';
			}
			if (http_request.responseText==2) {
			document.getElementById('MessageProgress').innerHTML = '<p class="cMessage1">Please check your email address and try sending again</p>';
			}
			if (http_request.responseText==3) {
			document.getElementById('MessageProgress').innerHTML = '<p class="cMessage2">Thanks, we have received your message and will be in touch</p>';
            			
			//reset form if successful
			document.getElementById('sndName').value='';
			document.getElementById('sndEmail').value='';
			document.getElementById('sndUsername').value='';
			document.getElementById('sndMessage').value='';
			}
            
			
		} else {
            document.getElementById('MessageProgress').innerHTML = '<p class="cMessage1">There seems to have been a problem, try sending again</p>';
		}
	}
}


function ContactFrm_validate_fields() {

var frmEl = document.getElementById('cForm');
var sndName = document.getElementById('sndName');
var sndEmail = document.getElementById('sndEmail');
var sndUsername = document.getElementById('sndUsername');
var sndType = document.getElementById('sndType');
var sndMessage = document.getElementById('sndMessage');


//Resets error colours and checking variable
var okToSend = 1;
sndName.style.border="2px solid #CCCCCC";
sndName.style.background="#FFFFFF";
sndEmail.style.border="2px solid #CCCCCC";
sndEmail.style.background="#FFFFFF";
sndUsername.style.border="2px solid #CCCCCC";
sndUsername.style.background="#FFFFFF";
sndType.style.border="2px solid #CCCCCC";
sndType.style.background="#FFFFFF";
sndMessage.style.border="2px solid #CCCCCC";
sndMessage.style.background="#FFFFFF";


//Error checks
if (sndName.value=="") {
sndName.style.background="#F3D9DF";
okToSend=0;
}
if (ContactFrm_validate_email()==false) {
sndEmail.style.background="#F3D9DF";
okToSend=0;
}
if (sndEmail.value=="") {
sndEmail.style.background="#F3D9DF";
okToSend=0;
}
if (sndMessage.value=="") {
sndMessage.style.background="#F3D9DF";
okToSend=0;
}


///AJAX and form submission
if (okToSend==1) {
	
	//dropdown value code
	var TypeIndex  = sndType.selectedIndex
    var TypeValue = sndType.options[TypeIndex].value


var poststr = "sndName=" + sndName.value + "&sndEmail=" + sndEmail.value + "&sndUsername=" + sndUsername.value + "&sndType=" + TypeValue + "&sndMessage=" + sndMessage.value;
makePOSTRequest('./php/ContactFrm_script.php', poststr, ContactFrm_ready_state);

<!--AJAX and submission End-->
}

<!--Function End-->
}

//////******************************** Home page ******************************

function HomeHelp(getVar) {
///This handles the output of the NewUser modal
if (getVar==1) {
window.location="./MyProfile.php?pic=1";
}
if (getVar==2) {
window.location="./FAQ.php";
}
if (getVar==3) {
window.location="./MyProfile.php";
}
if (getVar==4) {
window.location="./MyMail.php";
}

}



