// JavaScript Document
Array.prototype.in_array = function (obj) {
	var len = this.length;
	for (var x = 0;x <= len;x++) {
		if (this[x] == obj) return true;
	}
	return false;
}

function updateEcardMessage() {
  var preview = document.getElementById('yourPersonalMessage');
  var iFrame = document.getElementById('PersonalizedMessage_ifr');
  var browser = navigator.appName;
  if (browser=='Microsoft Internet Explorer') var docObj = window.frames['PersonalizedMessage_ifr'].document;
  else var docObj = iFrame.contentDocument;
  preview.innerHTML=docObj.getElementById('tinymce').innerHTML;
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function popup(url,width,height) {
  window.open(url,'popup','width='+width+',height='+height+',resizalbe=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function printCard(cardid,messagediv) {
  var printContent = document.getElementById(messagediv).innerHTML;
  if (printContent.indexOf('Your personal message will appear here.') > -1) {
    alert('Make sure you click the "Preview Message" button to update the text of the card or your message will not print!');
    return;
  }
  var windowUrl = 'about:blank';
  var uniqueName = new Date();
  var windowName = 'Print' + uniqueName.getTime();
  var printWindow = window.open(windowUrl, windowName,'width=860,height=1000,resizalbe=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
  printWindow.document.write('<div align="center" style="margin-top:50px;text-align:center;">');
  printWindow.document.write('<img src="/ecards/image.php?cardid='+cardid+'&width=800&height=800" border="0" align="absbottom" />');
  printWindow.document.write('</div>');

  printWindow.document.write('<table align="center" style="margin-top:50px;text-align:center;width:800px;">');
  printWindow.document.write('<tr><td width="15%"></td>');
  printWindow.document.write('<td width="70%" align="left">'+printContent+'</td>');
  printWindow.document.write('<td width="15%"></td></tr>');
  printWindow.document.write('</table>');

  printWindow.document.close();
  printWindow.focus();
  printWindow.print();
  printWindow.close();
}

function select_all() {
  var text_val=eval("document.form1.type");
  text_val.focus();
  text_val.select();
}

function globals(subscribers,countries) {
	var page = document.getElementById("content");
	var p = page.getElementsByTagName("p");
	for(var i = 0; i < p.length; i++) {
		if (p[i].innerHTML.indexOf('[TOTAL_SUBSCRIBERS]') >= 0) p[i].innerHTML = p[i].innerHTML.replace("[TOTAL_SUBSCRIBERS]", subscribers);
		if (p[i].innerHTML.indexOf('[TOTAL_COUNTRIES]') >= 0) p[i].innerHTML = p[i].innerHTML.replace("[TOTAL_COUNTRIES]", countries);
	}
	var div = page.getElementsByTagName("div");
	for(var i = 0; i < div.length; i++) {
		if (div[i].innerHTML.indexOf('[TOTAL_SUBSCRIBERS]') >= 0) div[i].innerHTML = div[i].innerHTML.replace('[TOTAL_SUBSCRIBERS]', subscribers);
		if (div[i].innerHTML.indexOf('[TOTAL_COUNTRIES]') >= 0) div[i].innerHTML = div[i].innerHTML.replace('[TOTAL_COUNTRIES]', countries);
	}
	var span = page.getElementsByTagName("span");
	for(var i = 0; i < span.length; i++) {
		if (span[i].innerHTML.indexOf('[TOTAL_SUBSCRIBERS]') >= 0) span[i].innerHTML = span[i].innerHTML.replace('[TOTAL_SUBSCRIBERS]', subscribers);
		if (span[i].innerHTML.indexOf('[TOTAL_COUNTRIES]') >= 0) span[i].innerHTML = span[i].innerHTML.replace('[TOTAL_COUNTRIES]', countries);
	}
}