
function check_heb(str) {
	var heb_exp = /[א-ת]/i;
	return heb_exp.test(str);
}

function change_dir() {
	var obj = window.event.srcElement;
		
	if (obj.isContentEditable) {
		if (check_heb(obj.value)) {
			obj.style.direction = "rtl";
		} else {
			obj.style.direction = "ltr";
		}
	}
}

function change_input_dir() {
	
	var i;

	for(i = 0; i < document.all.length; i++){
		if (document.all(i).tagName == "INPUT") {
		
			var obj = document.all(i);
		
			if (obj.isContentEditable) {
				if (check_heb(obj.value)) {
					obj.style.direction = "rtl";
				} else {
					obj.style.direction = "ltr";
				}
			
			}
		}
	}
}

function validate_input() {

	var v_exp = /['=]/i;
	var obj = window.event.srcElement;

		if ((obj.tagName == "INPUT") || (obj.tagName == "TEXTAREA")) {
			if (v_exp.test(obj.value)) {
				alert("התווים (') ו- (=) אינם חוקיים");
				obj.select();
			}
		}
		
}

function highlight_edit() {
	//var obj = window.event.srcElement;
	var obj = window.event ? window.event.srcElement : null;
     if (!obj) {
          return;
     }

	if ((obj.isContentEditable) || (obj.tagName == "SELECT")) {
		//obj.onfocus = function (){
			//obj.style.backgroundColor = "#f6f4ea"; 
			//};
			if (obj.onblur == null) {
				obj.onblur = validate_input;
			}
		
		//obj.attachEvent ('onblur', validate_input);

	}
}

function change_css(css){
	
	var obj;
	if ((window.event.srcElement.tagName == "TD") || (window.event.srcElement.tagName == "INPUT") || (window.event.srcElement.tagName == "SELECT")) {
		obj = window.event.srcElement;
	} else {
		//alert(window.event.srcElement.parentElement.tagName);
		obj = window.event.srcElement.parentElement;
	}
	obj.className = css;
}
			
function roll_off(css){
	var obj;
	if (window.event.srcElement.tagName == "TD") {
		obj = window.event.srcElement;
	} else {
		obj = window.event.srcElement.parentElement;
	}
	window.event.srcElement.className = css;
}

function go_to(url){
	document.location = url;
}

var hint_layer;
var iIntervalID;
var hint_msg;
var caller_obj;
var hint_x,hint_y;

function display_hint(msg){
	
	hint_msg = "<div align=right>" + msg + "</div>";
	hint_x = window.event.x + document.body.scrollLeft + 15;
	hint_y = window.event.y + document.body.scrollTop + 20;
	
	window.event.srcElement.onmousemove = span_move;
	
	if (hint_layer == null) {
		iIntervalID = window.setInterval("draw_span()",300);
	} else {
		if (hint_layer.style.visibility == "hidden") {
			iIntervalID = window.setInterval(function () {hint_layer.style.visibility = "visible";},300);
		}
	}
}

function draw_span(){
	
	if (hint_layer == null) {
		
		hint_layer = document.createElement("SPAN");
		hint_layer.innerHTML = hint_msg;
		hint_layer.style.position = "absolute";
		hint_layer.style.backgroundColor = "#F1EEE0"
		hint_layer.style.padding = 3;
		hint_layer.style.borderBottom = "2px solid #666666"
		hint_layer.style.borderTop = "1px solid #666666"
		hint_layer.style.borderRight = "2px solid #666666"
		hint_layer.style.borderLeft = "1px solid #666666"
		hint_layer.style.zIndex = 100;
		hint_layer.style.left = hint_x;
		hint_layer.style.top = hint_y;
		
		document.body.appendChild(hint_layer);

	}
	
}

function span_move(){
	if (hint_layer != null) {
		hint_layer.innerHTML = hint_msg;
		hint_layer.style.left = window.event.x + document.body.scrollLeft + 15;
		hint_layer.style.top = window.event.y + document.body.scrollTop + 20;
	}
}

function remove_hint(){

	window.clearInterval(iIntervalID);
	iIntervalID="";
	
	if (hint_layer != null) {
		hint_layer.style.visibility = "hidden";
	}

}

function open_popup(theURL,w,h,window_name) {
	features="product_browser.aspx','toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h;
	window.open(theURL,window_name,features);
}

function getCookie(c_name) {
if (document.cookie.length>0) {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    	return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function setCookie(c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}




var modalName = 'modalWindow';

function show_warning_modal(wn)
{
	
	if (wn != undefined) {
		modalName = wn;
	}
	
	$(modalName).style.display = $('modalBackground').style.display = 'block';
	$(modalName).setOpacity(0);
	$(modalName).fade(0,1);
	$('modalBackground').setOpacity(0);
	$('modalBackground').fade(0,0.40);
	
	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		//var type = $('hideType').value;
		
		//if (type == 'iframe')
		//	$('modalIframe').style.display = 'block';
		//if (type == 'replace')
		//	ReplaceSelectsWithSpans();
	}

	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}

function OnWindowResize()
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = $(modalName);
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}

function RemoveSelectSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}

function close_warning_modal()
{
	$(modalName).style.display = $('modalBackground').style.display = 'none';
	return;
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		//var type = $('hideType').value;
		
		//if (type == 'iframe')
		//	$('modalIframe').style.display = 'none';
		//if (type == 'replace')
			//RemoveSelectSpans();
	}
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
}

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}

function openpagepop(page_id) {
	document.getElementById('modaliframe').src = 'page.aspx?page_id='+page_id+'&show_page_template=no';
	show_warning_modal('modalWindow');
}


	
	
