/**
 * Adodis Blog package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

function blockSubmit(){
	document.adminForm.submit();
}

//For adding vedio url from popup
function addVideo(){
	var url 		= document.getElementById('video').value;
	var theurl		= document.getElementById('video');
	if( theurl != null ) {
		var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
		if( theurl.value != '' ) {
		     if (tomatch.test(theurl.value)) {
		     } else {
		     	document.getElementById('video').style.border 			= "1px solid #FF0000";
				document.getElementById('video').focus();
				document.getElementById("video").title 					="Please Enter valid URL";
				return;
		     }
		}
	}
	var prefix_url 	= '<p>';
	var suffix_url 	= '</p>';
	url 			= prefix_url+url+suffix_url;
	window.parent.addIntoEditor(url);
}

//For adding vedio url to Editor
function addIntoEditor(url) {
	jInsertEditorText(url, 'jform_content');
	window.parent.SqueezeBox.close();
}

function readMore() {

	var totalcmt 		= document.getElementById('totalcmt').value;
	var totalcmt_dis 	= document.getElementById('totalcmt_dis').value;
	total				= parseInt(totalcmt);
	value				= parseInt(totalcmt_dis);
	var next 			= value+5;

	for(i=5;i<next;i++){
		if(i>=total)
			break;
		removeClass(document.getElementById("adodis-blog_cmt"+i), "adodis-blog_blockdata");
		addClass(document.getElementById("adodis-blog_cmt"+i), "adodis-blog_unblockdata");
	}
	document.getElementById('totalcmt_dis').value = next;
	if(next>=total)
		addClass(document.getElementById("adodis-blog_readmore_link"), "adodis-blog_blockdata");
}

//Like Dislike Comment starts
function likedislikes(value,likes,ival)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest 		= new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest 	= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay                                 			=  ajaxRequest.responseText;
			var values 													= new Array();
			values     													= ajaxDisplay.split(',');

			document.getElementById( 'displikes_'+ival ).style.display 	= "block";
			document.getElementById( 'displikes_'+ival ).innerHTML  	=  values[0];
			if(values[1]!='none'){
				document.getElementById( 'total_like_'+ival ).innerHTML =  values[1];
			}
		}
	}

	var path	= document.getElementById('sitepath').value;
	var url		= 'index.php?option=com_adodisblog&view=blog&task=Comment.updatelikes&id='+value+'&likeid='+likes+'&ival='+ival;
	ajaxRequest.open("GET", path+url, true);
	ajaxRequest.send(null);
}
//Like Dislike Comment ends


//Like Dislike Blog starts
function likeDislikesBlog(value,likes,ival,liketxt,disliketxt)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest 		= new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest 	= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay                                 				=  ajaxRequest.responseText;
			var values 														= new Array();
			values     														= ajaxDisplay.split(',');
			if(values[1]=='none'){
				document.getElementById( 'displikes_b_'+ival ).style.display 	= "block";
				document.getElementById( 'displikes_b_'+ival ).innerHTML  	=  values[0];
			} else {
				if(values[2]-values[3]>0) {
					values[1]='+'+values[1];
				}

				document.getElementById( 'total_likes_b_'+ival ).innerHTML 	= values[2];
				document.getElementById( 'total_dislikes_b_'+ival ).innerHTML = values[3]  ;
				document.getElementById( 'total_like_b_'+ival ).innerHTML 	=  values[1];
			}
		}
	}

	var path	= document.getElementById('sitepath').value;
	var url		= 'index.php?option=com_adodisblog&view=blogs&task=blog.updateLikesBlog&id='+value+'&likeid='+likes+'&ival='+ival+'&liketxt='+liketxt+'&disliketxt='+disliketxt;
	ajaxRequest.open("GET", path+url, true);
	ajaxRequest.send(null);
}
//Like Dislike Blog ends