function fillContact(id)
{
	var selObj = document.getElementById('contact_'+id);
	var txtValueObj = document.getElementById('recip_email_'+id);
	var txtTextObj = document.getElementById('recip_name_'+id);
	
	var selIndex = selObj.selectedIndex;
	txtValueObj.value = selObj.options[selIndex].value;
	txtTextObj.value = selObj.options[selIndex].text;
	selObj.blur();

}

function changeBg()
{
	var newBg = document.getElementById('bg_color').value;
	tinyMCE.getInstanceById('message').dom.setStyle('tinymce','background-color', newBg)
	document.getElementById('bg_color').blur();
}

function doPoem()
{
	var poem_box = document.getElementById('poem_changer');
	var poem_id = poem_box.selectedIndex;
	var poem_body = poem_box.options[poem_id].value;

	poem_box.selectedIndex=0;
	poem_box.blur();

	var current_body = tinyMCE.activeEditor.getContent();
	var new_body = current_body + poem_body;

	tinyMCE.activeEditor.setContent(new_body);
}


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

function CUA(ch) {
var v = ch.checked;
var f = ch.form;
for(var i=0;i<f.elements.length;i++) {
    if(f.elements[i].type=="checkbox") {
       f.elements[i].checked = v; 
     }
}
}

var xmlhttp;

function findEvent(year,mon,day)
{
document.getElementById("event_title").style.display="block";
document.getElementById("event_load").style.display="block";
document.getElementById("calendar_data").innerHTML="";
xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
var url="index.php?act=cal_data";
url=url+"&year="+year;
url=url+"&mon="+mon;
url=url+"&day="+day;
xmlhttp.onreadystatechange=stateChanged ;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
document.getElementById("calendar_data").innerHTML=xmlhttp.responseText;
document.getElementById("event_load").style.display="none";
  }
}

function fillDate(dVal)
{
	opener.document.forms['main_form'].send_date_box.value = dVal;
	window.close();
}



function delContact(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }        
var url="index.php";
url=url+"?act=contacts&what=del_single";
url=url+"&id="+id;
/*xmlHttp.onreadystatechange=contStateChanged;*/
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

document.getElementById(id).style.backgroundColor='red';
setTimeout("document.getElementById("+id+").style.display='none';", 300);

}

function contStateChanged()
{ 
if (xmlHttp.readyState==4)
   {

alert('Done');
   document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

   }
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function rateImg(rating,id)
{
document.getElementById('rateload').style.visibility='visible';
xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
var url=popup_base_url+"index.php?act=rate_img";
url=url+"&rating="+rating;
url=url+"&id="+id;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = rateCallback;
}

function rateCallback()
{
if (xmlhttp.readyState==4)
  {
var resp=xmlhttp.responseText
var newData = resp.split("-");
newSize=newData[0]*25;
document.getElementById('ratelinks').style.display = 'none';
document.getElementById('current-rating').style.width = newSize+'px';
document.getElementById('ratingtext').innerHTML = newData[0];
document.getElementById('votetext').innerHTML = newData[1]
document.getElementById('rateload').style.visibility='hidden';
  }
}

function changeStamp(stampFile) /* This function saves the active stamp so we can reset it if we choose another one */
{
if(typeof currentStampId != 'undefined')
{
	document.getElementById('stamp-'+currentStampId).className='unselected_stamp'; /* Reset our previously selected stamp */
}
currentStampId = stampFile;
document.getElementById('stamp-'+stampFile).className='selected_stamp';
}

function hideDiv(id)
{
	  var itm = null;
	  if (document.getElementById) {
		itm = document.getElementById(id);
	  } else if (document.all){
		itm = document.all[id];
	  } else if (document.layers){
		itm = document.layers[id];
	  }
	
	  if (!itm) {
	   // do nothing
	  }
	  else if (itm.style) {
		itm.style.display = "none"; 
	  }
}

function showDiv(id)
{
	  var itm = null;
	  if (document.getElementById) {
		itm = document.getElementById(id);
	  } else if (document.all){
		itm = document.all[id];
	  } else if (document.layers){
		itm = document.layers[id];
	  }
	
	  if (!itm) {
	   // do nothing
	  }
	  else if (itm.style) {
		 itm.style.display = "block";
	  }
}


function disableEl(divName,disableIt)
{
	document.getElementById(divName).disabled = disableIt;
}


function changeDate(day,mon,yr)
{
	var opts = document.getElementById('day_chooser').options;
	for (var i=0; i < opts.length; i++) {
		if (opts[i].value == day) {
			opts[i].selected = true;
			break;
		}
	}
	var opts = document.getElementById('month_chooser').options;
	for (var i=0; i < opts.length; i++) {
		if (opts[i].value == mon) {
			opts[i].selected = true;
			break;
		}
	}
	var opts = document.getElementById('year_chooser').options;
	for (var i=0; i < opts.length; i++) {
		if (opts[i].value == yr) {
			opts[i].selected = true;
			break;
		}
	}
}
