function GetComboData( ComboID, Name, Table, Src, SrcValue, addOther )
{ 
 var combo = document.getElementById(ComboID);
 var retArr = new Array();
 var myAjax = new Ajax.Request(
   'getdata.asp?Name='+Name+'&Table='+Table+'&Src='+Src+'&SrcValue='+SrcValue,
   {
    method: 'get', 
    onComplete: function(response) { 
     retArr=response.responseText.split(';');
     combo.options.length=1;
     for(i=0; i< (retArr.length/2)-1; i++){
      combo.options[i+1] = new Option(retArr[2*i], retArr[2*i+1]);
     }
	 if (addOther) {
	  combo.options[i+1] = new Option('Other...', '-1');
	 }
     combo.selectedIndex=0;
     
    }
    
   }
   );
}

function GetComboDataList( ComboID, Name, Table, Src, SrcValue, isclients )
{ 
 var combo = document.getElementById(ComboID);
 var retArr = new Array();
 var showNumOfClients = 0
 var myAjax = new Ajax.Request(
   'getdata.asp?Name='+Name+'&Table='+Table+'&Src='+Src+'&SrcValue='+SrcValue+'&showNumOfClients='+isclients,
   {
    method: 'get', 
    onComplete: function(response) { 
	 //alert(response.responseText);
     retArr=response.responseText.split(';');
     combo.options.length=0;
     for(i=0; i< (retArr.length/2)-1; i++){
      combo.options[i] = new Option(retArr[2*i], retArr[2*i+1]);
     }
	 if (ismap) { showAddress(); }
     //combo.selectedIndex=0;
     
    }
    
   }
   );
}

function updateGoogleMap( Name, Table, Src, SrcValue )
{
	 var retArr = new Array();
	 var myAjax = new Ajax.Request(
	   'getCordinates.asp?Name='+Name+'&Table='+Table+'&Src='+Src+'&SrcValue='+SrcValue,
	   {
		method: 'get', 
		onComplete: function(response) { 
		 //alert(response.responseText);
		 retArr=response.responseText.split(';');
		 var lat = parseFloat(retArr[0]);
		 var lng = parseFloat(retArr[1]);
		 var zoom = parseInt(retArr[2]);
		 var map = new google.maps.Map2(document.getElementById("map"));
		 map.setCenter(new google.maps.LatLng(lat, lng), zoom);
		 map.addControl(new GLargeMapControl());
		 map.addControl(new GScaleControl());
		 map.addControl(new GMapTypeControl());
		 //combo.selectedIndex=0;
		 
		}
		
	   }
	   );
}

function filterData(strURL)
{
	var oSelect = window.event.srcElement;
	var strName = oSelect.name;
	var strValue = oSelect.options[oSelect.selectedIndex].value;
	strURL += "&" + strName + "=" + strValue;
	window.location.replace(strURL);
}

function setVacancy( BusinessID, RoomID, dDate ){ 

	var myAjax = new Ajax.Request(
   'setBusinessDate.asp?BusinessID='+BusinessID+'&RoomID='+RoomID+'&Date='+dDate,
   {
    method: 'get', 
    onComplete: function(response) { 
     msg=response.responseText;
     alert(msg);
    }
    
   }
   );
}

function menuclick(id)
{
	var div = document.getElementById("div" + id);
	if (div.style.display == "none")
		div.style.display = "block";
	else
		div.style.display = "none";
}

function changeamount(id, change)
{
	obj = document.getElementById("prod" + id);
	if (obj.value > 0)
		obj.value = parseFloat(obj.value) + change;
	else if (change == 1)
		obj.value = 1;
	else if (change == 0.5)
		obj.value = 0.5;
}

function addtocart(bid,id)
{
	amount = document.getElementById("prod" + id).value;
	if (amount == "")
		alert("נא לבחור כמות להזמנה ממוצר זה. השתמש ב(+) ו(-) לשינוי הכמות.");
	else
		location.href = "addtocart.asp?BusinessID=" + bid + "&ProductID=" + id + "&Amount=" + amount + "&BackURL=" + location.href.replace("&", "%26");
}

function checkCatalog(oForm)
{
	if (oForm.Products.checked)
		return true;
	for(i = 0; i < oForm.Products.length; i++)
		if (oForm.Products[i].checked)
			return true;
	alert("יש לסמן לפחות מוצר אחד");
	return false;
}

