var errors_list = new Array(30);
var error_flag = false;
var error_counter = 0;
var character_errors_list = new Array(30);
var character_error_flag = false;
var character_error_counter = 0;


//###########################
function change_image(image_to_show, image_name, image_width)
{
 document[image_name].src = "images/" + image_to_show;
 document[image_name].width = image_width;
}
//###########################


//###########################
function set_select_value(form_name, select_object_name, select_value)
{
 var select_object = eval("document." + form_name + "." + select_object_name);
 for ( var i = 0 ; i < select_object.length ; i++ )
 {
  if (select_object[i].value == select_value)
  {
   select_object.selectedIndex = i;
   return;
  }
 }
}
//###########################


//###########################
function check_checkboxes(form_name, checkbox_name, number_of_checkboxes, on_off)
{
 var checkbox;
 for( var i = 1 ; i <= number_of_checkboxes ; i++ )
 {
  checkbox = eval("document." + form_name + "." + checkbox_name + "_" + i);
  if (checkbox)
  {
   if (on_off == "on")
    checkbox.checked = true;
   else
    checkbox.checked = false;
  }
 }
}
//###########################


//###########################
function show_error(error_code)
{
 var error_text = "";

 switch (error_code)
 {
  case "1001":
   error_text = "אנא תקנו את מספר המודעה";
   break;
  case "1002":
   error_text = "אנא תקנו את מספר המודעה";
   break;
  case "1003":
   error_text = "אנא תקנו את כתובת האימייל";
   break;
  case "1004":
   error_text = "אנא תקנו את כתובת האימייל";
   break;
  case "1005":
   error_text = "המודעה לא נמצאה. \nאנא בדקו את מספר המודעה ואת כתובת האימייל.";
   break;
  case "1006":
   error_text = "המודעה לא נמצאה. \nאנא בדקו את מספר המודעה.\nאם המספר נכון, ייתכן כי פג תוקף המודעה.";
   break;
  case "1007":
   error_text = "כתובת האימייל או מספר המודעה שגויים.";
   break;
  case "1008":
   error_text = "אנו מתנצלים, חלה תקלה בשליחת המודעה. \nאנא נסו שנית. \n\nאם התקלה חוזרת, בבקשה <a href='/footer/contact_us.asp' class='inTextLink'>ספרו לנו</a> עליה.";
   break;
  default:
   error_text = "בעיה לא צפויה בביצוע הפעולה. \nאנא נסו שנית";
 }

 return error_text;
}
//###########################



//###########################
function add_message_id(message_id)
{
 if (message_id_list != "")
  message_id_list += ",";
 message_id_list += message_id; 
}
//###########################



//###########################
function set_phone_prefix(the_form, city_code, city_type)
{
 var prefix_array;
 var form_name = "main_form";

 if (city_type == "from_city")
 {
  prefix_array = from_city_phone_prefix;
 }
 else if (city_type == "ps_city")
 {
  prefix_array = ps_city_phone_prefix;
 }

 if (the_form.home_phone.value == "")
 {
  set_select_value(form_name, "home_phone_prefix", prefix_array[city_code]);
 }
 if (the_form.other_phone.value == "")
 {
  set_select_value(form_name, "other_phone_prefix", prefix_array[city_code]);
 }
}
//###########################


//###########################
function set_status(status_text)
{
 window.status = status_text;
}
//###########################

//###########################
function mouseDown(e)
{
	if (parseInt(navigator.appVersion)>3)
	{
		var clickType = 1;
		if (navigator.appName == "Netscape")
			clickType = e.which;
		else
			clickType = event.button;

		if (clickType != 1)
		{
			alert("Copyright (c) 2004 Udi Shomer");
		}
	}
	return true;
}

if (parseInt(navigator.appVersion)>3)
{
	//document.onmousedown = mouseDown;
	if (navigator.appName == "Netscape")
		document.captureEvents(Event.MOUSEDOWN);
}
//###########################


