
/********************************************************************
 * Show Comments
 *******************************************************************/
 
function showComments(direction) {
		
		if($('youtube_logo').style.display == 'none') {			
				setTimeout("showLogo()",600);
				
		} else {
			$('youtube_logo').style.display = 'none'; 
		}
		
		new Effect.toggle('listing_comments','BLIND',{ duration: .4 })
	

}
 

function showLogo() {
		$('youtube_logo').style.display = 'block'; 	
}
 
 
 /********************************************************************
 * Comments
 *******************************************************************/

function loadComments () {
	new Effect.BlindDown('video_listings', {duration:0.3, delay:.1});
}

function toggleComments(direction) {
	
		
	switch(direction){
		case 'show':
		$('youtube_logo').style.display = 'none'; 
		$('listing_comments').style.display = 'none';
		new  Effect.BlindUp('video_info', {duration:0.5});
		new Effect.BlindDown('add_comment', {duration:0.2, delay:.5});
		//new Effect.Move ('video_listings',{ x: 310, y: 0, mode: 'relative',duration:.5});
		//new Effect.Move ('video_listings',{ x: 310, y: 0, mode: 'relative',duration:.5});
 		break;
		
		case 'hide':
		new  Effect.BlindUp('add_comment', {duration:0.5});
		new Effect.BlindDown('video_info', {duration:0.2, delay:.5});
		setTimeout("showLogo()",800);
		
		break;
	}
 
 
 }
 
function saveComments() {
	
	var post_id = $('post_id').value;
	var vid = 0;
	var url    = 'ajax/save_comments.php';
	$('comment_content').style.display = 'none';
	var comment_pars = Form.serialize('add_comment_form');
	var rand   = Math.random(9999);
	var pars   = 'post_id=' + post_id + '&rand=' + rand + '&' + comment_pars;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,onLoading: showLoad(), onComplete: showResponse} );
			
}

function showResponse (originalRequest) 
{
	$('saving_comments').style.display = 'none';
	$('add_comment_response').style.display = 'block';
	$('add_comment_response').innerHTML = originalRequest.responseText;
	$('your_comments').value = '';
	setTimeout("cleanComments()",8000);
}

function showLoad () {
	
	$('saving_comments').style.display = 'block';
	
	}

 function cleanComments() {
	$('add_comment_response').style.display = 'none';
    $('comment_content').style.display = 'block';
 	
 }
 
 
 
 /********************************************************************
 * Validate 
 *******************************************************************/
 
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Your email appears to be invalid")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Your email appears to be invalid")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Your email appears to be invalid")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Your email appears to be invalid")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Your email appears to be invalid")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Your email appears to be invalid")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Your email appears to be invalid")
		    return false
		 }

 		 return true					
	}
	
	
  
function checkComments() {
	var errormessage = "The following errors have occured:\n\r\n";
	var noerror = 1;

	// --- title ---
	
	var display_name =document.getElementById("display_name");
		if (display_name.value == "" || display_name.value == " ") {
			errormessage += "Please enter your display name \r\n";
			noerror = 0;
		}
		
	var email =document.getElementById("email");
	if (echeck(email.value) == false) {
		errormessage += "There is a problem with the email you entered \r\n";
		noerror = 0;
	}
	
	var your_comments =document.getElementById("your_comments");
		if (your_comments.value == "" || your_comments.value == " ") {
			errormessage += "Please enter a comment \r\n";
			noerror = 0;
		}
		
    // --- check if errors occurred ---
	if (noerror == 0) {
		alert(errormessage);
		return false;
	}
	
	
	else { 
	
	saveComments();
	
	 }
}



