  

function checkSearchForm()
{
	str=document.getElementById('sStr').value.length;
	emailFiled=document.getElementById('email').value;
	skillSlct=document.getElementById('skill');
	if(str<2 && emailFiled=="" && skillSlct.selectedIndex==0)
	{
		alert("אנא מלא לפחות שני תווים בשם, או בחר מיומנות.");
		return false;
	}
	else
		return true;
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCountField=document.getElementById(limitCount);
		limitCountField.innerHTML = limitNum - limitField.value.length;
		if((limitNum - limitField.value.length) < 11)
			limitCountField.style.color="red";
		else
			limitCountField.style.color="black";
			} 
}
 

function switchMainEvent(hide_div,show_div)
{
		document.getElementById(hide_div).style.display='none';
		document.getElementById(show_div).style.display='block';
}
function open_q(qDiv)
{
	opened=document.getElementById("opened_q");
	toClose=opened.value;
	if(toClose!="")
	{
		toCloseDiv=document.getElementById(toClose);
	}
	toOpen=document.getElementById(qDiv);
	toOpen.style.display="block";
	if(toClose!="")
		toCloseDiv.style.display="none";
	opened.value=qDiv;
	
}


function submitEditPicForm(actionBtn)
{
	
	if(actionBtn=="delete")
	{
		if(!confirm('האם האתה בטוח?'))
			return false;
	}
	if(actionBtn=="edit")
	{
		document.getElementById('editPics').action="addPictures.php?editPic=1";
	}
	
	document.getElementById('editPics').submit();
}

function updatePic(pid, aid, dir)
{
	url='ajax/getPicture.php?dir='+dir+'&aid='+aid+'&pid='+pid+'&of=מ&next=הבא&previous=הקודם';
	url=encodeURI(url);
	ret=LoadHTML(url);
	
	picDiv=document.getElementById('pictureDiv');
	picDiv.innerHTML=ret;
	updatePicTalkbacks(pid,dir);
}
function createSendToUsersArray()
{
	sendToUsersList=document.getElementById("sendToList");
	myForm=document.getElementById("sendMessageForm");
	for( var x = 0; sendToUsersList.childNodes[x]; x++ )
	{
		var field=document.createElement('input');
		field.type='hidden';
		field.name='sndToVal[]';
		field.value=sendToUsersList.childNodes[x].id;
		myForm.appendChild(field);
	}
	return true;
}

function showHideUsersList(link)
{
	list=document.getElementById("usersList");
	if(list.style.display=="none")
	{
		list.style.display="block";
		link.innerHTML='סגור רשימת חברים';
	}
	else
	{
		list.style.display="none";
		link.innerHTML='פתח רשימת חברים';
	}
}

function removeSendToUser(obj, uid)
{
	li=obj.parentNode;
	ul=li.parentNode;
	ul.removeChild(li);
	li_list=document.getElementById('userList_'+uid);
	li_list.style.display='block';
} 
function addSendToUser(obj, uid, userName)
{
	obj.style.display='none';
	ul=document.getElementById("sendToList");
	ul.innerHTML+="<li id='"+uid+"'>"+userName+"<a href='javascript:void(0)' onclick='removeSendToUser(this,\""+uid+"\");'></a></li>";
}

function getVisionPic(dir,uid)
{
	curPic=document.getElementById('pic_id').value;
	url='ajax/getVision.php?dir='+dir+'&uid='+uid+'&curPic='+curPic;
	ret=LoadHTML(url);
	picDiv=document.getElementById('visionPic');
	picDiv.innerHTML=ret;
	
}

