// JavaScript Document
function IMG_ON(obj){
	obj.src=obj.src.replace('.' + getEXT(obj.src),'_on.' + getEXT(obj.src));
}
function IMG_OFF(obj){
	obj.src=obj.src.replace('_on.' + getEXT(obj.src),'.' + getEXT(obj.src));
}
//Picks file extantion
function getEXT(str){
	str=str.split('.');
	ext=str[str.length -1];
	return ext;
}

ComponentPics=new Array();

function Fade(objID,CurrentAlpha,TargetAlpha,steps){
	var obj = document.getElementById(objID);
	
	CurrentAlpha = parseInt(CurrentAlpha);
	if (isNaN(CurrentAlpha)){
		  CurrentAlpha = parseInt(obj.style.opacity*100);
		  if (isNaN(CurrentAlpha))CurrentAlpha=100;
	}
	
	var DeltaAlpha=parseInt((CurrentAlpha-TargetAlpha)/steps);
	var NewAlpha = CurrentAlpha - DeltaAlpha;
	
	obj.style.opacity = (NewAlpha / 100);
	obj.style.MozOpacity = obj.style.opacity;
	obj.style.filter = 'alpha(opacity='+NewAlpha+')';
	
	if (steps>1) setTimeout('Fade("'+objID+'",'+NewAlpha+','+TargetAlpha+','+(steps-1)+')', 1);
	else{
		if(objID=='ComponentImg' && NewAlpha==0){
			obj.src=ComponentPics[curMask];
			Fade('ComponentImg',0,100,ComponentfadeSteps);
		}
	}
}
var fadeSteps=20;
function fadeOut(ID){
	Fade(ID,100,80,fadeSteps);
}
function fadeIn(ID){
	Fade(ID,80,100,fadeSteps);
}

var curMask=5;
var T;
var ComponentfadeSteps=20;
function nextMask(ID){
	if(ID>0 && ID==curMask) return;
	
	Fade('ComponentImg',100,0,ComponentfadeSteps);
	document.getElementById('Mask'+curMask).className='';
	if(ID==0){
		curMask++;
		if(curMask>5) curMask=1;
	}
	else{
		clearInterval(T);
		curMask=ID;
	}
	var obj = document.getElementById('Mask'+curMask);
	obj.className='On';
	str = obj.lang;
	if(obj.lang) document.getElementById('Info').innerHTML=str;
	else document.getElementById('Info').innerHTML='';
}

window.onload=function(){
	if(document.getElementById('ComponentImg')){
		nextMask(0);
		T=setInterval("nextMask(0);",4000);
	}
}
var http;

if (window.ActiveXObject){
    http = new ActiveXObject("Microsoft.XMLHTTP");
}
// for other browsers
else if (window.XMLHttpRequest) {
    http = new XMLHttpRequest();
}

function vote(){
	var curPost=0;
	obj = document.forms['Votes'].elements['vt'];
	for(var i=0; i<obj.length; i++){
		if(obj[i].checked) curPost=i+1;
	}
	if(curPost<=0) alert('נא לבחור תשובה');
	else{
		curPost++;
		//alert('OK-'+curPost);
		var url="includes/Seker.php";
		var params = 'id='+curPost+'&sid='+Math.random();
		http.open("POST", url, true);
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				document.getElementById('SekerInner').innerHTML=http.responseText;
			}
		}
		http.send(params);
		return false;
	}
}
function voteBack(){
	var curPost=0;
	//alert('OK-'+curPost);
	var url="includes/Seker.php";
	var params = 'id='+curPost+'&sid='+Math.random();
	http.open("POST", url, true);
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('SekerInner').innerHTML=http.responseText;
		}
	}
	http.send(params);
	return false;
}


//Validator

function echeck(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
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    
	    return false
	 }

		 return true					
}


function validForm(cont) {
	if (cont.Name.value == "") {
		alert("נא להזין שם מלא");
		cont.Name.focus();
		cont.Name.select();
		return false;
	}
	if (cont.Mail.value == "" || !echeck(cont.Mail.value)) {
		alert("נא להזין כתובת מייל תקינה");
		cont.Mail.focus();
		cont.Mail.select();
		return false;
	}
	document.cont.submit();
	return true;
}

var message="Right click is not allowed";
///////////////////////////////////
function clickIE()

{if (document.all)
{(message);return false;}}

function clickNS(e) {
if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")

