var $=jQuery.noConflict();


/***
	Name: afc_side_footer
	Purpose: 
	Arguments:
		data - 
***/
function afc_side_footer(data){
	if(data.length>0){
		var sOutput='';
		var fOutput='';
		for(var i=0;i<data.length;i++){
			if(data[i]){
				if(i<4){
					sOutput+='<div class="item"><a href="'+ data[i].redirect_url +'" ' + params.target + '>'+ data[i].title +'<p>'+ data[i].d1 +' '+ data[i].d2 +'</p><span>'+ data[i].url +'</span></a></div>'
				}else{
					fOutput+='<div class="item"><a href="'+ data[i].redirect_url +'" ' + params.target + '>'+ data[i].title +'<p>'+ data[i].d1 +' '+ data[i].d2 +'</p><span>'+ data[i].url +'</span></a></div>'
				}
			}
		}
		if(sOutput){document.getElementById('dmn_results_s').innerHTML='<div class="spon_link side_foot"><h3><a href="http://about-search.aol.com/index.html#sl" target="_blank">Sponsored Links</a></h3>'+sOutput+'<a href="http://search.aol.com/aol/weboffers?invocationType=campaign7&query=autos&sbrand=undefined&sch=paol-landing&sclient=aol-landing&scoco=undefined&snum=10&ssch=campaign7&sview=undefined&spch=campaign7" target="_blank">See More Offers</a></div>'}
		if(fOutput){document.getElementById('dmn_results').innerHTML='<div class="spon_link side_foot"><h3><a href="http://about-search.aol.com/index.html#sl" target="_blank">Sponsored Links</a></h3>'+fOutput+'<a href="http://search.aol.com/aol/weboffers?invocationType=campaign7&query=autos&sbrand=undefined&sch=paol-landing&sclient=aol-landing&scoco=undefined&snum=10&ssch=campaign7&sview=undefined&spch=campaign7" target="_blank">See More Offers</a></div>'}
	}
}

function tabTo(tab) {
	document.getElementById('formerrors').innerHTML = '';
	document.getElementById('cmtuinfo_email').style.display='none';
	document.getElementById('cmtuinfo_blogsmith').style.display='none';
	document.getElementById('cmtuinfo_sns').style.display='none';
	document.getElementById('cmtuinfo_'+tab).style.display='block';
	document.getElementById('cmtutab_email').className='';
	document.getElementById('cmtutab_blogsmith').className='';
	document.getElementById('cmtutab_sns').className='';
	document.getElementById('cmtutab_'+tab).className='currenttab';

	if (!sns_checked && tab == 'sns')
	{
		image1 = new Image();
		image1.src = "http://www.blogsmithmedia.com/framework.weblogsinc.com/media/loading.gif";
		sns.init('ch1ga1KvP7TotwTC');
		sns_checked = true;
	}
	
	current_tab = tab;
}

function inputValidation() {
	document.getElementById('formerrors').innerHTML = '';

	var validInfo = 0;
	var validName = 0;
	var validEmail = 0;
	var validComments = 0;
	var validSNS = 0;
	var links = 0;
	var errors = '';
	
	switch(current_tab) {
		case "email":
			var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var email = document.getElementById('AuthorEmail').value;
			if(document.getElementById('AuthorName').value == '') {
				errors += "<li class='error'>Please provide a name.</li>";
			}
			if (email == '' || !filter.test(email)) {
				errors += "<li class='error'>Please provide a valid email address.</li>";
			}
			if (!errors) {
				validInfo = 1;
			}
			
			break;
		case "blogsmith":
			if(document.getElementById('C_AuthorEmail').value == '') {
				errors += "<li class='error'>Please enter your email address.</li>";	
			}
			if(document.getElementById('C_AuthorPass').value == '') {
				errors += "<li class='error'>Please enter your password.</li>";	
			}
			if (!errors) {
				validInfo = 1;
			}

			
			break;
		case "sns":
			if (document.getElementById('sns_screenname') && document.getElementById('sns_password'))
			{
				if (document.getElementById('sns_screenname').value && document.getElementById('sns_password').value) {
					sns.calls.login();
					return false;
				}
			}
			if (document.getElementById('sns_securid'))	{
				if (document.getElementById('sns_securid').value) {
					 sns.calls.login();//setTimeout("sns.calls.login();",1000);
					return false;
				}
			}
			var token = (document.getElementById('token')) ? document.getElementById('token').value : '';
			if(token == '') {  
				errors = "<li class='error'>Sorry, we don't have that login on file. Please try again, you may have made a typo.</li> ";
			} else {
				validInfo = 1;
			}
			break;
	}
	var txt = document.getElementById('Comments').value;

	if(txt != '') {
		validComments = 1;
	}

	for (var ind=0;ind<txt.length;ind++)
	{
		if (txt.substring(ind,ind+7)=="http://") {
			links = links + 1;
		} else if (txt.substring(ind,ind+6)=="ftp://") {
			links = links + 1;
		} else if (txt.substring(ind,ind+8)=="https://") {
			links = links + 1;
		}
	}

	if(validInfo == 1 && validComments == 1 && links < 4) {
		return true;
	} else {
		var errorMessage = "<div><h4>Sorry there were errors:</h4><ol>";
		errorMessage += errors;
		if(validComments == 0) { errorMessage += "<li class='error'>Please enter a comment.</li> "; }
		if(links > 3) { errorMessage += "<li class='error'>Sorry, we can only store 3 urls.</li>"; }
		errorMessage += "</ol></div>";
		document.getElementById('formerrors').innerHTML = errorMessage;
		return false;
	}
}


// PR HIDER
jQuery('#pr_text').slideUp();

$(window).load(function(){
var $=jQuery.noConflict();
var prButton = $('#pr_box_button');

var prText = $('#pr_text');

prButton.click(function(){

	if(prText.is(':visible'))

	{

	prText.fadeTo('fast',0,function(){

		prText.slideUp('fast');

		prButton.css('background-image','url(http://www.blogsmithmedia.com/www.autoblog.com/media/show_full_pr_button.png)');

		});

	}

	else

	{

	prText.fadeTo('fast',0).slideDown('fast',function(){

		prText.fadeTo('fast',1);

		prButton.css('background-image','url(http://www.blogsmithmedia.com/www.autoblog.com/media/hide_full_pr_button.png)');

		});

	}

});
})
