
/* ZIPD CODE DETAILS */

function checkUniqueZipcode(code,city,state,country,div,zip)
{
var e;
	if(code!=''){	
		$.ajax({
		type: "POST",
	   	dataType: "json",
		url: "/utilities/utility/zipcode/",
		data: "code="+code,
		success: function(msg){ 
			if(msg.errorcode != '')
			{
				$('#'+div).html(msg.errorcode);
			$('#'+state).val('') ;
			$('#'+country).val('') ;
			$('#'+city).val('') ;
 			document.getElementById(state).value = '';
 			document.getElementById(country).value = '';
			document.getElementById(city).value = '';
			$('#'+zip).focus();
			} else {
			$('#'+state).val(msg.state);
			$('#'+country).val(msg.country);
			$('#'+city).val(msg.city);
			}
			
		}
		
		});
	} else {
		$('#'+div).html('');

	}	


}
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"); 
		} );
	 	
}

function sortingBy(contenttype,bid,pagesize,page,field,order,actionname,urlp)
{

	var fieldorder='ASC',urlPath; 
	if(actionname ==  undefined )
		urlPath = urlp+"index/";
	else
		urlPath = urlp+actionname+"";
		//alert(urlPath);
	$.ajax({
	type: "POST",
	url: urlPath,
	data: "id="+bid+"&page="+page+"&pagesize="+pagesize+"&field="+field+"&fieldorder="+order,
	success: function(msg){
		$('#postedComments').html(msg);
	}
	});
}

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';
}

function reportAbuse(contentId,bid)
{
	if(lg == true) {
		if(confirm('Do you really want to abuse this comment?'))
		{
			$.ajax({
					type: "POST",
					dataType: "json",
					url: "/utilities/utility/report-abuse",
					data:  {cid:contentId},
					success: function(data){
						if(data.success==1){	
							alert('This comment has been reported abuse.');
							sortingBy('',bid,'','1','posted_on',null,'','/bigidea/comments/');
						} 
					}
				});
		}
	} 
	else
	{
		if(confirm('You need to be logged in to report this comment as abuse.')) 
			window.location = '/utilities/utility/trackback';
	}
	
}
function showPostComments()
{
	if(lg == true)
	{
		if(shi == 0)
		{
			$("#pcomm").show("slow");
			shi = 1;
		}
		else
		{
			$("#pcomm").hide("slow");
			shi = 0;
		}
	}
	else
	{
		if(confirm('You need to be logged in to Post Comments.')) 
			window.location = '/user/login/';
		return false;		
	}
}
function changeParentId(id)
{
	$("#pid").val(id);
	$("#pcomm").show("slow");
	shi = 1;
	$('#comment').focus();
}
function rate(type,id,uid)
{
	var cname = 'voting_'+id+uid;
	
	var cval = getCookie(cname);
	if(cval == 1) {
	   alert('You have already voted');		
	} else {
		setCookie(cname,1,1)
		$.ajax({
			type: "POST",
			url: "/bigidea/index/voting/",
			data: "type="+type+"&id="+id,
			success: function(msg){ 
				$("#rate").html(msg);	
				alert('You have voted successfully');
			}
			
			});
	}
	
	
/*	if(ratedcook == 0)
	{
		$.ajax({
			type: "POST",
			url: "/bigidea/index/voting/",
			data: "type="+type+"&id="+id,
			success: function(msg){ 
				$("#rate").html(msg);	
				alert('You have voted successfully');
			}
			
			});
			//alert(type+'-->'+id);
	}
	else
	{
		alert('You have already voted');
	}*/
}

function followIdea(id,value)
{
	$.ajax({
		type: "POST",
		dataType: "json",
		url: "/bigidea/index/follow-big/",
		data: "id="+id+"&bValue="+value,
		success: function(data){
			if(data.success==1) {
			alert('Your alert is unregistered.');
			$("#follow").show();
			$("#unfollow").hide();
			}
			else {
			alert('Your alert is registered.');
			$("#follow").hide();
			$("#unfollow").show();
			}	
		}
		
		});
		//alert(type+'-->'+id);
}

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 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 "";
}

// Trim the spaces

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function validInput(string)
{
re=/[<>]/;
return re.test(string);
}


