function checkUsernameAvailability()
{
 
	username = document.getElementById("username").value;
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="checkUsername.php";
    var parameters = "u="+username+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    availability = xmlhttp.responseText.replace(/^\s+|\s+$/g, "");

	if(availability == "false")
	{
	 	document.getElementById("usernameError").innerHTML = "Username not available";
		document.getElementById("usernameError").style.display = "block";	
		
		return false;	
	}
	else
	{
		return true;	
	}
}

function validateEmailAddress()
{
 	email = encodeURI(document.getElementById("email1").value);
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="checkEmail.php";
    var parameters = "e="+email+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    availability = xmlhttp.responseText.replace(/^\s+|\s+$/g, "");

	if(availability == "false")
	{
	 	document.getElementById("email1Error").innerHTML = "Email already registered";
		document.getElementById("email1Error").style.display = "block";	
		
		return false;	
	}
	else
	{
		return true;	
	}
}


function validateRegistrationForm()
{
 	var returnVal = true;

	document.getElementById("usernameError").innerHTML = "*";
	document.getElementById("usernameError").style.display = "none";
	document.getElementById("email1Error").style.display = "none";
	document.getElementById("email2Error").style.display = "none";
	document.getElementById("passwordError").style.display = "none";
	document.getElementById("password2Error").style.display = "none";
	document.getElementById("termsError").style.display = "none";
	document.getElementById("sourceError").style.display = "none";
	
	
	if(document.getElementById("username").value == "")
	{
		document.getElementById("usernameError").style.display = "block";			
		returnVal = false;
	}
	if(returnVal == true)
	{
		var available = checkUsernameAvailability();	
		returnVal = available;
	}

	if(document.getElementById("email1").value == "")
	{
 	  	document.getElementById("email1Error").innerHTML = "*";
		document.getElementById("email1Error").style.display = "block";			
		returnVal = false;
	}

	if(document.getElementById("email2").value == "")
	{
		document.getElementById("email2Error").style.display = "block";	
		returnVal = false;
	}
	if(returnVal == true)
	{
		returnVal = validateEmailAddress();
	}
	if(document.getElementById("email2").value != document.getElementById("email1").value)
	{
	  	document.getElementById("email1Error").innerHTML = "*";
		document.getElementById("email1Error").style.display = "block";		
		document.getElementById("email2Error").style.display = "block";		
		returnVal = false;
	}
	
	if(document.getElementById("password").value == "")
	{
		document.getElementById("passwordError").style.display = "block";	
		returnVal = false;
	}

	if(document.getElementById("password2").value == "")
	{
		document.getElementById("password2Error").style.display = "block";	
		returnVal = false;
	}
	
	if(document.getElementById("password2").value != document.getElementById("password").value)
	{
		document.getElementById("passwordError").style.display = "block";	
		document.getElementById("password2Error").style.display = "block";	
		returnVal = false;
	}

	if(document.registerForm.terms.checked == false)
	{
		document.getElementById("termsError").style.display = "block";		
		returnVal = false;
	}

	if(document.registerForm.cboHeard.selectedIndex == 0)
	{
		document.getElementById("sourceError").style.display = "block";		
		returnVal = false;
	}

	return returnVal;
}

function showControlPanelElement(theDiv)
{
	document.getElementById("details").style.display = "none";
	document.getElementById("avatar").style.display = "none";
	document.getElementById("signature").style.display = "none";
	document.getElementById("changePassword").style.display = "none";	

	document.getElementById(theDiv).style.display = "block";	

	document.getElementById("detailsTab").className = "tabOff";
	document.getElementById("avatarTab").className = "tabOff";
	document.getElementById("signatureTab").className = "tabOff";
	document.getElementById("changePasswordTab").className = "tabOff";	

	document.getElementById(theDiv+"Tab").className = "tabOn";	

//	Set_Cookie( 'controlPanel', 'test', '', '/', '', '' );	
//	expire.setTime(today.getTime() + 3600000*24*nDays);

//	document.cookie = "controlPanel="+escape(theDiv)+ ";expires="+expire.toGMTString();

}

function validatePasswordChange()
{
 	var oldPassword = document.getElementById("oldPassword").value;
	var password = document.getElementById("password1").value;
 	var password2 = document.getElementById("password2").value;
 	 
 	document.getElementById("oldPasswordError").style.display = "none";
 	document.getElementById("password1Error").style.display = "none";
	document.getElementById("password2Error").style.display = "none";	   	 

	var returnVal = true;	
 	if(oldPassword == "")
 	{
 	 	document.getElementById("oldPasswordError").style.display = "block";
 	 	document.getElementById("oldPasswordError").innerHTML = "You must enter your old password";
		returnVal = false;
	}

	if(password == "")
	{

		document.getElementById("password1Error").style.display = "block";
 	 	document.getElementById("password1Error").innerHTML = "You must enter a new password ";
		returnVal = false;

	}

	if(password2 == "")
	{
		document.getElementById("password2Error").style.display = "block";
 	 	document.getElementById("password2Error").innerHTML = "You must confirm your new password ";
		returnVal = false;

	}
	
	if(password != "" && password2 != "" && password != password2)
 	{
 	 	document.getElementById("password1Error").style.display = "block";
 	 	document.getElementById("password1Error").innerHTML = "< Passwords do not match";
 	 	document.getElementById("password2Error").style.display = "block";
 	 	document.getElementById("password2Error").innerHTML = "< ";

		returnVal = false;
	}
	
	return returnVal;
}