function submitSearch(obj)
{
	if (obj.Search.value == "" && obj.CategoryID.selectedIndex == 0)
	{
		alert("יש לבחור קטגוריה");
		return false;
	}
	if (obj.Search.value == "" && obj.AreaID.selectedIndex == 0)
	{
		alert("יש לבחור אזור");
		return false;
	}
	return true;
}

function redirectSearch(obj)
{
	oForm = obj.form;
	if (oForm.query.value == "")
	{
		alert("יש לרשום מילת חיפוש");
		return false;
	}
	for (i=0; i<oForm.rdSearchSite.length; i++)
		if (oForm.rdSearchSite[i].checked)
		{
			location.href = oForm.rdSearchSite[i].value + oForm.query.value;
			return true;
		}
	alert("יש לבחור מנוע חיפוש");
	return false;
}


/*function window.onscroll()
{
	obj = document.getElementById("sidebanner");
	if (!obj) return;
	obj.style.top = document.body.scrollTop;
}*/

function printPage()
{
	args = "top=100, left=100, height=500, width=700, status=no, toolbar=no, menubar=no, scrollbars=yes, location=no";
	window.open("print.asp", "Print", args);
}

function showHide(id)
{
	oDiv = document.getElementById(id);
	if (oDiv)
	{
		if (oDiv.style.display == "none")
		{
			oDiv.style.display = "block";
		}
		else
		{
			oDiv.style.display = "none";
		}
	}
}

function show(id)
{
	oDiv = document.getElementById(id);
	oDiv.style.display = "block";
}

function hide(id)
{
	oDiv = document.getElementById(id);
	oDiv.style.display = "none";
}

function openproduct(id,bid)
{
	var args = "left=300, top=200, width=450, height=450, status=no, toolbar=no, menubar=no, scrollbars=yes, location=no";
	window.open("showproduct.asp?ProductID=" + id + "&BusinessID=" + bid, "", args);
}

function openproduct2(num,bid)
{
	var args = "left=300, top=200, width=450, height=450, status=no, toolbar=no, menubar=no, scrollbars=yes, location=no";
	window.open("showproduct2.asp?PhotoNum=" + num + "&BusinessID=" + bid, "", args);
}

function upload(path, key)
{
	args = "top=200, left=300, height=150, width=400, status=no, toolbar=no, menubar=no, scrollbars=no, location=no";
	window.open("upload.asp?path=" + path + "&key=" + key, "Upload", args);
}

