/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;
var http_request = false;
var currentdiv = '';
var duration = 500;  /* 1000 millisecond fade = 1 sec */
var steps = 20;       /* number of opacity intervals   */
var delay = 5000;     /* 5 sec delay before fading out */

function changesplash(id)
{
//alert("ids are: "+ida+" "+idb+" "+idc+" "+idd);
document.getElementById(id).style.visibility='visible';
document.getElementById(id).style.position='relative';
document.getElementById(id).style.display='block';

}


function hidesplash(id)
{
//alert("ids are: "+ida+" "+idb+" "+idc+" "+idd);
document.getElementById(id).style.visibility='hidden';
document.getElementById(id).style.position='absolute';
document.getElementById(id).style.display='none';

}



function processAjaxb(url,id) {

processAjax(url,id);

}

function processAjax(url,id) {

//alert(url);
//alert(id);
setOpacity(0, id, false, '') ;
currentdiv = id;
//alert(id+currentdiv);
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
//alert(currentdiv);
document.getElementById(currentdiv).innerHTML = req.responseText;
fadeIn( currentdiv, false, '');
} else {
alert("Problem: " + req.statusText);
}
}
}


function processAjaxc(url,id) {

//alert(url);
//alert(id);
//setOpacity(0, id, false, '') ;
currentdiv = id;
//alert(id+currentdiv);
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDivc;
req.open("GET", url, true);
req.send();

}
}
}

function targetDivc() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
//alert(currentdiv);
document.getElementById(currentdiv).innerHTML = req.responseText;
//fadeIn( currentdiv, false, '');
} else {
alert("Problem: " + req.statusText);
}
}
}


// Rollover for image Stars //
function rating(num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "on";
				document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+i).className = "";
				document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(preSet);
			document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me){
	if(!rated){
		document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		preSet = me;
		rated=1;
		sendRate(me);
		rating(me);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
	processAjaxc('setrate.php?cid='+sel.target+'&rate='+sel.id.replace("_",""),'');
	//alert("Your rating was: "+sel.title+" "+sel.id.replace("_","")+" cid was "+sel.target);
}


function rateIt2(me){
	if(!rated){
		document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		
		preSet = me;
		rated=1;
		sendRate2(me);
		rating(me);
		document.getElementById("rate").value = me.id.replace("_","");
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate2(sel){
	processAjaxc('setadrate.php?id='+sel.target+'&rate='+sel.id.replace("_",""),'');
	//alert("Your rating was: "+sel.title+" "+sel.id.replace("_","")+" cid was "+sel.target);
}

   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            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);
	  
	  //req.responseText;
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('result').innerHTML = result;            
         } else {
            alert('There was a problem with the request.'+http_request.status);
			            result = http_request.responseText;
            document.getElementById('result').innerHTML = result;  
         }
      }
   }
   
   function get(obj,url) {
   
	  
      var poststr = "comment=" + encodeURI( document.getElementById('comment').value ) +
                    "&type=" + encodeURI( document.getElementById('type').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value ) +
                    "&cid=" + encodeURI( document.getElementById('cid').value );

	  makePOSTRequest(url, poststr);
		document.getElementById('pcomment').innerHTML = '<span class=largered><center>Your Comment was Posted!</center></span>';
		processAjax('getcomments.php?cid='+document.getElementById("cid").value+'&type=1','comments');	  
   }

   
    function getinsp(obj,url) {
   
	  
      var poststr = "comment=" + encodeURI( document.getElementById('comment').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value );

	  makePOSTRequest(url, poststr);
		document.getElementById('inspire').innerHTML = '<span class=largered><center>Thank you, your Comment was recieved!</center></span>';
		
   }  
   
   function getrev(obj,url) {
   
	  
      var poststr = "comment=" + encodeURI( document.getElementById('comment').value ) +
                    "&rate=" + encodeURI( document.getElementById('rate').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value ) +
                    "&adid=" + encodeURI( document.getElementById('adid').value );

	  makePOSTRequest(url, poststr);
		
		document.getElementById('preview').innerHTML = '<span class=largered><center>Your Review was Posted!</center></span>';
		processAjax('getcomments.php?cid='+document.getElementById("cid").value+'&type=1','comments');	  
   }

   
    function getdeny(obj,url) {
   
	  
      var poststr = "comment=" + encodeURI( document.getElementById('comment').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value ) +
                    "&cid=" + encodeURI( document.getElementById('cid').value );

	  makePOSTRequest(url, poststr);
		document.getElementById(obj).innerHTML = '<span class=largered><center>Creation Denied</center></span>';
		//processAjax('denyc.php?cid='+document.getElementById("cid").value+'&type=1','comments');	  
   }  
   
    function getbull(obj,url) {
   
	  
      var poststr = "bodya=" + encodeURI( document.getElementById('bodya').value ) +
                    "&subject=" + encodeURI( document.getElementById('subject').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value );

	  makePOSTRequest(url, poststr);
		document.getElementById('pcomment').innerHTML = '<span class=largered><center>Your Bulletin was Posted!</center></span>';
		//processAjax('getbulletin.php','consolearea');	  
   } 

    function getimport(obj,url) {
   
	  
      var poststr = "email_box=" + encodeURI( document.getElementById('email_box').value ) +
                    "&password_box=" + encodeURI( document.getElementById('password_box').value ) +
                    "&provider_box=" + encodeURI( document.getElementById('provider_box').value );

	  makePOSTRequest(url, poststr);
	 //alert('url: '+url+' pstr: '+poststr);
		//processAjax('denyc.php?cid='+document.getElementById("cid").value+'&type=1','comments');	  
   }    
 


 
   
   function smail(obj,url) {
   
	  
      var poststr = "bodya=" + encodeURI( document.getElementById('bodya').value ) +
                    "&subject=" + encodeURI( document.getElementById('subject').value ) +
                    "&posted=" + encodeURI( document.getElementById('posted').value ) +
                    "&user=" + encodeURI( document.getElementById('user').value );

	  makePOSTRequest(url, poststr);
		//processAjax('getinbox.php','consolearea');
		document.getElementById('consolearea').innerHTML = '<span class=largered><center>Your Mail was Sent!</center></span><br>';
			  
   }
   
   
