// if not using document.write JS can be called from the bottom of the page... recommended for faster pages load.

function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}

// start rakSearch.js
// this is the ajax search engine

$(function() {
	function format(item) {
		return "<img border='0' src='/get.php?met=img&id="+item.id+"&w=29&h=36'/> "+item.name;
	}
	$("#sJ").autocomplete('/get.php?met=getJsonCoachs&active=1', {
		multiple: false,
		parse: function(data) {
			return $.map(eval(data), function(row) {
				return {
					data: row
				}
			});
		},
		formatItem: function(item) {
			return format(item);
		}
	}).result(function(e, item) {
		//$("#content").append("<p>selected " + format(item) + "</p>");
		var sTargetURL = 'coach.php?id='+item.id;
		window.location.href = sTargetURL;
	});
});

// end rakSearch.js

// start dialogwindow.js
var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';

 function ModalDialogShow(file,width,height)
 {

    ModalDialog.value = '';
    ModalDialog.eventhandler = '';
	
    var args='width='+width+',height='+height+',left=325,top=300,toolbar=0,';
       args+='location=0,status=0,menubar=0,scrollbars=1,resizable=0';  

   ModalDialogWindow=window.open(file,"",args); 
   ModalDialogWindow.focus();

 }
// end dialogwindow.js
// start xmlload.js
var getphone=0;
function ShowCPhone(cId){
	if (getphone==0){
		$("#showphone").html("בדרך...");
		$.ajax({type:"POST",
					url:"get.php",
					dataType: "json",
					data: "met=coachPhone&cid="+cId,
			success: function(data){
				getphone=1;
				$("#showphone").html(data.phone);
			}
		});
	}
}
function checkEmail(eml){
	if (emailcheck(eml) == false) { document.getElementById('addcoach').disabled='disabled';return; }
	var objLink = document.getElementById("div_email");
	objLink.style.display='block';
	$("#div_email").html("בודק זמינות דואר אלקטרוני...");
	$.ajax({type:"POST",
				url:"get.php",
				dataType: "json",
				data: "met=checkEmail&eml="+eml,
		success: function(data){
			if (data.success == 1) {objLink.innerHTML="<div style='color:green'>כתובת האימייל תקינה</div>";document.getElementById('addcoach').disabled='';}
			if (data.success == 0) {objLink.innerHTML='כתובת האימייל אינה חוקית';document.getElementById('addcoach').disabled='disabled';}
		}
	});
}
function getSubCategories(check,id,name,select){
	var editAnafs = document.getElementById('editAnafs');
	$.ajax({type:"POST",
				url:"get.php",
				dataType: "json",
				data: "met=subCats&catId="+id,
		success: function(data){
			if (check.checked == true || select != null) {
				var success = data.success
				if (success == '1') {
					var selectid = null;
					var divHTML = '<div id="subs'+id+'">תת קטגוריות ב <b>'+name+'</b>: <input type="hidden" name="subids[]" id="anaf'+id+'"><select id="sel'+id+'" onchange="addthisid(this.value,'+id+');">';
					$.each(data.subcategory, function(i,subcat){
						var needtoselect = null;
						var sub_id = subcat.id;
						var sub_name = subcat.name;
						var addids = null;
						if (select != null) {
							if (sub_id in oc(select)) {
								needtoselect = ' selected';
								if (sub_id != 'null') {
									selectid=sub_id;
								}
							}
						}
						divHTML += '<option value="'+sub_id+'"'+needtoselect+'>'+sub_name+'</option>';
					});
					divHTML += '</select></div>';
					$("#subs_div").append(divHTML);
					if (selectid != null) {
						var subcats = document.getElementById('anaf'+id);subcats.value = selectid;
					}
				}
			} else if (check.checked == false) {
				if (document.getElementById('subs'+id) != null) {
					var el = document.getElementById('subs'+id);
					el.parentNode.removeChild(el);
				}
			}
			if (document.getElementById('editAnafs')) {
				editAnafs.innerHTML = "ערוך";
			}
		}
	});
}
function addthisid(cat_id,id){var subcats = document.getElementById('anaf'+id);subcats.value = cat_id;}
function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}
var Subclicked=0;