//Initialize 2nd demo:
ddaccordion.init({
	headerclass: "dashTitle", //Shared CSS class name of headers group
	contentclass: "dashDrop", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["dashTitleclose", "dashTitleopen"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "<img src='images/drop-plus.gif' />", "<img src='images/drop-minus.gif' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})


function limitChars(textid, limit, infodiv){
 var text = $('#'+textid).val(); 
 var textlength = text.length;
if(textlength > limit)
 {
$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
  $('#'+textid).val(text.substr(0,limit));
return false;
}

 else

 {

 $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');

 return true;

 }

 }

$(function(){

$('#editAbout').keyup(function(){

limitChars('editAbout', 500, 'charlimit');

})

$('#amsg').keyup(function(){

limitChars('amsg', 2500, 'charlimitmsg');

})

$('#post-notice-body').keyup(function(){

limitChars('post-notice-body', 250, 'charlimit');

})
$('#post-offer-body').keyup(function(){

limitChars('post-offer-body', 500, 'charlimit2');

})

$('#comment').keyup(function(){

limitChars('comment', 500, 'charlimit');

})

$('#reviewBody').keyup(function(){
limitChars('reviewBody', 500, 'charlimit99');
})
$('#statustxt').keyup(function(){
limitChars('statustxt', 140, 'status-chars-left');
})

});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


$(document).ready(function(){
	$("#alerts-red").ready(function(){
	  $("#alerts-red").fadeIn(1500);
	 });

});

$(document).ready(function(){
	$("#alerts-blue").ready(function(){
	  $("#alerts-blue").fadeIn(1000).animate({opacity: '+=0'}, 2000).fadeOut(1000);
	 
	});

});


  $(document).ready(function(){
    $("#submitBus").validate();
	
  });
   $(document).ready(function(){
    $("#submitNotice").validate();
	
  });
    $(document).ready(function(){
    $("#submitOffer").validate();
	
  });

    $(document).ready(function(){
    $("#submitNews").validate();
	
  });
   $(document).ready(function(){
    $("#submitPro").validate();
	
  });
   $(document).ready(function(){
    $("#register").validate();
	
  });
  $(document).ready(function(){
    $("#sendmsg").validate();
	
  });
  $(document).ready(function(){
    $("#accSettings").validate();
	
  });
  $(document).ready(function(){
    $("#frmStatus").validate();
	
  });
   $(document).ready(function(){
    $("#frmReview").validate();
	
  });
  $(document).ready(function(){
    $("#frmMessage").validate();
	
  });

  
  //favorite items
  
function addToFav(id,type){

   $(document).ready(function(){

	//$("#bus-favorite").click(function(){
	var busid = addToFav;
		$.post("add-fav.php", { id: id, type: type}, function(){
											  $("#bus-add-ok"+id).html("<small>Added to Favorites</small>").animate({ opacity: "hide" }, 2000);
											  });
	$("#bus-fav-box"+id).hide();
	
	//});

});
  
}
function addContact(id){

   $(document).ready(function(){
		$("#add-con-ok"+id).html("Please wait... <img src='images/loading-small.gif'>");
		$.post("add-contact.php", { id: id}, function(){
											  $("#add-con-ok"+id).html("<small>Request Sent</small>").animate({ opacity: "hide" }, 2000);
											  });
	$("#add-con-box"+id).hide();
	

});
  
}

function subsToBus(id){

   $(document).ready(function(){

$.post("subs-bus.php", { id: id}, function(){
											  $("#bus-subs-ok"+id).html("<small>Subscription Successful</small>").animate({ opacity: "hide" }, 2000);
											  });
	$("#bus-subs-box"+id).hide();
	
	

});
  
}

function approveContact(id){
   $(document).ready(function(){
$.post("approve-contact.php", { id: id}, function(){
					$("#cont"+id).animate( {opacity: "hide" }, "slow");
			});

});
}

function confirmRequest(id,type){
   $(document).ready(function(){
	$.post("confirm-request.php", { id: id,type:type}, function(){
						$("#cr"+id).animate( {opacity: "hide" }, "slow");
				});
	});
}



$(function() {
    $('#show-reviews').cycle();
    
    $('#show-offers').cycle({
        prev:   '#prev',
        next:   '#next',
        timeout: 0
    });
	 $('#show-notices').cycle({
        prev:   '#prev2',
        next:   '#next2',
        timeout: 0
    });
	 $('#show-latest-bus').cycle({
        prev:   '#prev3',
        next:   '#next3',
        timeout: 0
    });
	 $('#show-latest-pro').cycle({
        prev:   '#prev4',
        next:   '#next4',
        timeout: 0
    });
	 
	$('#slideshow').cycle({ 
    fx:      'scrollRight', 
    speed:    300, 
    timeout:  5000,
	next:   '#next-slide', 
    prev:   '#prev-slide' 

	});

    
});


		// initialise plugins
		jQuery(function(){
			jQuery('ul.sf-menu').superfish();
		});
		
function delReview(id,type){
$(document).ready(function(){

		$.post("./review-operations.php?a=delete&t="+type, {id: id}, function(){
					$("#revtr"+id).animate( {opacity: "hide" }, "slow");
			});
});
}
function delSub(id){
$(document).ready(function(){

		$.post("./subsc-operations.php", {id: id}, function(){
					$("#sid"+id).animate( {opacity: "hide" }, "slow");
			});
});
}

function delRecom(id){
$(document).ready(function(){

		$.post("./recom-operations.php?a=delete", {id: id}, function(){
					$("#rectr"+id).animate( {opacity: "hide" }, "slow");
			});
});
}

function okReview(id,type){


$(document).ready(function(){

		$.post("./review-operations.php?a=ok&t="+type, {id: id}, function(){
					$("#revtr"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}
function okRecom(id){
$(document).ready(function(){

		$.post("./recom-operations.php?a=ok", {id: id}, function(){
					$("#rectr"+id).animate( {opacity: "hide" }, "slow");
			});
});
}

function delContact(id){


$(document).ready(function(){

		$.post("./contacts-operations.php", {id: id}, function(){
					$("#cont"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}


function delNews(id){


$(document).ready(function(){

		$.post("./news-operations.php", {id: id}, function(){
					$("#newsli"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}
function delOffer(id){


$(document).ready(function(){

		$.post("./offers-operations.php", {id: id}, function(){
					$("#offersli"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}
function delNotice(id){


$(document).ready(function(){

		$.post("./notices-operations.php", {id: id}, function(){
					$("#noticeli"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}

function delMsg(id){


$(document).ready(function(){

		$.post("./msg-operations.php?a=delete", {id: id}, function(){
					$("#msg"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}

function delSubscription(id,type,busid){


$(document).ready(function(){

		$.post("./subs-operations.php?a=" + type + "&busid=" + busid, {id: id, busid: busid}, function(){
					$("#subs"+id).animate( {opacity: "hide" }, "slow");
			});
	
});

}

function showNews(t){
	$(document).ready(function(){
	
		$("#switch-news").fadeOut(500);
		$("#news"+t).fadeIn(500);
							   });
}
function hideNews(t){
	$(document).ready(function(){
		$("#news"+t).fadeOut(500);
		$("#switch-news").fadeIn(500);
							   });
}
function showOffers(t){
	$(document).ready(function(){
	
		$("#switch-offers").fadeOut(500);
		$("#offers"+t).fadeIn(500);
							   });
}
function hideOffers(t){
	$(document).ready(function(){
		$("#offers"+t).fadeOut(500);
		$("#switch-offers").fadeIn(500);
							   });
}


function showNotice(t){
	$(document).ready(function(){
	
		$("#switch-notice").fadeOut(500);
		$("#notice"+t).fadeIn(500);
							   });
}
function hideNotice(t){
	$(document).ready(function(){
		$("#notice"+t).fadeOut(500);
		$("#switch-notice").fadeIn(500);
							   });
}

$(document).ready(function() {

	$("ul#topnav li").hover(function() { //Hover over event on list item
		$(this).css({ 'background' : '#51585a'}); //Add background color and image on hovered list item
		$(this).find("span").show(); //Show the subnav
	} , function() { //on hover out...
		$(this).css({ 'background' : 'none'}); //Ditch the background
		$(this).find("span").hide(); //Hide the subnav
	});

});


function OnSubmitForm()
{
  if(document.pressed == 'Business')
  {
   document.searchfrm.action ="search.php";
  }
  else
  if(document.pressed == 'Products')
  {
    document.searchfrm.action ="search.php";
  }
  return true;
}
//status updater
$(document).ready(function() {
	$("#frmStatus").submit(function() {
		var msg = $("#statustxt").val();
		
		if(msg != 'What are you doing now?'){
			$.post("update-status.php", { statusmsg: msg }, 
					function() {
				$("#st-up-ok").fadeIn(500).animate({opacity: '+=0'}, 1000).fadeOut(1000);
	
			});
		} else {
				$("#st-up-er").fadeIn(500).animate({opacity: '+=0'}, 1000).fadeOut(1000);
		}
		return false;
	});
});


function setCaretPosition(ctrl, pos)
{

 if(ctrl.setSelectionRange)
 {
 ctrl.focus();
 ctrl.setSelectionRange(pos,pos);
 }
 else if (ctrl.createTextRange) {
 var range = ctrl.createTextRange();
 range.collapse(true);
 range.moveEnd('character', pos);
 range.moveStart('character', pos);
 range.select();
 }
}

function process()
{
setCaretPosition(document.getElementById('msgb'),0);
} 

//load msgbody to reply
$(document).ready(function(){
		$(".reply-msg").click(function(){
			var msgid = $("#msgid").val();
				$("#show-rep-body").html("<div align='center' class='inactive'>Loading...</div>");
				$("#show-rep-body").load('./rep-body-load.php?id=' + msgid,function(){
					process();
				}).show("slow").slideDown("slow");
				$(".reply-msg").hide();
				//$("#show-rep-body").append("");
				
		});
	});

function sendReply(){
	$(document).ready(function(){
			$.post("./send-reply-back.php",{ tid: $("#tid").val(), sb: $("#sb").val(), msgb:$("#msgb").val() }, function(){
				$("#show-rep-body").fadeOut("slow");
				$("#show-rep-sent").append("<hr><p>Message Sent</p>").fadeIn(1000).animate({opacity: '+=0'}, 1500).fadeOut(1000);

			});
		
	});

}

function delComment(id){
		var pro = $("#proid").val();
		$.post("./comment-operations.php", {id: id, pro:pro}, function(){
					$(".del-com"+id).animate( {opacity: "hide" }, "slow");
	});

}
function sendInvite(){
	//$(document).ready(function(){
		$("#invite-sent").html("Sending <img src='images/loading-small.gif'>");
		var getemail = $("#invitemails").val();  
		
		$.post("./invite.php",{ emails: getemail }, function() {
				$("#invitemails").val(""); 
				 $("#invite-sent").html("Invitations Sent");
				$("#invite-sent").fadeIn(500).animate({opacity: '+=0'}, 1000).fadeOut(1000);
	
			});
	//});
}
function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
} 

$(document).ready(function()
{
	$("#subdomain").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the subdomain exists or not from ajax
		$.post("check-sub-domain.php",{ subdomain:$(this).val() } ,function(data)
        {
		  if(data=='no') //if subdomain not avaiable
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Sub-domain already taken').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Sub-domain Available!').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});

function showCountry(){
	$(document).ready(function()
	{

			$("#change-pop").fadeIn(500).animate({opacity: '+=0'}, 2000);
			
	});
	
}
function hideCountry(){
$(document).ready(function()
	{
		
							$("#change-pop").hide();		   
									   
	});
}

function saveCountry(){

   $(document).ready(function(){

	var c  = $("#country-list-pop").val();
		$.post("save-country.php", { c: c}, function(){
											 $("#change-pop").hide();
											 $("#cl-r").html(c);
											 location.reload(true);
											  });

	});
  
}