//--------------
// Days
//--------------
//###########################
function display_days(days) 
{
 var display_text = "";
 var day = "";
 
 if ( days == "123456" )
 {
  display_text = "א - ו";
 }
 else if ( days == "12345" )
 {
  display_text = "א - ה";
 }
 else if ( days == "1234567" )
 {
  display_text = "כל השבוע";
 }
 else
 {
  for ( var i = 0 ; i < days.length ; i++ )
  {
   day = days.charAt(i);
   switch(day)
   {
   case "1":
     display_text += "א";
	 break;
   case "2":
     if (display_text += "")
	  display_text += ","
     display_text += "ב";
	 break;
   case "3":
     if (display_text += "")
	  display_text += ","
     display_text += "ג";
	 break;
   case "4":
     if (display_text += "")
	  display_text += ","
     display_text += "ד";
	 break;
   case "5":
     if (display_text += "")
	  display_text += ","
     display_text += "ה";
	 break;
   case "6":
     if (display_text += "")
	  display_text += ","
     display_text += "ו";
	 break;
   case "7":
     if (display_text += "")
	  display_text += ","
     display_text += "שבת";
	 break;
   }
  } //end for
 } 
 document.write(display_text);
}
//###########################


//--------------
// Price
//--------------
//###########################
function display_price(price, write_text)
{
 var display_text = "";
 if (price)
 {
   if (price == "0")
   {
    display_text = "נדבר אחר כך";
   }
   else
   {
    display_text = price + " ש\"ח";
   }
 }

 if (write_text)
  document.write(display_text);
 else
  return display_text;
}
//###########################



//--------------
// Hours
//--------------
//###########################
function display_hours(from_hour, to_hour) 
{
 var display_text = "";

 if ( from_hour == to_hour )
 {
  display_text += display_single_hour(to_hour);
 }
 else
 {
  display_text += display_single_hour(to_hour)
  display_text += " - ";
  display_text += display_single_hour(from_hour)
 }
 document.write(display_text);
}
//###########################


//###########################
function display_single_hour(hour_string)
{
 var display_text = "";
 var hour = "";
 var minutes = "";

 switch(hour_string)
 {
  case "0":
    display_text += "גמיש";
	break;
  case "1":
    display_text += "לא קבוע";
	break;
  case "2":
    display_text += "כל היום";
	break;
  case "-1":
    display_text += "-";
	break;
  case "-2":
    display_text += "-";
	break;
  default:
    hour_string = new Number(hour_string);
    hour = Math.floor(hour_string.valueOf());
    minutes = (hour_string.valueOf() - Math.floor(hour_string.valueOf()))*60;
    if (minutes == 0)
     minutes += "0";
    display_text = hour + ":" + minutes;
 }
 return display_text;
}
//###########################


//--------------
// Date
//--------------
//###########################
function display_date(day, month, year) 
{
 var display_text = "";

 if (year.length == 4)
  year = year.substring(2);
 display_text = day + "/" + month + "/" + year;

 document.write(display_text);
}
//###########################


//--------------
// Phone numbers
//--------------
//###########################
function display_phone_number(prefix, number, seperator) 
{
 var display_text = "";
 if (number != "")
  display_text = prefix + seperator + number;

 document.write(display_text);
}
//###########################


//--------------
// Message list
//--------------
//###########################
function show_message_list(the_form, start_from_message)
{
 the_form.start_from_message.value = start_from_message;
 the_form.submit();
}
//###########################


//###########################
function sort_messages(the_form, sort_field)
{
 days = the_form.days.value;
 if (days.indexOf("1") >= 0)
  the_form.day_1.value = "1";
 if (days.indexOf("2") >= 0)
  the_form.day_2.value = "1";
 if (days.indexOf("3") >= 0)
  the_form.day_3.value = "1";
 if (days.indexOf("4") >= 0)
  the_form.day_4.value = "1";
 if (days.indexOf("5") >= 0)
  the_form.day_5.value = "1";
 if (days.indexOf("6") >= 0)
  the_form.day_6.value = "1";
 if (days.indexOf("7") >= 0)
  the_form.day_7.value = "1";

  the_form.sort_field.value = sort_field;
  the_form.submit();
}
//###########################