function confirmremovem(url,id)
{

var killthem=confirm("Are you sure you wish to delete this friend?");
if (killthem== true)
{
processAjax(url,id);
}

}
   
function confirmblock(url,id)
{

var killthem=confirm("Are you sure you wish to block this user?");
if (killthem== true)
{
processAjax(url,id);
}

}


function startUpload(){

document.getElementById('f1_upload_process').style.visibility = 'visible';

return true;

}

      function stopUploadb(message){
		//alert("HELLO!!!");
	      processAjax('sharepicture.php?g='+message,'myavi');

		return true;

      }

      

      

      

      function stopUpload(success,message){

      var result = '';

      if (success == 1){
	  processAjax('getava.php','myavi');
      document.getElementById('result').innerHTML =

      '<span class="msg">'+message+'<\/span><br/><br/>';

      }

      else {

      document.getElementById('result').innerHTML =

      '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';

      }

      document.getElementById('f1_upload_process').style.visibility = 'hidden';

      return true;

      }
	  
	  
	  
function fadeIn( id, doajax, url){
  for (i = 0; i <= 1.2; i += (1 / steps)) {
    setTimeout("setOpacity(" + i + ", '"+id+"', "+doajax+", '"+url+"')", i * duration);
  }
  //setTimeout("fadeOut()", delay);
}

function fadeOut( id, doajax, url) {
  for (i = 0; i <= 1.2; i += (1 / steps)) {
    setTimeout("setOpacity(" + (1 - i) + ", '"+id+"', "+doajax+", '"+url+"')", i * duration);
  }
  //setTimeout("fadeIn()", duration);
}

function setOpacity(level, id, doajax, url) {
  document.getElementById(id).style.opacity = level;
  document.getElementById(id).style.MozOpacity = level;
  document.getElementById(id).style.KhtmlOpacity = level;
  document.getElementById(id).style.filter = "alpha(opacity=" + (level * 100) + ");";
	if(level <= 0.2 && doajax)
	{
		
		processAjaxb(url,id);
		
		//alert("url "+url+" id "+id+" doajax "+doajax);
	
	}  
}


	var dhtmlgoodies_tooltip = false;
	var dhtmlgoodies_tooltipShadow = false;
	var dhtmlgoodies_shadowSize = 4;
	var dhtmlgoodies_tooltipMaxWidth = 200;
	var dhtmlgoodies_tooltipMinWidth = 100;
	var dhtmlgoodies_iframe = false;
	var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;
	function showTooltip(e,tooltipTxt)
	{
		
		var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	
		if(!dhtmlgoodies_tooltip){
			dhtmlgoodies_tooltip = document.createElement('DIV');
			dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
			dhtmlgoodies_tooltipShadow = document.createElement('DIV');
			dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';
			
			document.body.appendChild(dhtmlgoodies_tooltip);
			document.body.appendChild(dhtmlgoodies_tooltipShadow);	
			
			if(tooltip_is_msie){
				dhtmlgoodies_iframe = document.createElement('IFRAME');
				dhtmlgoodies_iframe.frameborder='5';
				dhtmlgoodies_iframe.style.backgroundColor='#FFFFFF';
				dhtmlgoodies_iframe.src = '#'; 	
				dhtmlgoodies_iframe.style.zIndex = 100;
				dhtmlgoodies_iframe.style.position = 'absolute';
				document.body.appendChild(dhtmlgoodies_iframe);
			}
			
		}
		
		dhtmlgoodies_tooltip.style.display='block';
		dhtmlgoodies_tooltipShadow.style.display='block';
		if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='block';
		
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX + 10;
		
		dhtmlgoodies_tooltip.style.width = null;	// Reset style width if it's set 
		dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
		dhtmlgoodies_tooltip.style.left = leftPos + 'px';
		dhtmlgoodies_tooltip.style.top = e.clientY + 10 + st + 'px';

		
		dhtmlgoodies_tooltipShadow.style.left =  leftPos + dhtmlgoodies_shadowSize + 'px';
		dhtmlgoodies_tooltipShadow.style.top = e.clientY + 10 + st + dhtmlgoodies_shadowSize + 'px';
		
		if(dhtmlgoodies_tooltip.offsetWidth>dhtmlgoodies_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
			dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
		}
		
		var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;		
		if(tooltipWidth<dhtmlgoodies_tooltipMinWidth)tooltipWidth = dhtmlgoodies_tooltipMinWidth;
		
		
		dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
		dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
		dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';		
		
		if((leftPos + tooltipWidth)>bodyWidth){
			dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
			dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
		}
		
		if(tooltip_is_msie){
			dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
			dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
			dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
			dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';
		
		}
				
	}
	
	function hideTooltip()
	{
		dhtmlgoodies_tooltip.style.display='none';
		dhtmlgoodies_tooltipShadow.style.display='none';		
		if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='none';		
	}