// JavaScript Document
function showFilter(url)
{
	
	if($('filter_content_status').innerHTML!="") return;
	if($('button_show_filter').src.indexOf("plus.gif")>0)
	{

		Effect.SlideDown('filter_content', { duration: 1.0 });

		$('button_show_filter').src="/images/minus.gif";
	}else{
		Effect.SlideUp('filter_content', { duration: 1.0 });
		$('button_show_filter').src="/images/plus.gif";			
	}
}


function editPage(id,w,h, caption)
{
	if(id=="picturepage")
	{
		$('noeditor').value = "true";	
	}
	
	if(caption=="")
	hs.htmlExpand($(id), { objectType: 'ajax', preserveContent: false, width: w, height: h, align: 'center', captionText: 'ניהול תוכן הושימה', captionOverlay: 
		{ position: 'top right', width: '220px'} } )	
	
	else
	hs.htmlExpand($(id), { objectType: 'ajax', preserveContent: false, width: w, height: h, align: 'center', captionText: caption, captionOverlay: 
		{ position: 'top right', width: '220px'} } )	
}
function editframePage(id,w,h, caption)
{
	if(id=="picturepage")
	{
		$('noeditor').value = "true";	
	}
	
	if(caption=="")
	hs.htmlExpand($(id), { objectType: 'iframe', preserveContent: false, width: w, height: h, align: 'center', captionText: 'ניהול תוכן הושימה', captionOverlay: 
		{ position: 'top right', width: '220px'} } )	
	
	else
	hs.htmlExpand($(id), { objectType: 'iframe', preserveContent: false, width: w, height: h, align: 'center', captionText: caption, captionOverlay: 
		{ position: 'top right', width: '220px'} } )	
}

function initAdmin()
{

	elems = $$("#toedit");
	elems.each( function (value){
		value.setStyle({cursor: 'pointer'});				  
	});	

}
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 

function changeCultureContent(elem)
{

	contents = $$("div.content_fr");

contents.each( function (value){
		value.hide();				  
	});
	contents = $$("div.content_en");
	contents.each( function (value){
		value.hide();				  
	});
	contents = $$("div.content_he");
	contents.each( function (value){
		value.hide();				  
	});

	contents = $$("div.content_"+elem.value);
	contents.each( function (value){
		value.show();				  
	});
	
}
function refresh_content()
{
	alert("the product has been uploaded");
	if($('new_content').innerHTML=="")return;
	if($('cur_cat').value!=$('new_cur_cat').value) return;
    $('ProductLeft').innerHTML += $('newProductLeft').innerHTML;
	$('ProductRight').innerHTML += $('newProductRight').innerHTML;
}
function serial(elem)
{
	$(elem+"fr").value = tinyMCE.get("t_"+elem+"fr").getContent();
	$(elem+"en").value = tinyMCE.get("t_"+elem+"en").getContent();
	$(elem+"he").value = tinyMCE.get("t_"+elem+"he").getContent();	
	tinyMCE.execCommand("mceRemoveControl", false, "t_"+elem+"he");
	tinyMCE.execCommand("mceRemoveControl", false, "t_"+elem+"fr");
	tinyMCE.execCommand("mceRemoveControl", false, "t_"+elem+"en");	

	
}
function unloadw()
{

tinyMCE.execCommand('mceFocus', false, 'txaEditableContent'); 
tinyMCE.execCommand('mceRemoveControl', false, 'txaEditableContent');

var container = document.getElementById('TINYMCE_CONTAINER');
var tinyNode = document.getElementById('TINYMCEPANE');
container.removeChild(tinyNode);	

}

function validateAllArchi()
{
	error="1";
	if(!validateit("lastname")) error="0";
	if(!validateit("tel")) error="0";
	if(!validateit("pass")) error="0";
	if(!validateit("firstname")) error="0";
	if(!validateit("cf")) error="0";	
	if($("cf").value!=$("pass").value)
	{
		alert("The confirmation does not match the password");	
		return false;
	}
	if(!IsEmail("email")) error="0";

	if(error=="0")
	{
		alert($('errmsg').innerHTML);	
		return false;
	}
	return true;
}

function validateAllContact()
{
	error="1";
	if(!validateit("lastname")) error="0";
	if(!validateit("tel")) error="0";
	if(!IsEmail("email")) error="0";
	if(!validateit("comments")) error="0";	
	if(error=="0")
	{
		alert($('errmsg').innerHTML);	
		return false;
	}
	return true;
}

function validateAll()
{
	error="1";
	if(!validateit("name")) error="0";
	if(!validateit("numres")) error="0";

	if(!IsEmail("email")) error="0";
	if(error=="0")
	{
		alert($('errmsg').innerHTML);	
		return false;
	}
	return true;
}

function validateit(id)
{
		
	if($(id).value=="")
	{
			
		$(id).highlight();
		$(id).setStyle({backgroundColor: '#FF0000'});	
		return false;
	}
	else
	{
		$(id).setStyle({backgroundColor: '#FFFFFF'});	
		return true;
	}

}
function IsEmail(elem)
{
		
		Expression = $(elem).value;
        if (Expression == null)
                return (false);

        var supported = 0;
        if (window.RegExp)
        {
                var tempStr = "a";
                var tempReg = new RegExp(tempStr);
                if (tempReg.test(tempStr)) supported = 1;
        }
	
        if (!supported)
                return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
        var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
        var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		
		if(!r1.test(Expression) && r2.test(Expression)) return true;
		else
		{
				
		$(elem).highlight();
		
		$(elem).setStyle({backgroundColor: '#FF0000'});	
			//$(elem).focus();
		return; 
		}
		$(elem).setStyle({backgroundColor: '#FFFFFF'});	
			
        return (!r1.test(Expression) && r2.test(Expression));
}
	var m = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
		var t = new Array();
		
		function showit(adr) 
		{
			clearTimeout(t[adr]);
			m[adr]+=5;	
			
			document.getElementById("button"+adr+"_on").style.opacity = m[adr]/100;
			document.getElementById("button"+adr+"_on").style.filter="alpha(opacity="+m[adr]+")";
			t[adr] = setTimeout("showit("+adr+")",5);
			if (m[adr]>98) clearTimeout(t[adr]);
		}
		
		function hideit(adr) 
		{
			clearTimeout(t[adr]);
			m[adr]-=5;	
			document.getElementById("button"+adr+"_on").style.opacity = m[adr]/100;
			document.getElementById("button"+adr+"_on").style.filter="alpha(opacity="+m[adr]+")";
			t[adr] = setTimeout("hideit("+adr+")",5);
			if (m[adr]<2) clearTimeout(t[adr]);
		}


	function fadeit(elem, out)
	{
/*		$(elem).fade({from: 1.0, to: 0.0, duration: 0.4});
		$(out).appear({from: 0.0, to: 1.0, duration: 0.4});		
*/		$(elem).hide()
		$(out).show();
	}
	function fadeout(elem, out)
	{
/*		$(elem).appear({from: 0.0, to: 1.0, duration: 1.0});
		$(out).fade({from: 1.0, to: 0.0, duration: 1.0});				
*/		$(out).hide()
		$(elem).show();

}	