function showpostnote()
{
	showFader();
 //	var windowWidth = document.documentElement.clientHeight;
//	var windowHeight = document.documentElement.clientWidth; 
	
//	middle = windowHeight / 2;
//	center = windowWidth / 2;

//	var left = Math.round(center);
//	var top = Math.round(middle);
	
//	document.getElementById('postnote').style.display = "block";	
//	document.getElementById('postnote').style.left = left+"px";	
//	document.getElementById('postnote').style.top = top+"px";		

	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }
    
    var indicatorWidth = 540; 
    var indicatorHeight = 190; 
    var left = (availWidth/2) - (indicatorWidth/2); 
    var top = (availHeight/2) - (indicatorHeight/2); 

    var element = document.getElementById('postnote'); 
    element.style.border="10px solid #fbdf5b"; 
    element.style.background="#ffffff"; 
    element.style.position="absolute"; 
    element.style.zIndex="999"; 
    element.style.top=top+"px"; 
    element.style.left=left+"px"; 
    element.style.display="block";
    element.style.position="fixed";
}

function showFader()
{
	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }	
    var element = document.getElementById('fader'); 
    element.style.border="0px"; 
    element.style.background="black"; 
    element.style.position="absolute"; 
    element.style.zIndex="900"; 
//    element.style.top=top+"px"; 
//    element.style.left=left+"px"; 
    element.style.height = availHeight+"px";
    element.style.width = availWidth+"px";
    element.style.display="block";
    element.style.position="fixed";

}

function closePost()
{
	document.getElementById('postnote').style.display = "none";
	document.getElementById('fader').style.display = "none";
}

function GetXmlHttpObject()
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function savepost()
{
	var text =  tinyMCE.get('homepost').getContent();
	var dashboard = document.getElementById('dashboardOwner').value;

	var key = document.getElementById('key').value;
	
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="savepost.php";
    var parameters = "post="+text+"&dash="+dashboard+"&key="+key+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("addpost").innerHTML=xmlhttp.responseText;

	location.reload(true);
}

function showCommentBox(ForumID)
{
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="showComment.php";
    var parameters = "forum="+ForumID+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("comment"+ForumID).innerHTML=xmlhttp.responseText;
	//location.reload(true);
}

function saveComment(ForumID)
{
 	var comment = document.getElementById('commentTextarea'+ForumID).value;

    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="saveComment.php";

    var parameters = "comment="+comment+"&forum="+ForumID+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("comment"+ForumID).innerHTML=xmlhttp.responseText;
	location.reload(true);

}

function login(page)
{
	var username = document.getElementById("txtUsername").value;
	var password = document.getElementById("txtPassword").value;
	
	var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
	if(page == 'h')
	{
	    var url="Member/login.php";	
	}
	else
	{
	    var url="login.php";		
	}

    var parameters = "u="+username+"&p="+password+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("loginForm").innerHTML=xmlhttp.responseText;
	
	if(xmlhttp.responseText.length == 2 || xmlhttp.responseText.length == 1)
	{
		location.reload(true);	

			
	}
}

function showMenu(menu)
{
	document.getElemenyById("menu1").style.display = "block";
}

function sendBuddyRequest(friendID)
{	
	var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
	    var url="sendBuddyRequest.php";	

    var parameters = "u="+friendID+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    //document.getElementById("loginForm").innerHTML=xmlhttp.responseText;
//	location.reload(true);
	alert(xmlhttp.responseText);
}

function showReplyForm()
{
//	document.getElementById('showFriendsWishList').style.display = "none";
	document.getElementById('messageReply').style.display = "block";

	Spry.Effect.Blind('messageReply', {duration: 1000, from:  '1px', to:  '200px', toggle: false});
}

function cancelReply()
{

	Spry.Effect.Blind('messageReply', {duration: 1000, from:  '200px', to:  '0px', toggle: false});
	document.getElementById('messageReply').style.display = "none";

}

function ValidateGift()
{
	var emailID=document.getElementById('Email').value;

	returnVal = "true";
	if(document.getElementById('BusName').value=="") 
	{
		document.getElementById('BusNameError').style.display = 'block';
		returnVal = false;
	}
	else
	{
		document.getElementById('BusNameError').style.display = 'none';
	}

	if(document.getElementById('Address').value=="") 
	{
		document.getElementById('AddressError').style.display = 'block';
		returnVal = false;
	}
	else	
	{
		document.getElementById('AddressError').style.display = 'none';
	}

	if(document.getElementById('Postcode').value=="") 
	{
		document.getElementById('PostcodeError').style.display = 'block';
		returnVal = false;
	}
	else
	{
		document.getElementById('PostcodeError').style.display = 'none';
	}

	if ((document.getElementById('Email').value==null)||(document.getElementById('Email').value==""))
	{
		document.getElementById('EmailError').style.display = 'block';
		returnVal = false;
	}
	else
	{
		document.getElementById('EmailError').style.display = 'none';
	}
	
	if ((document.getElementById('BusContact').value==null)||(document.getElementById('BusContact').value==""))
	{
		document.getElementById('BusContactError').style.display = 'block';
		returnVal = false;
	}	
	else
	{
		document.getElementById('BusContactError').style.display = 'none';
	}
	
 	return returnVal;
}