function switchEventsGroupTabs(activateDiv)
{
	if(activateDiv=='event')
	{
		document.getElementById('groupTabSelected').style.display='none';
		document.getElementById('groupsList').style.display='none';
		document.getElementById('eventTabSelected').style.display='block';
		document.getElementById('eventsList').style.display='block';
	}
	else
	{
		document.getElementById('groupTabSelected').style.display='block';
		document.getElementById('groupsList').style.display='block';
		document.getElementById('eventTabSelected').style.display='none';
		document.getElementById('eventsList').style.display='none';
	}


}
function deletePicTalkback(id,pid)
{
	if(confirm('האם האתה בטוח?')){
	url='ajax/deletePicTalkback.php?id='+id+'&pid='+pid+'&delete=מחק&sendComment=שלח תגובה';
	url=encodeURI(url);
	ret=LoadHTML(url);
	talkbackDiv=document.getElementById('talkBackBlocks');
	talkbackDiv.innerHTML=ret;
	}
}

function addPicComment(pid)
{
	talkback=document.getElementById('addTalkback').value;
	url='ajax/addPicTalkback.php?pid='+pid+'&talkback='+talkback+'&writeAcomment=כתוב תגובה...&delete=מחק&sendComment=שלח תגובה&langid=1';
	url=encodeURI(url);
	ret=LoadHTML(url);
	talkbackDiv=document.getElementById('talkBackBlocks');
	talkbackDiv.innerHTML=ret;
}

function updatePicTalkbacks(pid,dir)
{
	talkback=document.getElementById('addTalkback').innerHTML;
	url='ajax/getPicTalkbacks.php?pid='+pid+'&talkback='+talkback+'&writeAcomment=כתוב תגובה...&delete=מחק&sendComment=שלח תגובה&langid=1&dir='+dir;
	url=encodeURI(url);
	ret=LoadHTML(url);
	talkbackDiv=document.getElementById('talkBackBlocks');
	talkbackDiv.innerHTML=ret;
}


function removeMeFromGroup(group_id)
{
	url="ajax/removeMeFromGroup.php?group="+group_id;
	ret=LoadHTML(url);
	document.location.reload(true);

}
function addMeToGroup(group_id)
{
	url="ajax/addMeToGroup.php?group="+group_id;
	ret=LoadHTML(url);
	document.location.reload(true);

}

function updateComingFriends(event)
{
	ret="";
	url="ajax/updateComingFriends.php?event="+event+ "&dummy=" + new Date().getTime();
	ret=LoadHTML(url);
	document.getElementById('eventWillCome_List').innerHTML="";
	document.getElementById('eventWillCome_List').innerHTML=ret;
	url="ajax/updateMayComingFriends.php?event="+event+ "&dummy=" + new Date().getTime();
	ret=LoadHTML(url);
	document.getElementById('eventMayCome_List').innerHTML="";
	document.getElementById('eventMayCome_List').innerHTML=ret;
}

function rsvpThis(what,event, updateComing){
	

	url='ajax/rsvp.php?'+'e='+event+'&r='+what+"&dummy=" + new Date().getTime();;
	LoadHTML(url);
	if(updateComing)
		updateComingFriends(event);

	
	return false;
}

function addManualSkill()
{
	manualSkills=document.getElementById('manualSkill').value;
	url="ajax/addSkill.php?skill="+manualSkills+"&lang=1";
	url=encodeURI(url);
	ret=LoadHTML(url);
}

function createSkillsArray()
{
	mySkillsList=document.getElementById("mySkills");
	myForm=document.getElementById("settingForm");
	for( var x = 0; mySkillsList.childNodes[x]; x++ )
	{
		var field=document.createElement('input');
		field.type='hidden';
		field.name='skillsVal[]';
		field.value=mySkillsList.childNodes[x].id;
		myForm.appendChild(field);
	}
	return true;
}

function showHideSkillsList(link)
{
	list=document.getElementById("skillsList");
	if(list.style.display=="none")
	{
		list.style.display="block";
		link.innerHTML='סגור רשימת מיומניות';
	}
	else
	{
		list.style.display="none";
		link.innerHTML='הוסף מיומניות';
	}
}

function removeSkill(obj, skill_id)
{
	li=obj.parentNode;
	ul=li.parentNode;
	ul.removeChild(li);
	li_list=document.getElementById('skillList_'+skill_id);
	li_list.style.display='block';
} 
function addSkill(obj, skill_id, skill_name)
{
	obj.style.display='none';
	ul=document.getElementById("mySkills");
	ul.innerHTML+="<li id='"+skill_id+"'>"+skill_name+"<a href='javascript:void(0)' onclick='removeSkill(this,\""+skill_id+"\");'></a></li>";
}

