// JavaScript Document

  /*
 	Eg: SelectDropDown("value",document.addEmployement.fromMonth -- Element Name); 
 */
 function SelectDropDown(selectItem,listBox) {

  var intIndex = 0;
  var SelectList = listBox;
  for( intIndex = 0; intIndex < SelectList.options.length; intIndex++ ) {
	 
		if( SelectList.options[intIndex].value == selectItem ) {
			SelectList.selectedIndex = intIndex;
			break;
		}
  }    
}
/* *** START ***Ajax more info code*/
var lastid=0;
var flip=true;
function showDetails(id,type)
{
	var poststr='id='+id+'&type='+type;
	if( lastid!= 0 && lastid != id) {
		$('#span_'+lastid).hide('slow'); flip=true;
	}

	if(flip == true) {
		$('#span_'+id).show();
		$('#span_'+id).html('<br><img src="/images/loadingAjax.gif" />')
		$('#a_'+id).addClass('commonboldlink11 grey');
		$.getJSON("/utilities/utility/article-innovation/",poststr, function(data) {
		  $('#span_'+id).html(data.rows.description);  
		} );
	 
		flip=false;
	} else {
		flip = true; 
		$('#span_'+lastid).hide('slow');
	}
	lastid=id;
	
	
	return false;
}
function hidebox(id)
{
	flip=true;//$('#a_'+id).addClass('commonlink11 grey');
	$('#span_'+id).hide('slow');
	return false;
}
/* *** END ***Ajax more info code*/
/* *** START ***Pagination code*/
function setPagination(count,topId,downId,topDet,botDet)
{
	//alert(count);
	var perPage = pagination['resultsPerPage'];
	
	if( parseInt(count) > 0 && parseInt(count) > parseInt(perPage) ){
			
		if(topId!=''){
			$('#'+topId).html(pagination['pager']);
		}
		if(downId!=''){
			$('#'+downId).html(pagination['pager']);
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
	else   {
		if(topId!=''){
			$('#'+topId).html('');
		}
		if(downId!=''){
			$('#'+downId).html('');
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
}
function ajaxPager(page)
{
	 
	var perPage = pagination['resultsPerPage'];
	//Eg: var url = '/article/prediction/pagerlist/${article/id}/' + page + '/' + perPage; 
	var url = requestUrl + page +  '/' + perPage;
	reg = /\s+/;
	url = url.replace(reg,'-');
	
	//Eg :  var Params='category=' + $('#prediction_type').val();
	$.getJSON(url,Params, function(data) {
		  $('#listContent').html(data.output);		 
	      pagination['pages'] = data.pages;
	      pagination['pager'] = data.pager;
	      pagination['currentPage'] = data.currentPage;
		  pagination['resultsDetails'] = data.resultsDetails;
		  setPagination(data.resultsCount,'topPagerId','downPagerId',"topdet","botdet"); 
		} );
	 	
}
/* *** END *** Pagination code*/
/* *** START ***Comments Display and Pagination code*/
function sortingBy(contenttype,bid,pagesize,page,field,order,actionname,urlp)
	{
		
		
		
        if(actionname ==  undefined )
			urlPath = urlp+"index/";
		else
			urlPath = urlp+actionname+"";
		$.ajax({
		type: "POST",
		url: urlPath,
		data: "itemId="+bid+"&page="+page+"&pagesize="+pagesize+"&field="+field,
		success: function(msg){
			$('#postedComments').html(msg);
		}
		});
		
		
	}
/* *** END ***Comments Display and Pagination code*/
function validateComment(textId)
{
	if(lg == true) {
		if($.trim($("#"+textId).val())=='')
		{
			alert('Please enter a comment');
			$("#"+textId).focus();
			return false;
		}
	} else {
		if(confirm('You need to be logged in to Post a Comment.')) {
			window.location = "/utilities/utility/trackback?url="+encodeURI(window.location.toString());
			
		}
		return false;
	}	
}
function SelectOptionInList(selectItem,listBox) {

  var intIndex = 0;
  var SelectList = listBox;
  for( intIndex = 0; intIndex < SelectList.options.length; intIndex++ ) {
		if( SelectList.options[intIndex].value == selectItem ) {
			SelectList.selectedIndex = intIndex;
			break;
		}
  }    
}

function showShareBox(url)
{
	if(lg == true) {
		location.href=url;
	} else {
		if(confirm('You need to be logged in to Share this.')) 
			window.location = '/utilities/utility/trackback';
	}
}
function focusc(key)
{
	if( key.value == key.title )
		key.value = '';
}
function blurc(key)
{
	if( key.value == '')
		key.value = key.title; 
}
function validateSearchform(key,id)
{
	key = document.getElementById(key);
	if( key.value == '' || key.value == key.title ){
		alert('Please enter your search word');
		return false;
	}
	else 
		$("#"+id).submit();
}
function addBookmark(){
	var title =  document.title;
	var url = location.href;
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
	else 
		alert('You need to press Command/Cmd + D to bookmark our site.');
}

function textAreaLimit( field, maxlimit ) {
  var fieldValue = document.getElementById(field).value;
  if ( fieldValue.length > maxlimit )
  {
    var fieldValue1 = fieldValue.substring( 0, maxlimit );
    document.getElementById(field).value=fieldValue1;
  }
  
}


function cancelAction(tar)
	{
		//if(confirm('You will loose all the data, Are You Sure To Continue?'))
			window.location = tar;
	}

function showPreviewAdmin(titvar,descvar)
{
	var fckcontent = FCKeditorAPI.GetInstance(descvar).GetXHTML();
	document.getElementById('popupContact').style.display = '';
	document.getElementById('backgroundPopup').style.display = '';
	document.getElementById('popupContact').innerHTML = '<a id="popupContactClose" onclick="hidePop()">x</a><h1>'+document.getElementById(titvar).value+'</h1><p id="contactArea">'+fckcontent+'</p>';
}

function hidePop()
{
	document.getElementById('popupContact').style.display = 'none';
	document.getElementById('backgroundPopup').style.display = 'none';
}

//Printing Page 
	function openPrint(bid,type)
	{
		window.open('/blog/index/print?id='+bid+'&type='+type);
	}
//Email Function 
function getEmail(bid,type)
	{
		if(lg == true)
		{
			window.location = '/sendemail?id='+bid+'&type='+type;
		} else {
		if(confirm('You need to be logged in to Send Email.')) {
			window.location = "/utilities/utility/trackback?url="+encodeURI(window.location.toString());
		}
		}
	}

//Email Function 
function getEmail(bid,type)
	{
		  
			window.location = '/sendemail?id='+bid+'&type='+type;
		
		
	}


function rate(type,id)
{  
	var cname = 'voting_'+id;
	
	var cval = getCookie(cname);
	if(cval == 1) {
	   alert('You have already voted');		
	} else {
		setCookie(cname,1,1)
		$.ajax({
			type: "POST",
			url: "/blogs/comments/voting/",
			data: "type="+type+"&id="+id,
			success: function(msg){ 
			//	$("#rate").html(msg);	
			    arr = msg.split("##");	
				//alert(arr[2]);
				document.getElementById(arr[1]).innerHTML=arr[0];				
				//alert(arr[0])
				alert('You have voted successfully');
			}
			
			});
	}
}
	/*function rate(type,id)
	{
		
		$.ajax({
			type: "POST",
			url: "/blogs/comments/voting/",
			data: "type="+type+"&id="+id,
			success: function(msg){
				arr = msg.split("##");	
				//alert(arr[1]);
				document.getElementById(arr[2]).innerHTML=arr[1];				
				alert(arr[0]);
			}
			
			});
	
	}*/

//Printing Page 
	function openPrint(bid,type)
	{
		window.open('/blogs/index/print?id='+bid+'&type='+type);
	}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}


function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function pages(contenttype,bid,pagesize,page,field,order,actionname,urlp)
	{
		//alert(order);
		//alert(document.getElementById('order').value);
		//var fieldorder='ASC',urlPath; 
		if(order == null) {
			document.getElementById('orderField').value = field;
	
			if(document.getElementById('order').value == 'ASC') {
				document.getElementById('order').value = 'DESC';
				fieldorder = document.getElementById('order').value ;
			}else {
				document.getElementById('order').value = 'ASC';
				fieldorder = document.getElementById('order').value ;			
			}
		}else {
			fieldorder = order;
			//alert(fieldorder);
		}
		
        if(actionname ==  undefined )
			urlPath = urlp+"index/";
		else
			urlPath = urlp+actionname+"";
			//alert(urlPath);
		$.ajax({
		type: "POST",
	    dataType: "json",
		url: urlPath,
		data: "itemId="+bid+"&page="+page+"&pagesize="+pagesize+"&field="+field+"&fieldorder="+order+"&contentType="+contenttype,
		success: function(msg){
			if(contenttype =='')
			{
				$('#postedComments').html(msg.output);
			}
			else
			{
				//alert(contenttype);
				//$('#commentsId').show('slow');
				$('#postedComments').html(msg.output);
				//$('#commentsOrder').hide('slow');
			}
			
		}
		});
		
	}

function hasWhiteSpace(s) 
{
     reWhiteSpace = new RegExp(/^\s+$/);

     // Check for white space
     if (reWhiteSpace.test(s)) {
          //alert("Please Check Your Fields For Spaces");
          return false;
     }
return true;
}
