// adding a new comment
function commentAdd(strID){
	//Get the content from the form
	if(document.layers){
		//NN4+
		var strCommentText = document.layers["commentText"].value;
	}else if(document.getElementById){
		//gecko(NN6) + IE 5+
		var strCommentText = document.getElementById("commentText").value;
	}else if(document.all){
		// IE 4
		var strCommentText = document.all["commentText"].value;
	}
	new ajax('includes/addComment.php',{postBody:'strID='+strID+'&strComment='+strCommentText, onComplete: showResponse, update: 'commentContent'}).request();
	
	function showResponse(response){

	};
};
//login function
function loginSubmit(){
	var userName = document.frmLogin.username.value;
	var passWord = document.frmLogin.password.value;
	
	if(userName == '' || passWord == ''){
		alert('Please make sure you enter a username and password to login');
	}else{
		new ajax('includes/loginuser.php',{postBody:'u='+userName+'&p='+passWord, onComplete: showResponse}).request();
	}
	function showResponse(response){
		if(response == 'fail'){
			alert('Login Failed - Please try again.');			
		}else{
			//Get the content from the form
			if(document.layers){
				//NN4+
				document.layers["frmErrorLogin"].innerHTML =response;
			}else if(document.getElementById){
				//gecko(NN6) + IE 5+
				document.getElementById("frmErrorLogin").innerHTML =response;
			}else if(document.all){
				// IE 4
				document.all["frmErrorLogin"].innerHTML = response;
			}	
		}

	}
};
function showCommentForm(){
			//Get the content from the form
			if(document.layers){
				//NN4+
				document.layers["showForm"].style.display ='block';
			}else if(document.getElementById){
				//gecko(NN6) + IE 5+
				document.getElementById("showForm").style.display ='block';
			}else if(document.all){
				// IE 4
				document.all["showForm"].style.display = 'block';
			}	
};
function reportComment(){
	alert('Thanks for informing us of this post. We will check it out.');
};
//login function
function registerSubmit(){
	var email = document.frmSignUp.email.value;
	var displayName = document.frmSignUp.displayName.value;
	var password = document.frmSignUp.password.value;
	var firstname = document.frmSignUp.firstname.value;
	var surname = document.frmSignUp.surname.value;
	var checkbox = document.frmSignUp.checkbox.checked;
	if(email == '' || displayName == '' || password == '' || firstname == '' || surname == ''){
		alert('Please fill in all the fields below to signup');
	}else{
		new ajax('includes/signupuser.php',{postBody:'email='+email+'&displayName='+displayName+'&password='+password+'&firstname='+firstname+'&surname='+surname+'&checkbox='+checkbox, onComplete: showResponse}).request();
	}
	function showResponse(response){
		if(response == 'fail'){
			var strFail = '<p class="error">Signup failed - This is likely to be due to another user using the same email address, please correct and try again.</p>';
			//failed
			if(document.layers){
				//NN4+
				document.layers["frmError"].innerHTML =strFail;
			}else if(document.getElementById){
				//gecko(NN6) + IE 5+
				document.getElementById("frmError").innerHTML =strFail;
			}else if(document.all){
				// IE 4
				document.all["frmError"].innerHTML = strFail;
			}			
		}else if(response == 'video'){
			var strSuccess = '<p>Thanks for registering. You can now upload your video below. Please note the video must be an avi, mpeg, mov, wmv or flv to upload successfully</p>';
		  		strSuccess += '<div id="frmVideo"></div>';
		  		strSuccess += '<p>'
          		strSuccess += '<form action="" method="post" enctype="multipart/form-data" name="frmVideoUpload">'
			  	strSuccess += '<label for="email" class="hide">Video Title:</label>'
		    	strSuccess += '<input type="text" name="title" id="title" class="input" />'	 
			  	strSuccess += '<label for="text" class="hide">Description:</label>'
			  	strSuccess += '<input type="text" name="description" id="description" class="input" />'
			  	strSuccess += '<label for="password" class="hide">Video to upload:</label>'
			  	strSuccess += '<input type="file" name="file" class="input"/>'
			  	strSuccess += '<a href="javascript:videoUpload();"><img src="images/but-upload.gif" name="btnLogin" width="85" height="26" border="0" id="btnLogin"/></a> '    
			  	strSuccess += '<br />'
		  		strSuccess += '</form>'
         		strSuccess += '</p>';
			//Get the content from the form
			if(document.layers){
				//NN4+
				document.layers["contentMid"].innerHTML =strSuccess;
			}else if(document.getElementById){
				//gecko(NN6) + IE 5+
				document.getElementById("contentMid").innerHTML =strSuccess;
			}else if(document.all){
				// IE 4
				document.all["contentMid"].innerHTML = strSuccess;
			}	
		}else{
			var strSuccess = '<p>Thanks for registering. You now have full access to all the features of the site, such as;</p>';
				strSuccess += '<ul><li>Upload Videos</li><li>Comment on Videos</li><li>Add videos to your favourites</li><li>Rate Videos</li><li>View your video stats</li></ul>';
			//Get the content from the form
			if(document.layers){
				//NN4+
				document.layers["contentMid"].innerHTML =strSuccess;
			}else if(document.getElementById){
				//gecko(NN6) + IE 5+
				document.getElementById("contentMid").innerHTML =strSuccess;
			}else if(document.all){
				// IE 4
				document.all["contentMid"].innerHTML = strSuccess;
			}			
		}

	}
};
//search submit
function searchSubmit(){
	var keywords = document.frmSearch.keywords.value;
	if(keywords == ''){
		alert('Please fill in your search criteria');
	}
};