function checkUploadPicForm()
{
	if(document.getElementById("pic").value=="")
	{
		alert("אנא בחר קובץ תמונה להעלאה");
		return false;
	}
	else
		return true;
}

function updateCroods(pos)
{
	document.getElementById("posX").value=pos.x;
	document.getElementById("posY").value=pos.y;
	document.getElementById("posW").value=pos.w;
	document.getElementById("posH").value=pos.h;
}


function searchFriends(sStr,uid,friendPerPage)
{
	url="ajax/getFriends.php?uid="+uid+"&friendPerPage="+friendPerPage+"&addFriendText=הוסף חבר&removeFriendText=הסר חבר&skillsText=מיומנויות&langid=1&sStr="+sStr;
	url=encodeURI(url);
	ret=LoadHTML(url);
	document.getElementById('friendList').innerHTML=ret;
}

function checkUserName(username){

	if(username=="") return true;
	if(username.indexOf(" ")>0)
	{
		document.getElementById("userNameError").innerHTML='שם משתמש אינו אמור להכיל רווחים';
		document.getElementById("userNameError").style.display='block';
		return false;
	}
	if(username=="")
	{
		document.getElementById("userNameError").innerHTML='חובה למלא שם משתמש';
		document.getElementById("userNameError").style.display='block';
		return false;
	}
	url="ajax/checkusername.php?u="+username;
	ret=LoadHTML(url);
	if(ret=="1")
	{
		document.getElementById("userNameError").innerHTML='שם משתמש תפוס';
		document.getElementById("userNameError").style.display='block';
		return false;
	}
	document.getElementById("userNameError").style.display='none';
}


function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}


function removeFriend(uid, friend)
{
	if(confirm('האם האתה בטוח?'))
	{
		url="ajax/removeFriend.php?uid="+uid+"&friend="+friend;
		ret=LoadHTML(url);
		page=document.getElementById('pageNumVal').value;
		friendPerPage=document.getElementById('friendPerPageVal').value;
		totalFriends=document.getElementById('totalFriendsVal').value;
		totalFriends=totalFriends-1;
		document.getElementById('totalFriendsVal').value=totalFriends;
		document.getElementById('totalFriendsSpan').innerHTML="("+totalFriends+")";
		updateFriendPage(uid,page,friendPerPage, totalFriends);
		updateFriendPageNum(uid,page,friendPerPage, totalFriends)
	}
}
function addFriend(uid, friend, linkDiv)
{
	url="ajax/addFriend.php?uid="+uid+"&friend="+friend;
	ret=LoadHTML(url);
	linkDiv.className='awaitingConfirm';
	linkDiv.innerHTML='מחכה לאישור החבר';
}
function updateFriendPageNum(uid,page,friendPerPage, totalFriends)
{
	url="ajax/getFriendsPageNums.php?uid="+uid+"&page="+page+"&friendPerPage="+friendPerPage+"&totalFriends="+totalFriends+"&selectPageText=בחר עמוד&langid=1";
	url=encodeURI(url);
	ret=LoadHTML(url);
	document.getElementById('pageNum').innerHTML=ret;

}

function updateFriendPage(uid,page,friendPerPage, totalFriends)
{
	url="ajax/getFriends.php?uid="+uid+"&page="+page+"&friendPerPage="+friendPerPage+"&addFriendText=הוסף חבר&removeFriendText=הסר חבר&skillsText=מיומנויות&langid=1&totalFriends="+totalFriends;
	url=encodeURI(url);
	ret=LoadHTML(url);
	document.getElementById('friendList').innerHTML=ret;
	updateFriendPageNum(uid,page,friendPerPage, totalFriends)
	document.getElementById('pageNumVal').value=page;
}

