
var elemShown = '';
//document.onclick=check(); 

 

tinyMCE.init({
	onchange_callback : "myMCEChange",
	mode : "textareas",
	width : "348",
	height : "200",
	theme : "advanced",
	theme_advanced_font_sizes : "80%=80%,100%=100%,130%=130%,150%=150%",
	theme_advanced_layout_manager : "SimpleLayout",
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,link,unlink,sub,sup,cut,copy,paste,forecolor,charmap",
	theme_advanced_buttons2 : "fontselect,fontsizeselect,bullist,numlist,justifyleft,justifyfull,undo,redo,removeformat",
	theme_advanced_buttons3 : "",
	language : "en",
	entity_encoding : "numeric",
	apply_source_formatting : true,
	element_format : "html",	
	relative_urls : false,
	remove_script_host : false,		
	verify_html : "true"
});

function check()
{
	if (elemShown != '')
	{
		apply(elemShown);
	}
}

function itemAdd()
{
	document.NEWSFORM.action = "index.php?action=add";
	document.NEWSFORM.submit();
}

function itemDelete(itemNr)
{
	var answer = confirm("Are you sure you want to delete this newsitem?");
	if (answer)
	{
		//alert("index.php?action=delete&item=" + itemNr);
		document.NEWSFORM.action = "index.php?action=delete&item=" + itemNr;
		document.NEWSFORM.submit();
	}
}

function edit()
{
	document.themeset.action='settings.php?return=return';
	document.themeset.submit();
}

function head()
{
	document.themeset.action='settings.php?action=header';
	document.themeset.submit();
}

function foot()
{
	document.themeset.action='settings.php?action=footer';
	document.themeset.submit();
}

function showItemText(elem, value)
{

}

function mouseOver(elem)
{

	//elem.style.backgroundColor = '#C0C0F0';
	elem.style.border='1px dashed #0000FF';
	elem.style.cursor = 'pointer';
}

function mouseOut(elem)
{
	//elem.style.backgroundColor = '';
	elem.style.border='';
}

function showEdit(nr)
{
	//alert ('java: Edit');
	elemShown = nr;
	document.getElementById('edit_div_'+nr).style.display='block';
	document.getElementById('upload_div_'+nr).style.display='block';
	document.getElementById('preview_div_'+nr).style.display='none';

}

function apply(nr)
{
	elemShown = '';
	//alert ('java: Preview');
	document.getElementById('iText'+nr).innerHTML = document.getElementById('item_textarea_'+nr).value;
	document.getElementById('iTitle'+nr).innerHTML = document.getElementById('item_subject_'+nr).value;
	//document.getElementById('edit_div_'+nr).innerHTML = document.getElementById(objID).value;
	document.getElementById('edit_div_'+nr).style.display='none';
	document.getElementById('upload_div_'+nr).style.display='none';
	document.getElementById('preview_div_'+nr).style.display='block';


}

function moveUp(itemNr)
{
	document.NEWSFORM.action = "index.php?action=up&item=" + itemNr;
	document.NEWSFORM.submit();
}

function moveDown(itemNr)
{
	document.NEWSFORM.action = "index.php?action=down&item=" + itemNr;
	document.NEWSFORM.submit();
}

function selectImg(itemNr, imgName)
{
	document.NEWSFORM.action = "index.php?action=image&item=" + itemNr +"&arg1="+imgName;
	document.NEWSFORM.submit();
}

function upload(itemNr) 
{

	document.NEWSFORM.action = "index.php?action=uploadpage&item=" + itemNr;
	document.NEWSFORM.submit();
	//var width = 400;
	//var height = 100;
	//var left = (screen.width - width)/2;
	//var top = (screen.height - height)/2;
	//window.open( "http://www.vacaza.com/news/upload.php", "upload", 'location=0, status=0, scrollbars=0, dependent=1, status=1, height='+height+', width='+width+', left='+left+', top='+top+', resizable=0' )
}

function settings()
{

	document.NEWSFORM.action = "index.php?action=settings";
	document.NEWSFORM.submit();
}

function maillist()
{

	document.NEWSFORM.action = "index.php?action=maillist";
	document.NEWSFORM.submit();
}