function update(fileName, key)
{
	var pic = document.getElementById(key);
	pic.value = fileName;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
 
function showOther(obj, name)
{
	if (obj.value == 'Other') { document.getElementById('Other'+name).style.display = 'block'; }
	else { document.getElementById('Other'+name).style.display = 'none';  document.getElementById('Other'+name).value = ''; }
}
function setSelectionType(obj)
{
	var num = parseInt(obj.value);
	var oForm = document.mailbox;
	var checkbox = oForm.selected;
	var checkboxread = oForm.selectedRead;
	
	for (i=0; i < checkbox.length; i++)
	{
		switch (num)
		{
		case 1:
		  checkbox[i].checked = false;
		  break;
		case 2:
			if (checkboxread[i].value == "True") {
				checkbox[i].checked = true;
			}
			else {
				checkbox[i].checked = false;
			}
		    break;
		case 3:
			if (checkboxread[i].value == "False") {
				checkbox[i].checked = true;
			}
			else {
				checkbox[i].checked = false;
			}
		    break;
		case 4:
			checkbox[i].checked = true;
		    break;
		default:
		    obj.selectedIndex = 0;
		}
	}
	obj.selectedIndex = 0;
}

function submitMailForm(action)
{
	var oForm = document.mailbox;
	oForm.Action.value=action;
	oForm.submit()	
}

function openWin(url)
{
	NewWindow(url,'ChatWindow','660','420','no','center');
}
function NewWindow(mypage,myname,w,h,scroll,pos){
var	win;
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}

var totalLangs = 1
function addLang()
{
	currentLang = totalLangs-1;
	
	if (document.getElementById('OtherLanguageID'+currentLang).selectedIndex == 0)
	{
		document.getElementById('OtherLanguageID_err').innerHTML = 'You must choose a language first';
		return;
	}
	else
	{
		oForm = document.RegisterForm;
		var levelCount = 0;
		var objLevel = eval("oForm.LanguageLevelID"+currentLang);
		for (i=0; i<objLevel.length; i++) 
		{
			if (objLevel[i].checked == true) { levelCount++; }
		}
		if (levelCount == 0)
		{
			document.getElementById('OtherLanguageID_err').innerHTML = 'You must choose a language level';
			return;
		}
		document.getElementById('OtherLanguageID_err').innerHTML = '';
	}
	if (navigator.userAgent.indexOf("Firefox")!=-1)
		document.getElementById('Lang'+totalLangs).style.display = "";
	else
		document.getElementById('Lang'+totalLangs).style.display = 'block';
	totalLangs++;
}
function subLang()
{
	if (totalLangs > 1)
	{
		totalLangs--;
		if ( totalLangs > 0 )
		{
			document.getElementById('OtherLanguageID'+totalLangs).selectedIndex = 0;
			document.getElementById('Lang'+totalLangs).style.display = 'none';
		}
		else
		{
			totalLangs++;
			alert('Can not remove fist line');	
		}
	}
}
var totalMembers = 1
function addMember()
{
	document.getElementById('Member'+totalMembers).style.display = 'inline';	
	totalMembers++;
}
function subMember()
{
	if (totalMembers > 1)
	{
		totalMembers--;
		if ( totalMembers > 1 )
		{
			document.getElementById('MemberName'+totalMembers).value = '';
			document.getElementById('MemberBirthYear'+totalMembers).selectedIndex = 0;
			document.getElementById('Member'+totalMembers).style.display = 'none';
		}
		else
		{
			totalMembers++;
			alert('Can not remove fist line');	
		}
	}
}
var totalPhotos = 1
function addPhoto()
{
	if (!document.getElementById('Photo'+totalPhotos)) {
		alert("You can't add more Photos");
		return;
	}
	document.getElementById('Photo'+totalPhotos).style.display = 'block';
	document.getElementById('Photo'+totalPhotos).style.display = 'table-row';
	totalPhotos++;
}
function subPhoto()
{
	if (totalPhotos > 1)
	{
		totalPhotos--;
		document.getElementById('PhotoVal'+totalPhotos).value = '';
		document.getElementById('Photo'+totalPhotos).style.display = 'none';
	}
	document.getElementById('TotalPhotos').value = totalPhotos;
}
var albumtotalPhotos = 1
function addAlbumPhoto()
{
	if (!document.getElementById('Photo'+albumtotalPhotos)) {
		alert("You can't add more Photos");
		return;
	}
	document.getElementById('AlbumPhoto'+albumtotalPhotos).style.display = 'block';	
	albumtotalPhotos++;
}
function subAlbumPhoto()
{
	if (albumtotalPhotos > 1)
	{
		albumtotalPhotos--;
		document.getElementById('AlbumPhoto'+albumtotalPhotos).value = '';
		document.getElementById('AlbumPhoto'+albumtotalPhotos).style.display = 'none';
	}
	document.getElementById('AlbumTotalPhotos').value = albumtotalPhotos;
}

function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8);
}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode;
 if (charCode > 31 && (charCode < 42 || charCode > 57) )
	return false;
 return true;
}

function checkCityOther(obj)
{
	if (obj.value != "-1") { document.getElementById('CityOther').style.display = 'none'; }
	else { document.getElementById('CityOther').style.display = 'inline'; }
}

function checkHomeCityOther(obj)
{
	if (obj.value != "-1") { document.getElementById('HomeCityOther').style.display = 'none'; }
	else { document.getElementById('HomeCityOther').style.display = 'inline'; }
}

function checkDateRange(start, end) {
   // Parse the entries
   var startDate = Date.parse(start);
   var endDate = Date.parse(end);
   // Make sure they are valid
    if (isNaN(startDate)) {
      alert("The start date provided is not valid, please enter a valid date.");
      return false;
   }
   if (isNaN(endDate)) {
       alert("The end date provided is not valid, please enter a valid date.");
       return false;
   }
   // Check the date range, 86400000 is the number of milliseconds in one day
   var difference = (endDate - startDate) / (86400000 * 2);
   if (difference < 0) {
       alert("The start date must come before the end date.");
       return false;
   }
   if (difference <= 1) {
       alert("The range must be at least one day apart.");
       return false;
    }
   return true;
}

function checkMaxLetter(f,id,num){

	if(f[id].value.length>num)
	{
		f[id].value = f[id].value.substring(0,num);
		return false;
	}
	document.getElementById(id+'_chars').innerHTML = num-f[id].value.length;
}
//Trim
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}