function deleteWorldMsg(msg_id, obj)
{
	if(confirm('האם האתה בטוח?'))
	{
		url="ajax/deleteWorldMsg.php?msg="+msg_id;
		ret=LoadHTML(url);
		node=obj.parentNode.parentNode;
		ul=node.parentNode;
		ul.removeChild(node);
		updateLastMessage();
		updateTotalMessages()
	}
	

}
function checkLoginForm()
{
	myform=document.getElementById("loginForm");
	if(document.getElementById("login_username").value=="")
	{
		alert("אנא מלא דוא\"ל");
		document.getElementById("login_username").focus();
		return false;
	}
	if(document.getElementById("login_password").value=="")
	{
		alert("אנא מלא סיסמה");
		document.getElementById("login_password").focus();
		return false;
	}
	return true;
	
}

function forgetPassword()
{
	username=document.getElementById("login_username").value;
	if(username=="")
	{
		alert("אנא הזינו דואר אלקטרוני");
		document.getElementById("login_username").focus();
		return false;
	}
	else
	{
		url="ajaxSendForgotPassword.php?username="+username;
		ret=LoadHTML(url); 
		alert(ret);
			
	}
}


function switchLoginTab(activeForm)
{
	if(activeForm=='login')
	{
		document.getElementById("signupFormDiv").style.display="none";
		document.getElementById("loginFormDiv").style.display="block";
		document.getElementById("leftTabs").style.display="none";
		document.getElementById("rightTabs").style.display="block";
	}
	else
	{
		document.getElementById("signupFormDiv").style.display="block";
		document.getElementById("loginFormDiv").style.display="none";
		document.getElementById("leftTabs").style.display="block";
		document.getElementById("rightTabs").style.display="none";
	}
	

}

function getTime()
{
	
	url="ajax/getTime.php";
	ret=LoadHTML(url);
	document.getElementById("clock").innerHTML=ret;
	setTimeout("getTime();",10000);
}

function preloader() 
{
heavyImage = new Image(); 
heavyImage.src = "images/grayBtn_clicked.png";
heavyImage = new Image(); 
heavyImage.src = "images/greenBtn_clicked.png";
heavyImage = new Image(); 
heavyImage.src = "images/checkbox-marked.png";
}

function changeCheck(checkImg, checkId) 
{
	checkVal=document.getElementById(checkId);
	
	if(checkVal.value=="1")
	{
		checkVal.value="0";
		checkImg.className="checkBoxOff";		
	}
	else
	{
		checkVal.value="1";
		checkImg.className="checkBoxOn";		
		
	}
	
}

function cleartextarea(f, val)
{	
	if(f.innerHTML==val)
	{
		f.innerHTML='';
	}
}

function updateTotalMessages()
{
	url="ajax/getWorldTotalMsg.php";
	ret=LoadHTML(url);
	document.getElementById('worldMsgTotal').innerHTML=ret;
	
}
function updateLastMessage()
{
	url="ajax/getWorldMsg.php";
	ret=LoadHTML(url);
	document.getElementById('worldMsgBody').innerHTML=ret;

	
}

function sendWorldMsg()
{
	msg=document.getElementById("status").value;
	if(msg=="" || msg=="כתוב פה")
	{
		alert('אנא כתוב מסר לעולם');
		return false;
	}
	document.getElementById('worldMsgBody').innerHTML=msg;
	msg=encodeURI(msg); 
	url="ajax/sendWorldMsg.php?msg="+msg+"&dummy=dsa";
	ret=LoadHTML(url);
	document.getElementById("status").innerHTML='';
	document.getElementById("countLetters").innerHTML='140';
	updateTotalMessages();
	document.getElementById('publishTime').innerHTML='נכתב עכשיו';
	if(document.getElementById('worldMsgsList'))
	{
		ul=document.getElementById('worldMsgsList');
		url="ajax/getLastWorldMsg.php?lang="+1;
		ret=LoadHTML(url);
		ul.innerHTML=ret+ul.innerHTML; 
	}
}

function clearField(f, val)
{	
	if(f.value==val)
	{
		f.value='';
		f.style.color='black';
	}
}


// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkChar(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode<48 || (cCode>57 &&cCode < 65) || (cCode > 90 && cCode<97) || cCode>122 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}


function passwordChanged() {
		var weakDiv = document.getElementById('weak');
		var normalDiv = document.getElementById('normal');
		var strongDiv = document.getElementById('strong');
		
		var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
		var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
		var enoughRegex = new RegExp("(?=.{0,}).*", "g");
		var pwd = document.getElementById("password");
		if (pwd.value.length==0) {
			weakDiv.style.background="white";
			normalDiv.style.background="white";
			strongDiv.style.background="white";
		}  else if (strongRegex.test(pwd.value)) {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="url(images/yellow.gif)";
			strongDiv.style.background="url(images/green.gif)";
		} else if (mediumRegex.test(pwd.value)) {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="url(images/yellow.gif)";
			strongDiv.style.background="white";
		} else {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="white";
			strongDiv.style.background="white";
		}
	}
function checkEmail(email) {

	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	} else {
		return true;
	}
}
function checkEmailExist(email)
{	
	if(email=="") return true;
	ret=ajaxCheckEmail(email);
	if(ret=="1")
	{
		document.getElementById("emailError").innerHTML='כתובת הדוא"ל כבר רשומה באתר';
		document.getElementById("emailError").style.display='block';
		return false;
	}
	

}
function ajaxCheckEmail(email)
{
	url="ajax/checkEmail.php?email="+email;
	ret=LoadHTML(url);
	return ret;
}

function checkHowToForm() {

	myform=document.getElementById('registerform');
	send = true;
	errormessage = "הבעיות הבאות נתגלו בטופס:\r\n";		
	if (document.getElementById("firstname").value=="" || document.getElementById("firstname").value=="First") {		
		send = false;
		errormessage += "שם פרטי\r\n";
	}
	if (document.getElementById("lastname").value=="" || document.getElementById("lastname").value=="Last") {		
		send = false;
		errormessage += "שם משפחה\r\n";
	}
	
	
		if (document.getElementById("email").value=="" || !checkEmail(document.getElementById("email").value)) {	
		send = false;
		errormessage += "דואר אלקטרוני שגוי\r\n";
	} 
	else
	{
		
	if(ajaxCheckEmail(document.getElementById("email").value)=="1")
	{
		send = false;
		errormessage += 'כתובת הדוא"ל כבר רשומה באתר\r\n';
	
	}
		
		
	}
	
	if (document.getElementById("username").value=="") {		
		send = false;
		errormessage += "שם משתמש\r\n";
	}
	else {
		
		url="ajax/checkusername.php?u="+document.getElementById("username").value;
			ret=LoadHTML(url);
			if(ret=="1")
			{
				send = false;
				errormessage += "שם משתמש תפוס\r\n";
			} 
		
	}
	
	if (document.getElementById("password").value=="") {		
		send = false;
		errormessage += "סיסמה שגוייה\r\n";
	}
	
	
	
	

	
	
	
	
		if (!document.getElementById("allpolicy").value) {
			send = false;
			errormessage += "הסכמיי המדיניות והפרטיות \r\n";
		}
	
	if (send) {
		return true;
	} else {
		alert(errormessage);
		return false;
	}
}


function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	
	xmlHttp.send(null);
	return xmlHttp.responseText;
}
function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, true);
	xmlHttp.setRequestHeader("Accept-Charset","UTF-8");
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}
function openSelect(arrow)
{
	slct=arrow.parentNode.childNodes[0];
	slct.click();	
 
}
    function setForm() {
    	return false; 
      var s = document.getElementsByTagName('select');
      for (var i=0; i<s.length; i++) {
      	var curSelect=s[i];
  		var container=document.createElement('div');
  		container.className="selectContainer";  		
  		curSelect.parentNode.appendChild(container);
  		container.appendChild(curSelect);
  		var arrow=document.createElement('div');
  		arrow.onclick=function(){ openSelect(this)};
        arrow.className="selectArrow";
        container.appendChild(arrow);

      }
    }

  