var changediv = "voter";
var showgraph = 0;
var lyricsid = 0;
var elem;
var campo;

function addComment(movieID) {
		text = document.getElementById('comment').value; 
		poststr = 'comment='+text+'&movieID='+movieID;
      	makePOSTRequest('http://www.fluge.com/send.php', poststr);

		if(document.all){
			document.getElementById('newcomment').innerHTML = text;
		} else{
			document.getElementById('newcomment').textContent = text;
		}

		document.getElementById('commentform').style.display  = 'none';
		return false;
}

function rateMovie(rating,movieID)  {

		poststr = 'rating='+rating+'&movieID='+movieID;
      	makePOSTRequest('http://www.fluge.com/send.php', poststr);
		rating = (rating * 25) - 8;
		document.getElementById('current-rating').style.width = rating/2+'px';
		document.getElementById('ratelinks').style.display = 'none';
		document.getElementById('ratingtext').innerHTML = 'Thank You!';
}


function editmovie(id){
	movieid = id;
	if(document){
	
		if(document.getElementById('movieContent')){
				actual = document.getElementById('movieContent');
				width = widthEl('movieContent') - 120;
				height = heightEl('movieContent') + 100;
				if(document.all){
				text = actual.innerText;
				} else{
				text=  actual.textContent;
				}
				actual.innerHTML = "<textarea id=\"content_field\" style=\"width: "+width+"px; height: "+height+"px;\" onfocus=\"highLight(this,'movieContent');\" onblur=\"noLight(this,'movieContent'); return createEditFrame(this,'movieContent');\">" + text + "</textarea>";	
				actual.firstChild.focus();
			}

	
	
	}

}




function createEditFrame(campo,idfld){ 
		var answer = confirm("Are you sure this is correct movie information?")
		elem = document.getElementById( idfld );
		if(answer){
				data = encodeURI(campo.value);
				poststr = "tit=+"+escape(document.title.slice(0,50)) +"&loc="+escape(location.href)+"&id="+movieid+"&data="+data;
      			makePOSTRequest('http://www.fluge.com/send.php', poststr);
				if(document.all){
					elem.innerText = campo.value;
				} else{
					elem.textContent = campo.value;
				}

		}else{
				if(document.all){
					elem.innerText = campo.value;
				} else{
					elem.textContent = campo.value;
				}
		}
} 

function highLight(span){ 
            //span.parentNode.style.border = "2px solid #D1FDCD"; 
            //span.parentNode.style.padding = "0"; 
            span.style.border = "1px solid #54CE43";           
} 

function noLight(span){ 
        //span.parentNode.style.border = "0px"; 
        //span.parentNode.style.padding = "2px"; 
        span.style.border = "0px";        

}

function widthEl(span){

	if (document.layers){
	  w=document.layers[span].clip.width;
	} else if (document.all && !document.getElementById){
	  w=document.all[span].offsetWidth;
	} else if(document.getElementById){
	  w=document.getElementById(span).offsetWidth;
	}
return w;
}

//get height of text element
function heightEl(span){

	if (document.layers){
	  h=document.layers[span].clip.height;
	} else if (document.all && !document.getElementById){
	  h=document.all[span].offsetHeight;
	} else if(document.getElementById){
	  h=document.getElementById(span).offsetHeight;
	}
return h;
}

  var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {

            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
				//alert('Thank you for sending in corrections!\nThey are double checked and changed.');  
         } else {
            	//alert('There was a problem with the request.');
         }
      }
   }