//--------------
// Find areas
//--------------
//###########################
function open_find_area_window(message_type, area_type)
{
 var url = "/find_area.asp?message_type=" + message_type + "&area_type=" + area_type;
 var width = 380;
 var height = 380;
 window.open(url, "win" + area_type, "width=" + width + ", height=" + height + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no");
}
//###########################


//###########################
function find_area(the_form)
{
 var area_name = the_form.area_name.value;
 var area_type = the_form.area_type.value;

 if (area_name == "")
 {
  alert("בבקשה הקלידו את שם הישוב/שכונה");
  the_form.area_name.focus();
  return false;
 }
 if (area_name.length < 2)
 {
  alert("יש להקליד לפחות 2 אותיות");
  the_form.area_name.focus();
  return false;
 }
 the_form.search_string.value = area_name;

 if (area_type == "from_area")
  find_from_area(area_name);
 else if (area_type == "to_area")
  find_to_area(area_name);
 else if (area_type == "ps_area")
  find_ps_area(area_name);
 
 display_areas(the_form);
}
//###########################


//###########################
function display_areas(the_form)
{
 var seperator = "_";
 var city_name_list = "";
 var city_code_list = "";
 var area_name_list = "";
 var area_code_list = "";

 for (var i = 0 ; i < city_names.length ; i++)
 {
  if (city_name_list != "")
   city_name_list += seperator;
  city_name_list += city_names[i];
  the_form.city_name_list.value = city_name_list;

  if (city_code_list != "")
   city_code_list += seperator;
  city_code_list += city_codes[i];
  the_form.city_code_list.value = city_code_list;

  if (area_name_list != "")
   area_name_list += seperator;
  area_name_list += area_names[i];
  the_form.area_name_list.value = area_name_list;

  if (area_code_list != "")
   area_code_list += seperator;
  area_code_list += area_codes[i];
  the_form.area_code_list.value = area_code_list;
 }

 the_form.submit();
}
//###########################


//--------------
// Display checked messages
//--------------
//###########################
function display_checked_messages(the_form, print)
{
 var checkbox;
 var i = the_form.start_from_message.value;
 var seperator = "_";
 the_form.message_id_list.value = "";
 if (!print)
  the_form.print.value = "no";

 while ( checkbox = document.getElementById("checkbox_" + i) )
 {
  if (checkbox.checked == true)
  {
   the_form.message_id_list.value += checkbox.value;
   the_form.message_id_list.value += seperator;
  }
  i++;
 }
 if (the_form.message_id_list.value != "")
 {
  the_form.submit();
 }
 else
 {
  if (print)
   alert("לא נבחרו מודעות להדפסה");
  else
   alert("לא נבחרו מודעות לתצוגה");
 }
}
//###########################


//###########################
function print_checked_messages(the_form)
{
 the_form.print.value = "yes";
 display_checked_messages(the_form, true);
}
//###########################


//--------------
// Check all messages
//--------------
//###########################
function check_all(the_form)
{
 var checkbox;
 var i = the_form.start_from_message.value;

 if (document.getElementById("check_all").src.indexOf("SmallIcon_MarkAll") > -1)
 {
  while ( checkbox = document.getElementById("checkbox_" + i) )
  {
   checkbox.checked = true;
   i++;
  }
  document.getElementById("check_all").src = "/images/SmallIcon_ClearAll.gif";
 }
 else
 {
  while ( checkbox = document.getElementById("checkbox_" + i) )
  {
   checkbox.checked = false;
   i++;
  }
  document.getElementById("check_all").src = "/images/SmallIcon_MarkAll.gif";
 }
}
//###########################


//--------------
// Check email address
//--------------
//###########################
function is_valid_email_address(email_address, min_length)
{
 if (email_address == "")
  return false;

 if (email_address.indexOf("@") < 0)
  return false;

 if (email_address.length < min_length)
  return false;

 if (email_address.indexOf("@") < email_address.lastIndexOf("@"))
  return false;

 if (email_address.indexOf("@") > email_address.lastIndexOf(".")-2)
  return false;

 if (email_address.length - email_address.lastIndexOf(".") < 3)
  return false;

 var current_char;
 for (var i = 0 ; i < email_address.length ; i++)
 {
  current_char = email_address.charAt(i);
  if (current_char != "@" && current_char != "." && current_char != "_" && current_char != "-" &&
      (current_char < "a" || current_char > "z") && (current_char < "0" || current_char > "9") &&
	  (current_char < "A" || current_char > "Z")
	 )
	 return false;
 }
 return true;
}
//###########################


//###########################
function check_load_message_details(the_form, user_id_min_length, message_id_min_length)
{
 if (the_form.user_id.value == "")
 {
  alert("בבקשה רשמו את כתובת האימייל");
  the_form.user_id.focus();
  return false;
 }
 if (! is_valid_email_address(the_form.user_id.value, user_id_min_length))
 {
  alert("בבקשה תקנו את כתובת האימייל");
  the_form.user_id.focus();
  return false;
 }
 if (the_form.message_id.value == "")
 {
  alert("בבקשה רשמו את מספר המודעה");
  the_form.message_id.focus();
  return false;
 }
 if (the_form.message_id.value.length < message_id_min_length)
 {
  alert("בבקשה רשמו את מספר המודעה");
  the_form.message_id.focus();
  return false;
 }
 if (isNaN(the_form.message_id.value))
 {
  alert("בבקשה תקנו את מספר המודעה");
  the_form.message_id.focus();
  return false;
 }
 
 return true;
}
//###########################


//--------------
// No email functions
//--------------
//###########################
function give_email_address()
{
 var url = "/give_email_address.asp";
 var width = 380;
 var height = 380;
 window.open(url, "win_give_email", "width=" + width + ", height=" + height + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes");
 //showModalDialog(url, "","dialogHeight:" + height + "px;dialogWidth:" + width + "px;status:no;");
}
//###########################


//###########################
function set_email_address(the_form)
{
 window.opener.main_form.user_id.value = the_form.email.value;
 window.close();
 return false;
}
//###########################


//###########################
function open_pop_up(url, width, height)
{
 window.open(url, "pop_win", "width=" + width + ", height=" + height + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes");
}
//###########################


//###########################
function send_message_id(the_form)
{
 var email_address = the_form.user_id.value;
 if (email_address == "")
 {
  alert("אנא מלאו את כתובת האימייל ואחר כך לחצו שוב");
  the_form.user_id.focus();
  return;
 }

 document.send_message_id.email_address.value = the_form.user_id.value;
 document.send_message_id.submit();
}
//###########################


//###########################
function show_comments(object_name, text, location)
{
 var height = 0;
 var width = 200;
 comments_window = window.createPopup();

 var inner_html = '<table id="comments_table" valign="middle" dir="rtl" cellpadding="2" width="100%" height="100%"><tr><td align="right" valign="middle">';
 inner_html += text;
 inner_html += '</td></tr></table>';
 comments_window.document.body.innerHTML = inner_html;

 if (object_name == "user_id")
 {
  height = 40;
 }
 else if (object_name == "give_email_address")
 {
  height = 40;
 }
 else if (object_name == "area_name")
 {
  height = 24;
 }
 else if (object_name == "terms_of_use")
 {
  height = 24;
  width = 100;
 }

 set_comments_style(comments_window.document.getElementById("comments_table"));
 //alert(comments_win.document.body.innerHTML);

 x_position = window.event.clientX - window.event.offsetX;
 y_position = window.event.clientY - window.event.offsetY;
 if (location == "up")
  y_position -= (height + 10);
 else if (location == "down")
  y_position += 30;
 else if (location == "left")
  x_position -= (width + 10);

 comments_window.show(x_position, y_position, width, height, document.body);
}

function set_comments_style(comments_object)
{
 comments_object.style.marginLeft = "0";
 comments_object.style.marginTop = "0";
 comments_object.style.marginRight = "0";
 comments_object.style.marginBottom = "0";
 comments_object.style.backgroundColor = "#99FFFF";
 comments_object.style.border = "solid black 1px";
 comments_object.style.fontFamily = "arial";
 comments_object.style.fontSize = "11";
}

function hide_comments()
{
 comments_window.hide();
}
//###########################


//###########################
function open_suggest_area_window(message_type, area_type)
{
 var url = "/feedback/get_suggested_town.asp?message_type=" + message_type + "&area_type=" + area_type;
 var width = 380;
 var height = 380;
 window.open(url, "win" + area_type, "width=" + width + ", height=" + height + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no");
}
//###########################


//###########################
var heard_about_us = new Array();

heard_about_us[0] = "";
heard_about_us[1] = "פורום באינטרנט";
heard_about_us[2] = "חברים";
heard_about_us[3] = "קישור מאתר אחר";
heard_about_us[4] = "מנוע חיפוש";
heard_about_us[5] = "פלייר בתיבת הדואר";
heard_about_us[6] = "מודעה ברחוב";
heard_about_us[7] = "פרסום באינטרנט";
heard_about_us[8] = "אחר";

function display_heard_about_us(index)
{
 if (index == "")
  return "";
 else
 {
  index = new Number(index).valueOf();
  return heard_about_us[index];
 }
}
//###########################


//###########################
function set_add_type(form_name, add_type)
{
 if (!add_type)
   return;

 switch (add_type)
 {
  case "1":
    eval("document." + form_name + ".add_type[0]").checked = true;
    break;
  case "2":
    eval("document." + form_name + ".add_type[1]").checked = true;
    break;
  case "3":
    eval("document." + form_name + ".add_type[2]").checked = true;
    break;
  case "4":
    eval("document." + form_name + ".add_type[3]").checked = true;
    break;
 }
}
//###########################


//---------------------------
// Colors
//---------------------------
var normal_font_color = "";
var input_border_color = "";
var display_details_bgcolor = "#FFE666";
