$j(document).ready(function() {

	if ($j.timeEntry != undefined) {
		// Define defaults for all timeentry fields
		$j.timeEntry.setDefaults({
			spinnerImage: '',
			show24Hours: true
		});
	}

	if ($j.datepick != undefined) {
		// Define defaults for all datepick fields
		$j.datepick.setDefaults({
			showAnim: 'fadeIn',
			showOnFocus: false,
			dateFormat: 'yyyy-mm-dd',
			showTrigger: '<img src="images/calendar.gif" alt="Popup">'
		});
	}

});

function goAjax(){
	var req = false;
	try {
		req = new XMLHttpRequest(); /* e.g. Firefox */
	}
	catch(err1) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */
		}
		catch(err2) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP"); /* some versions IE */
			}
			catch(err3) {
				req = false;
			}
		}
	}
	return req;
}

/*
	var content = FCKeditorAPI.GetInstance('content_'+id).GetXHTML();
*/

function send_news(){
	window.location = "send_newsletter.php?id="+document.getElementById("news").value;
}
function no(){
	window.location="send_newsletter.php";
}
function yes(id){
		window.location="send_newsletter.php?yes=1&id="+id;
}

//
function edit_event(id){
	window.open("edit_event.php?event_id="+id,"","width=780,height=650,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_product(id){
	window.open("edit_product.php?package_id="+id,"","width=780,height=550,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_feature(pid, id){
	window.open("edit_feature.php?product_id="+pid+"&id="+id,"","width=780,height=300,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_banner(id){
	window.open("edit_banner.php?banner_id="+id,"","width=780,height=600,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_page(id){
	window.open("edit_page.php?page_id="+id,"","width=780,height=550,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_role(id){
	window.open("edit_role.php?role_id="+id,"","width=450,height=240,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_blog_article(id){
	window.open("edit_blog_article.php?blog_article_id="+id,"","width=780,height=600,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_blog_category(id){
	window.open("edit_blog_category.php?id="+id,"","width=550,height=200,status=0,menu=0,scrollbars=1,resizable=1");
}
function new_show_guest(id){
	window.open("new_episode_guest.php?id="+id,"","width=500,height=400,status=0,menu=0,scrollbars=1,resizable=1");
}
function rerun_episode(id){
	window.open("rerun_episode.php?id="+id,"","width=400,height=370,status=0,menu=0,scrollbars=1,resizable=1");
}
function copy_episode(id){
	window.open("copy_episode.php?id="+id,"","width=780,height=650,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_episode(id){
	window.open("edit_episode.php?id="+id,"","width=780,height=650,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_episode_guest(id){
	window.open("edit_episode_guest.php?id="+id,"","width=500,height=400,status=0,menu=0,scrollbars=1,resizable=1");
}
function contact_edit(id){
	window.open("edit_contact.php?id="+id,"","width=780,height=580,status=0,menu=0,scrollbars=1,resizable=1");
}
function program_edit(id){
	window.open("edit_program.php?id="+id,"","width=780,height=600,status=0,menu=0,scrollbars=1,resizable=1");
}
function station_edit(id){
	window.open("edit_station.php?id="+id,"","width=600,height=350,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_program_templates(id){
	window.open("edit_program_templates.php?id="+id,"","width=600,height=280,status=0,menu=0,scrollbars=1,resizable=1");
}
function article_edit(id){
	window.open("edit_article.php?id="+id,"","width=780,height=550,status=0,menu=0,scrollbars=1,resizable=1");
}
function view_article(id){
	window.open("view_article.php?id="+id,"","width=780,height=550,status=0,menu=0,scrollbars=1,resizable=1");
}
function view_results(id){
	window.open("web_poll_results.php?id="+id,"","width=400,height=400,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_program_modes(id){
	window.open("edit_program_modes.php?id="+id,"","width=550,height=280,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_newsletter(id){
	window.open("edit_newsletter.php?id="+id,"","width=780,height=600,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_question(id){
	window.open("edit_question.php?id="+id,"","width=780,height=420,status=0,menu=0,scrollbars=1,resizable=1");
}
function edit_member(id){
	window.open("edit_member.php?id="+id,"","width=780,height=420,status=0,menu=0,scrollbars=1,resizable=1");
}
function import_members(){
	window.open("import_members.php","","width=400,height=280,status=0,menu=0,scrollbars=1,resizable=1");
}
function export_members(){
	window.open("export_members.php","","width=400,height=280,status=0,menu=0,scrollbars=1,resizable=1");
}
//
function collapseInit(setcookie){
	$j('.collapse_toggle').click(function() {
		var collapse_id = $j(this).parents('.collapse').attr('id');
		var collapse_toggle_id = $j(this).attr('id');
		var collapse_body_id = $j('#'+collapse_id+' .collapse_body').attr('id');
		$j('#'+collapse_body_id).slideToggle(300, function(){
			if (setcookie == true) {
				if ($j('#'+collapse_body_id).is(':hidden')) {
					$j.cookie(collapse_body_id, 1); // 1 = hide
				} else {
					$j.cookie(collapse_body_id, 0); // 0 = show
				}
			}
			collapseChangeLink(collapse_body_id, collapse_toggle_id);
		});
		return false;
	});
}
//
function collapseChangeLink(section, trigger){
	// Change link text based on div state
	if ($j('#'+section).is(':hidden')) {
		var txt = "[show]";
	} else {
		var txt = "[hide]";
	}
	$j('#'+trigger).html(txt);
}
//
function password_strength(field, min){
	var pw = $j('#'+field).val();
	if (pw.length > 0) { // Check only if characters entered
		$j.get("ax_password_strength.php", { pw: pw }, 
			function(data){
				var txt = 'Accepted! ';
				if (data < min && min > 0){
					txt = 'Too weak! ';
					$j('#'+field+'_strength').addClass("notif_error_text");
				}
				if (data >= min && min > 0){
					$j('#'+field+'_strength').removeClass("notif_error_text");
				}
				txt = txt + ' Score: ' + data;
				if (min > 0) txt = txt + ' (min. '+min+')';
				$j('#'+field+'_strength').html(txt);
			}
		);
	}
}
//
function delete_contact_checkroles(id){
	var x = goAjax();
	var url = "ax_delete_contact_checkroles.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.readyState==4){
			if (x.responseText>0){
				if (confirm("WARNING: This contact has " + x.responseText + " role(s) throughout the system that will be removed as well.\nPlease confirm this modification!")){
					delete_contact(id);
				}
			} else {
				delete_contact(id);
			}
		}
	}
	x.send(null);
}
//
function delete_contact(id){
	if(confirm("Are you sure that you want to delete this contact?")){
	var x = goAjax();
	var url = "ax_delete_contact.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_member(id){
	if(confirm("Are you sure that you want to delete this member?")){
		$j.get("ax_delete_member.php", { id: id }, 
			function(data){
				if(data=="ok"){
					refresh_and_close(closepopup=true, newurl=null);
				}
			}
		);
	}
}
//
function delete_question(id){
	if(confirm("Are you sure that you want to delete this question?")){
	var x = goAjax();
	var url = "delete_question.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_article(id){
	if(confirm("Are you sure that you want to delete this article?")){
	var x = goAjax();
	var url = "delete_article.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_program(id){
	if(confirm("Are you sure that you want to delete this program?")){
		if (confirm("WARNING: All episodes, topics, articles assigned to this program will be deleted. Are you sure?")){
			$j.get("ax_delete_program.php", { id: id }, 
				function(data){
					if(data=="ok"){
						refresh_and_close(closepopup=true, newurl=null);
					}
				}
			);
		}
	}
}
//
function delete_newsletter(id){
	if(confirm("Are you sure that you want to delete this newsletter issue?")){
		$j.get("ax_delete_newsletter.php", { id: id }, 
			function(data){
				if(data=="ok"){
					refresh_and_close(closepopup=true, newurl=null);
				}
			}
		);
	}
}
//
function delete_station(id){
	if(confirm("Are you sure that you want to delete this radio station?")){
		if (confirm("WARNING: It may be assigned to programs. Are you sure?")){
		var x = goAjax();
		var url = "delete_station.php?id="+id;
		x.open("GET",url,true);
		x.onreadystatechange = function(){
			if(x.responseText=="ok"){
				refresh_and_close(closepopup=true, newurl=null);
			}
		}
		x.send(null);
		}
	}
}
//
function delete_event(id){
	if(confirm("Are you sure that you want to delete this event?")){
	var x = goAjax();
	var url = "delete_event.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_product(id){
	if(confirm("Are you sure that you want to delete this product?")){
	var x = goAjax();
	var url = "delete_product.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_feature(id){
	if(confirm("Are you sure that you want to delete this feature?")){
	var x = goAjax();
	var url = "delete_feature.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_banner(id){
	if(confirm("Are you sure that you want to delete this banner?")){
	var x = goAjax();
	var url = "delete_banner.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_page(id){
	if(confirm("Are you sure that you want to delete this page?")){
	var x = goAjax();
	var url = "ax_delete_page.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_role(id){
	if(confirm("Are you sure that you want to delete this role?")){
	var x = goAjax();
	var url = "ax_delete_role.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_blog_category(id){
	if(confirm("Are you sure that you want to delete this blog category?")){
		if (confirm("WARNING: All articles inside this category will be uncategorized. Are you sure?")){
		var x = goAjax();
		var url = "ax_delete_blog_category.php?id="+id;
		x.open("GET",url,true);
		x.onreadystatechange = function(){
			if(x.responseText=="ok"){
				refresh_and_close(closepopup=true, newurl=null);
			}
		}
		x.send(null);
		}
	}
}
//
function delete_blog_article(id){
	if(confirm("Are you sure that you want to delete this blog article?")){
	var x = goAjax();
	var url = "ax_delete_blog_article.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_show(id){
	if(confirm("Are you sure that you want to delete this episode and any existing re-runs?")){
	var x = goAjax();
	var url = "ax_delete_episode.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function delete_rerun(id,date){
	if(confirm("Are you sure that you want to delete this episode re-run?")){
	var x = goAjax();
	var url = "ax_delete_rerun.php?id="+id+"&date="+date;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			window.location.reload();
		}
	}
	x.send(null);
	}
}
//
function remove_guest(gid,sid){
	if(confirm("Are you sure that you want to remove this guest?")){
	var x = goAjax();
	var url = "ax_remove_guest.php?gid="+gid+"&sid="+sid;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			window.location.reload();
		}
	}
	x.send(null);
	}
}
//
function delete_order(id){
	if(confirm("Are you sure that you want to delete this order request?")){
	var x = goAjax();
	var url = "delete_order.php?id="+id;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			window.location.reload();
		}
	}
	x.send(null);
	}
}
//
function suspend_hostacc(username){
	if(confirm("Are you sure that you want to suspend this web host?")){
		if (confirm("WARNING: The account cannot be used until unsuspended. Are you sure?")){
		var acc = goAjax();
		var url = "suspend_hostacc.php?username="+username;
		acc.open("GET",url,true);
		acc.onreadystatechange = function(){
			if(acc.responseText=="ok"){
				window.location.reload();
			}
		}
		acc.send(null);
		}
	}
}
//
function unsuspend_hostacc(username){
	if(confirm("Are you sure that you want to unsuspend this web host?")){
	var acc = goAjax();
	var url = "unsuspend_hostacc.php?username="+username;
	acc.open("GET",url,true);
	acc.onreadystatechange = function(){
		if(acc.responseText=="ok"){
			window.location.reload();
		}
	}
	acc.send(null);
	}
}
//
function remove_file(id, type, name){
	if(confirm("Are you sure that you want to remove this file?")){
	var x = goAjax();
	var url = "ax_remove_file.php?id="+id+"&type="+type+"&name="+name;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			refresh_and_close(closepopup=true, newurl=null);
		}
	}
	x.send(null);
	}
}
//
function edit_eventc(id){
	document.getElementById("cat_normal_"+id).style.display="none";
	document.getElementById("cat_edit_"+id).style.display="block";
	document.getElementById("display_normal_"+id).style.display="none";
	document.getElementById("display_edit_"+id).style.display="block";
	document.getElementById("butoane_normal_"+id).style.display="none";
	document.getElementById("butoane_edit_"+id).style.display="block";
}
//
function cancel_eventc(id){
	document.getElementById("cat_normal_"+id).style.display="block";
	document.getElementById("cat_edit_"+id).style.display="none";
	document.getElementById("display_normal_"+id).style.display="block";
	document.getElementById("display_edit_"+id).style.display="none";
	document.getElementById("butoane_normal_"+id).style.display="block";
	document.getElementById("butoane_edit_"+id).style.display="none";
}
//
function save_event_categ(id){
	if(document.getElementById("form_"+id).category.value=="")
	alert("Please fill the 'Category name' field.");
	else
	if(document.getElementById("form_"+id).display.value!="Yes" && document.getElementById("form_"+id).display.value!="No")
	alert("Please fill the display field with 'Yes' or 'No'!");
	else
	document.getElementById("form_"+id).submit();
}
//
function appendOptionLast(vfield,vtext,vvalue)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = vtext;
  elOptNew.value = vvalue;
  var elSel = vfield;
  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}
//
function change_featuretype(p){
	document.getElementById('blk_interview').style.display="none";
	document.getElementById('blk_sponsorship').style.display="none";
	document.getElementById('blk_newsletter').style.display="none";
	document.getElementById('blk_website').style.display="none";
	document.getElementById('blk_'+p).style.display="block";
}
//
function refresh_and_close(closepopup, newurl){
	if (window.parent.opener && window.parent.opener.open && !window.parent.opener.closed) {
		if (newurl) {
			window.parent.opener.location = newurl;
		}
		else {
			window.parent.opener.location.reload();
		}
		if (window.parent && window.parent.open && !window.parent.closed && closepopup) window.parent.close();
	}
	else if (window.opener && window.opener.open && !window.opener.closed) {
		if (newurl) {
			window.opener.location = newurl;
		}
		else {
			window.opener.location.reload();
		}
		if (window && window.open && !window.closed && closepopup) window.close();
	}
	else {
		if (newurl) {
			window.location = newurl;
			//window.parent.location = newurl; // For iframes
		}
		else {
			window.location.reload();
			//window.parent.location.reload(); // For iframes
		}
	}
}
//
function poll_answer_add(){
	var aa = document.getElementById('additionalanswers');
	var numi = document.getElementById('answers_lastkey');
	var num = (document.getElementById('answers_lastkey').value - 1) + 2;
	numi.value = num;

	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','divanswer'+num);
	newdiv.setAttribute('class','divanswer');
	newdiv.setAttribute('style','border-bottom:1px solid #ffffff;');
	newdiv.innerHTML = '<input type="text" id="answers[]" name="answers[]" />&nbsp;<a href="#" onclick="poll_answer_remove(\''+'divanswer'+num+'\')">Remove</a>';
	aa.appendChild(newdiv);
}
//
function poll_answer_remove(div){
	if(confirm("Are you sure that you want to remove this answer?")){
		var aa = document.getElementById('additionalanswers');
		var olddiv = document.getElementById(div);
		aa.removeChild(olddiv);
	}
}
//
function episode_guest_add(){
	var aa = document.getElementById('additionalguests');
	var numi = document.getElementById('guests_lastkey');
	var num = (document.getElementById('guests_lastkey').value - 1) + 2;
	numi.value = num;

	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','divguest'+num);
	newdiv.setAttribute('class','divguest');
	newdiv.setAttribute('style','border-bottom:1px solid #ffffff;');
	newdiv.innerHTML = '';

	var tmp = '<table border="0">';
	tmp = tmp+'<tr><td><table cellspacing="0" cellpadding="0" border="0"><tr><td><select name="guests['+num+']" id="guests['+num+']">';
	for (var j = 0; j < guest_def_k.length; j++) {
		tmp = tmp+'<option value="'+guest_def_k[j]+'">'+guest_def_v[j]+'</option>';
	}
	tmp = tmp+'</select></td><td>'
	tmp = tmp+'<select name="guests_roles['+num+']" id="guests_roles['+num+']">';
	for (var j = 0; j < role_def_k.length; j++) {
		tmp = tmp+'<option value="'+role_def_k[j]+'">'+role_def_v[j]+'</option>';
	}
	tmp = tmp+'</select></td><td width="100%"><a href="#" onclick="episode_guest_remove(\'divguest'+num+'\')">Remove Guest</a></td></tr></table></td></tr>';

	tmp = tmp+'<tr><td>';
	for (var j = 0; j < station_def_k.length; j++) {
		tmp = tmp+'<table cellspacing="0" cellpadding="2" border="0" class="st'+station_def_k[j]+'"><tr><td align="left">'+station_def_v[j]+'</td></tr><tr><td align="left"><table cellspacing="0" cellpadding="0" border="0"><tr><td>Between</td>';
		tmp = tmp+'<td><input type="text" class="timee {minTime: \''+station_def_st[j]+'\', maxTime: \''+station_def_et[j]+'\'}" name="guests_start_time['+num+']['+station_def_k[j]+']" id="guests_start_time['+num+']['+station_def_k[j]+']" value="" /></td><td>and</td>';
		tmp = tmp+'<td><input type="text" class="timee {minTime: \''+station_def_st[j]+'\', maxTime: \''+station_def_et[j]+'\'}" name="guests_end_time['+num+']['+station_def_k[j]+']" id="guests_end_time['+num+']['+station_def_k[j]+']" value="" /></td>';
		tmp = tmp+'</tr></table></td></tr></table>';
	}
	tmp = tmp+'</td></tr>';
	tmp = tmp+'<tr><td><table width="100%" cellspacing="0" cellspacing="0" border="0"><tr><td nowrap="nowrap" style="padding-right:2px;">Audio file:</td><td width="100%">\n';
	tmp = tmp+'<script type="text/javascript">\n';
	tmp = tmp+'var upload_current_'+num+' = \'\';\n';
	tmp = tmp+'var upload_filter_'+num+' = \'mp3\';\n';
	tmp = tmp+'</script>\n';
	tmp = tmp+'<iframe id="upload_frame_'+num+'" src="ax_file_upload.php?id='+num+'" frameborder="no" scrolling="no" class="upload_frame"><p>Your browser does not support iframes.</p></iframe>';
	tmp = tmp+'<input type="hidden" name="upload_file_'+num+'" id="upload_file_'+num+'" />';
	tmp = tmp+'</td></tr></table></td></tr></table>';
	newdiv.innerHTML = newdiv.innerHTML+tmp;

	aa.appendChild(newdiv);
	$j('.timee').timeEntry(); // Add timeentry
	hide_inactive_stations();
}
//
function episode_guest_remove(div){
	if(confirm("Are you sure that you want to remove this guest?")){
		var aa = document.getElementById('additionalguests');
		var olddiv = document.getElementById(div);
		aa.removeChild(olddiv);
	}
}
//
function program_station_add(){
	var aa = document.getElementById('additionalstations');
	var numi = document.getElementById('stations_lastkey');
	var num = (document.getElementById('stations_lastkey').value - 1) + 2;
	numi.value = num;

	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','divstation'+num);
	newdiv.setAttribute('class','divstation');
	newdiv.setAttribute('style','border-bottom:1px solid #ffffff;');
	newdiv.innerHTML = '';

	var tmp = '<table border="0">';
	tmp = tmp+'<tr><td><table cellspacing="0" cellpadding="0" border="0"><tr><td><select name="stations['+num+']" id="stations['+num+']">';
	for (var j = 0; j < station_def_k.length; j++) {
		tmp = tmp+'<option value="'+station_def_k[j]+'">'+station_def_v[j]+'</option>';
	}
	tmp = tmp+'</select></td>';
	if (num > 1) tmp = tmp+'<td><a href="#" onclick="program_station_remove(\'divstation'+num+'\')">Remove Station</a></td>';
	tmp = tmp+'</tr></table></td></tr>';

	tmp = tmp+'<tr><td><table cellspacing="0" cellpadding="0" border="0"><tr><td>From</td>';
	tmp = tmp+'<td><input type="text" class="datep" name="stations_start_date['+num+']" id="stations_start_date['+num+']" /></td>';
	tmp = tmp+'<td>to</td>';
	tmp = tmp+'<td><input type="text" class="datep" name="stations_end_date['+num+']" id="stations_end_date['+num+']" /></td>';
	tmp = tmp+'</tr></table></td></tr>';

	tmp = tmp+'<tr><td><table cellspacing="0" cellpadding="0" border="0"><tr><td>Between</td>';
	tmp = tmp+'<td><input type="text" class="timee" name="stations_start_time['+num+']" id="stations_start_time['+num+']" /></td>';
	tmp = tmp+'<td>and</td>';
	tmp = tmp+'<td><input type="text" class="timee" name="stations_end_time['+num+']" id="stations_end_time['+num+']" /></td>';
	tmp = tmp+'<td><select name="stations_time_zone['+num+']" id="stations_time_zone['+num+']">';
	for (var j = 0; j < time_zone_def_k.length; j++) {
		tmp = tmp+'<option value="'+time_zone_def_k[j]+'">'+time_zone_def_v[j]+'</option>';
	}
	tmp = tmp+'</select></td>';
	tmp = tmp+'</tr></table></td></tr>';

	tmp = tmp+'<tr><td><table cellspacing="0" cellpadding="0" border="0"><tr>';
	for (var j = 0; j < week_days_def_k.length; j++) {
		tmp = tmp+'<td><input type="checkbox" name="stations_week_days['+num+']['+week_days_def_k[j]+']" id="stations_week_days['+num+']['+week_days_def_k[j]+']" value="'+week_days_def_k[j]+'" /></td><td><label for="stations_week_days['+num+']['+week_days_def_k[j]+']">'+week_days_def_v[j]+'</label></td>';
	}
	tmp = tmp+'</tr></table></td></tr>';
	tmp = tmp+'</table>';
	newdiv.innerHTML = newdiv.innerHTML+tmp;

	aa.appendChild(newdiv);
	$j('.datep').datepick(); // Add datepick
	$j('.timee').timeEntry(); // Add timeentry
}
//
function program_station_remove(div){
	if(confirm("Are you sure that you want to remove this station?")){
		var aa = document.getElementById('additionalstations');
		var olddiv = document.getElementById(div);
		aa.removeChild(olddiv);
	}
}
//
function getMultiple(ob){ // Return array from select multiple
	selected = new Array(new Array(), new Array());
	for (var i = 0; i < ob.options.length; i++)
		if (ob.options[i].selected){
			selected[0].push(ob.options[i].value);
			selected[1].push(ob.options[i].text);
		}
	return selected;
}
//
function roleseditor_change_role() {
	var selObj = document.getElementById('roleseditor_selected');
	var selIndex = selObj.selectedIndex;
	var selValue = selObj.options[selIndex].value;

	for (var j = 0; j < role_def_k.length; j++) {
		document.getElementById('roleseditor_'+role_def_k[j]).style.display = 'none';
	}

	document.getElementById('roleseditor_'+selValue).style.display = 'block';
}
//
function roleseditor_remove_role(gid,sid,pid,rid){
	if(confirm("Are you sure that you want to remove this role?")){
	var x = goAjax();
	var url = "ax_remove_role.php?gid="+gid+"&sid="+sid+"&pid="+pid+"&rid="+rid;
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			window.opener.location.reload();
			window.location = 'edit_contact.php?id='+gid;
		}
	}
	x.send(null);
	}
}
//
function roleseditor_add_role(gid,rid){
	if(confirm("Are you sure that you want to add this role?")){
	var selObj = document.getElementById('pidsid_'+rid);
	var selIndex = selObj.selectedIndex;
	var selValue = selObj.options[selIndex].value;

	var sidpid = selValue.split(":");

	var x = goAjax();
	var url = "ax_add_role.php?gid="+gid+"&pid="+sidpid[0]+"&rid="+rid;
	if (sidpid[1]) url = url+"&sid="+sidpid[1];
	x.open("GET",url,true);
	x.onreadystatechange = function(){
		if(x.responseText=="ok"){
			window.opener.location.reload();
			window.location = 'edit_contact.php?id='+gid;
		}
	}
	x.send(null);
	}
}
//
function hide_inactive_stations(){
	var show_date = $j('#show_date').val();

	for (var i = 0; i < station_def_k.length; i++) {
		if (show_date >= station_def_sd[i] && show_date <= station_def_ed[i]) {
			$j('.st'+station_def_k[i]).show();
		}
		else {
			$j('.st'+station_def_k[i]).hide();
		}
	}
}
//
function moveupdownInit() {
	// Hide move up / down links on first / last
	$j('.move_up').show().filter(':first').hide();
	$j('.move_down').show().filter(':last').hide();
}
//
function moveupdown() {
	$j('.move_up, .move_down').click(function(event) {
		var $target = $j(event.target);
		var $parent = $target.closest('.moveable');
		// Get the editor data
		var $data = $parent.find('.ckeditor').val();
		($target.hasClass('move_up')) ? $parent.insertBefore($parent.prev()) : $parent.insertAfter($parent.next());       
		// Set the editor data
		$parent.find('.ckeditor').val($data);
		moveupdownInit(); // Reset links
		return false;
	});
}
//
function activate_newsletter_section(section){
	var currentstate = $j('#section_active_'+section).val();
	if (currentstate == '1') {
		$j('#section_active_'+section).val('0');
		$j('#app_actions_'+section+' a.accept').text('Activate');
		$j('#app_actions_'+section).parent().addClass('highlight1');
	}
	else {
		$j('#section_active_'+section).val('1');
		$j('#app_actions_'+section+' a.accept').text('Deactivate');
		$j('#app_actions_'+section).parent().removeClass('highlight1');
	}
}
//
function remove_newsletter_section(section){
	if (confirm("Are you sure that you want to remove this section? Warning: No undo possible.")) {
		$j('#collapse_'+section).remove();
		moveupdownInit();
	}
}
//
function getdata_newsletter_section(type,section){
	var date1 = $j('#date1_'+section).val();
	var date2 = $j('#date2_'+section).val();
	var dloading = $j('#dloading_'+section);
	if (confirm("Are you sure? Warning: The existing content (if any) will be replaced.")) {
		dloading.show();
		$j.get("ax_getdata_newsletter_section.php", { type: type, date1: date1, date2: date2 }, 
			function(data){
				if(data!=""){
					CKEDITOR.instances['section_body_'+section].setData(data, function(){
						dloading.hide();
					});
				}
			}
		);
	}
}
//
