function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

var min=8;
var max=24;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
	 var h = parseInt(p[i].style.lineHeight.replace("px",""));
      } else {
         var s = 12;
	 var h = 12;
      }
      if(s!=max) {
         s += 1;
	 h += 1;
      }
      p[i].style.fontSize = s+"px"
      p[i].style.lineHeight = h+"px"
   }
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}


function comment_rate(comment_id, rate)
{
	new Ajax.Request( rooturl + "comments/" + rate + "/" + comment_id + "/?rand=" + Math.random(), {
		method: "get",
		onSuccess: function(transport) {
		
		set_cookie( "rate_"+comment_id, rate, 30, "/", "", "" );
		
		$("rate_"+comment_id).update(transport.responseText);

		}
	});
} 

function comment_alert(comment_id)
{
	new Ajax.Request( rooturl + "comments/alert/" + comment_id + "/?rand=" + Math.random(), {
		method: "get",
		onSuccess: function(transport) {
		
		set_cookie( "alert_"+comment_id, "1", 30, "/", "", "" );
		
		$("alert_"+comment_id).update(transport.responseText);
		

		
		}
	});
} 


function vote_player(player_id)
{
	new Ajax.Request( rooturl + "ajax/vote_player/" + player_id + "/?rand=" + Math.random(), {
		method: "get",
		onSuccess: function(transport) {
		
		set_cookie( "player_id_"+player_id, "1", 1, "/", "", "" );
		
		$("contest_votes_"+player_id).update(transport.responseText);
		$("contest_vote_button_"+player_id).update('<img src="public/images/contest_vote_done.png" border="0">');
		}
	});
}

function set_cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

var cat = "article_image"; 
var first_image = 0; 

function select_image(iid, images_count){
	for(i=0;i<images_count;i++) {
		if(iid != i)
		{
			$(cat + "_" + i).hide();
			$("image" + i).removeClassName("active");
		}
		else 
		{
			$(cat + "_" + i).show();
			$("image" + i).addClassName("active");
		}
	}
	if($(cat + "_video")) { $(cat + "_video").hide(); }
	if($("imagevideo")) { $("imagevideo").removeClassName("activevideo"); }
}

function select_video(vid, images_count){
	for(i=0;i<images_count;i++) {
		$(cat + "_" + i).hide();
		$("image" + i).removeClassName("active");
	}
	
	$(cat + "_video").show();
	$("imagevideo").addClassName("activevideo");
}


function addpollother(what, where, say) {
	if(typeof say !== "undefined")
	{
		document.getElementById(where).innerHTML = say + "<input type='" + what + "' value='' name='poll_answer_other' MAXLENGTH=45 size='40'/><br />";
	}
	else 
	{
		document.getElementById(where).innerHTML = "<input type='" + what + "' value='' name='poll_answer_other' MAXLENGTH=45 size='40'/><br />";
	}
}

function removepollother(where) {
	document.getElementById(where).innerHTML = "";
}

function openFlash()
{

}

function closeFlash()
{
	$('nissan_ad').hide();
	$('nissan_ad_300').show();
}

function enabletextinput(inputname) 
{ 
	//document.$(formname).$(inputname).disabled=false;
	document.getElementById(inputname).disabled=false;

	
} 
function disabletextinput(inputname) 
{ 
	document.getElementById(inputname).disabled=true;
	document.getElementById(inputname).value="";
} 

function add_newsletter_email()
{
	var email = document.getElementById('newsletter_email').value;
	new Ajax.Request( rooturl + "newsletters/add/" + encodeURIComponent(email), {
		method: "get",
		onSuccess: function(transport) {
			$("newsletter_form").update(transport.responseText);
		}
	});
} 

function hideshowDiv(hidediv, showdiv)
{
	$(hidediv).hide();
	$(showdiv).show();
}