function setlang()
{

	document.NEWSFORM.action = "index.php";
	document.NEWSFORM.submit();
}
function theme()
{

	document.NEWSFORM.action = "index.php";
	document.NEWSFORM.submit();
}


function mail()
{

	document.NEWSFORM.action = "index.php?action=mail";
	document.NEWSFORM.submit();
}


function showSubject(divID, objID, elem)
{
	if ('none' == document.getElementById(divID).style.display)
	{
		document.getElementById(divID).style.display='block';
	}
	else
	{
		elem.innerHTML = document.getElementById(objID).value;
		document.getElementById(divID).style.display='none';
	}
}

function OnChangeEmailBox(emailbox)
{
	//alert(emailbox.value);
	var newmail = '';
	var email = emailbox.value;
	var emailsArray = email.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
	if (emailsArray)
	{
		for (var i = 0; i < emailsArray.length; i++)
		{
			if (i !== 0) newmail = newmail + ', ';
			newmail = newmail + emailsArray[i];
		}
	}
	emailbox.value = newmail;
}

function chkmail(str) 
{

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false; // No @
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;// Start or ends with @
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false; // No dot or start or ends with dot
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    return false; // More than one @
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false; //  *.@* or *@.* 
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    return false; // No dot after @
	}
	
	if (str.indexOf(" ")!=-1){
	    return false; // Contains a space
	}
 	return true;					
}

/*
function showDiv(objID)
{
	if ('none' == document.getElementById(objID).style.display)
	{
		document.getElementById(objID).style.display='block';
	}
	else
	{
		document.getElementById(objID).style.display='none';
	}
}

function showImage(objID, elem)
{
	if ('none' == document.getElementById(objID).style.display)
	{
		document.getElementById(objID).style.display='block';
	}
	else
	{
		document.getElementById(objID).style.display='none';
		//document.getElementById(objID).form.submit();
	}
}

function showEdit(objID, elem)
{
	if (!tinyMCE.get(objID))
	{
		tinyMCE.execCommand('mceAddControl', false, objID);
	}
	else
	{	
		if (tinyMCE.activeEditor.isDirty())
		{
			elem.innerHTML = tinyMCE.activeEditor.getContent();
		}
		tinyMCE.execCommand('mceRemoveControl', false, objID);
	}	
}
*/

/*
function myMCEChange(textblock, elem) { document.getElementById(elem).innerHTML=textblock.getBody().innerHTML;}
function showTitle(str, elem){ document.title = str;
	document.getElementById(elem).innerHTML=str;}
function showItemTitle(str, elem) { document.getElementById(elem).innerHTML=str; }
function showHint(str, elem) { document.getElementById(elem).innerHTML=str; }
*/

//////////////////////////////////
/*
function OnUpload()
{
	document.TheForm.action = "index.php?action=upload";
	document.TheForm.submit();
	return true;
}
function OnNewItem()
{
	document.TheForm.action = "index.php?action=new";
	document.TheForm.submit();
	return true;
}
function OnDeleteItem()
{
	document.TheForm.action = "index.php?action=delete";
	document.TheForm.submit();
	return true;
}
function OnSave()
{
	document.TheForm.action = "index.php?action=save";
	document.TheForm.submit();
	return true;
}
function OnSelectItem()
{
	document.TheForm.action = "index.php?action=select";
	document.TheForm.submit();
	return true;
}
function OnPreview()
{
	document.TheForm.action = "index.php?action=preview";
	document.TheForm.submit();
	return true;
}
function OnNoAction()
{
	document.TheForm.action = "index.php";
	document.TheForm.submit();
	return true;
}


	
function OnSendMail(emlfile, mail_to, mail_from, mail_subject)
{
	var emailbox = document.getElementById("EMAILAREA");
	var newmail = '';
	var email = emailbox.value;
	var emailsArray = email.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
	if (emailsArray)
	{
		for (var i = 0; i < emailsArray.length; i++)
		{
			if (i!=0) newmail = newmail + ', ';
			newmail = newmail + emailsArray[i];
		}
	}
	emailbox.value = newmail;
	document.TheForm.action = "mailscript.php?action=sendmail";
	document.TheForm.target = "ed_mailWindow";
	document.TheForm.submit();
}
*/
