var fullwin=null;
var addresswin=null;
var stillprocess = false;

function pageinit1()
{
	initRTE("php/rte/images/", "php/rte/", "styles/rte.css", false);
	var oHdnField = document.getElementById("hdnid_2");
	enableDesignMode("id_2", oHdnField.value, false, "");
}

function init()
{
	var o = document.getElementById("focusOnMe");
	if (o) o.focus();
	if  ((typeof pageinit) == "function")
		pageinit();
}

function checkall(name, value)
{
	var o = document.getElementById(name);
	for (var i=0; i<o.length; i++)
		if (o.elements[i].type == "checkbox")
			o.elements[i].checked = value;
}

function ClipBoard1(strtxt) 
{
	var o = document.getElementById("holdtext");
	o.value = strtxt;
	Copied = o.createTextRange();
	Copied.execCommand("Copy");
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}

function multiEmail(email_field) {
	var email_field = document.getElementsByName("to")[0].value;
	email_field=replaceAll(email_field,";",",");
	var email = email_field.split(',');
	for (var i = 0; i < email.length; i++) {
		str=email[i];
		if (!validateEmail(str.replace(/^\s*|\s*$/g,""))) {
			alert('one or more email addresses entered is invalid');
			return false;
		}
	}
	return true;
} 


function validateEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm)){
		return (true)
	}
	return (false)
}

function ClipBoard(strtxt) {
	var inElement = document.getElementById("holdtext");
	inElement.value = strtxt;
	//inElement = o.createTextRange();

  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range)
     range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(strtxt)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

function delconfirm(isedit,id,singleowner, isPrivate)
{
	if((isedit == "No" && isPrivate=="Public") || (isedit == "Yes" && singleowner=="No" && isPrivate=="Public"))
	{
		if(confirm("Are you sure you want to remove this page from here?"))
		{
			document.location.href="index.php?mode=2&page=saved&remove=Yes&isowner="+isedit+"&id="+id;
			//alert("Functionality to be implemented");
		}
	}
	else
	{
		if(confirm("This page will get removed from here and you will no longer have access to this page, are you sure?"))
		{
			document.location.href="index.php?mode=2&page=saved&remove=Yes&isowner="+isedit+"&id="+id;
			//alert("Functionality to be implemented");
		}
	}
	 
	/*
	if(isedit == "Yes" && singleowner=="Yes")
	{
		if(confirm("Are you sure you want to remove this page?  Since you have edit right to this page, no one else will have access to this page after deletion."))
		{
			document.location.href="index.php?mode=2&page=saved&remove=Yes&isowner="+isedit+"&id="+id;
			//alert("Functionality to be implemented");
		}
	}
	else
	{
		if(confirm("Are you sure you want to remove this page?"))
		{
			document.location.href="index.php?mode=2&page=saved&remove=Yes&isowner="+isedit+"&id="+id;
			//alert("Functionality to be implemented");
		}
	}
	*/
}

function fullscreen(pageid, cat, subcat)
{
	//alert("Under Implementation");
//	window.location.href="index.php?mode=2";
setHiddenVal("id_2");
	fullwin=window.open("editor.php?popup=true&mode=1&id="+pageid+"&cat="+cat+"&sub="+subcat, "editor","status=yes,toolbar=no,  width=600, height=500,scrollbars=yes,resizable=yes");
}

function resetpopup()
{
	if(fullwin!=null)
	{
		//var frmobjsp = document.getElementsByName("stillprocess")[0];
		
		if(!fullwin.closed )
		{
			fullwin.focus();
			return;
		}
	}
	if(addresswin!=null)
	{
		if(!addresswin.closed)
		{
			addresswin.focus();
			return;
		}
	}
}

function openpopup(id)
{
	var frmobj = document.getElementsByName("id_4")[0];
	if(frmobj.checked==true)
		addresswin=window.open("addressbook.php?mode=1&pageid="+id, "address","status=yes,toolbar=no, width=525, height=360, scrollbars=auto,resizable=yes");
//	else
//		alert("Page is public. You can not assign rights to a public page.");
}

function closeme()
{
//	var frmobjsp = opener.document.getElementsByName("stillprocess")[0];
//	frmobjsp.value="1";
//	opener.window.location.href="index.php?mode=2";
	self.close();
	opener.window.location.href="index.php?mode=2";
}
function openpopup1(id)
{
	addresswin=window.open("shareaddbook.php?mode=1&pageid="+id, "address","status=yes,toolbar=no,width=525,height=360,scrollbars=1,resizable=yes");
}

function redirectme(redurl)
{
	alert("redirecting");
	window.location.href=redurl;
}

function submitAddressSave()
{
	var email_field = document.getElementById("newemail").value;
	email_field=replaceAll(email_field,";",",");
	email_field=replaceAll(email_field," ","");
	var email = email_field.split(',');
	for (var i = 0; i < email.length; i++) {
		str=email[i];
		if (!validateEmail(str.replace(/^\s*|\s*$/g,""))) {
			alert('one or more email addresses entered is invalid');
			return false;
		}
	}
	document.getElementById("newemail").value=email_field;
	document.getElementById("submitype").value="1";
	return true;
	//document.forms[0].submit();
}


function changeimage()
{
	var stat;
	if(document.getElementById("imageoption").selectedIndex == 1)
	{
	stat="visible";
	}
	else
	{
	stat="hidden";
	}
	//alert(stat);
	document.getElementById("form1").image.style.visibility = stat;
}

function popupMessage(subject,body) {
  // SET MESSAGE VALUES
 // var to = "tomer@netscent.com";
 // var cc = "yehuda@internet.com";
 // var bcc = "tomer@internet.com";
  // BUILD MAIL MESSAGE COMPONENTS
  var doc = "mailto:" + 
    "?subject=" + escape(subject) +
    "&body=" + escape(body);

  // POP UP EMAIL MESSAGE WINDOW
  window.location = doc;
}


function openhelp(id)
{
	helpwin=window.open("help.php?id="+id, "help","status=yes,toolbar=no, width=400, height=300, scrollbars=auto,resizable=yes");
}

