// JavaScript Document

function collapse(id)
{
	if (document.getElementById(id).style.display == "")
	{
		document.getElementById(id).style.display = "none";
		
		try
		{
			document.getElementById(id + "_img").src = "images/plus.png";
		}
		catch(ex)
		{
		}
	}
	else
	{
		document.getElementById(id).style.display = "";
		
		try
		{
			document.getElementById(id + "_img").src = "images/minus.png";
		}
		catch(ex)
		{
		}
	}
}

function SubmitSearchForm()
{
	if (document.SearchForm.search.value == "" || document.SearchForm.search.value == "חיפוש בקטלוג")
	{
		return ShowError('אנא ציין מילות חיפוש', document.SearchForm.search);
	}
	
	return true;
}

function SubmitRecordForm()
{
	if (document.RecordForm.name.value == "")
	{
		return ShowError('אנא ציין שם מלא', document.RecordForm.name);
	}
	
	if (document.RecordForm.kidomet.value == "")
	{
		return ShowError('אנא ציין קידומת', document.RecordForm.kidomet);
	}
	
	if (document.RecordForm.phone.value == "")
	{
		return ShowError('אנא ציין מספר טלפון', document.RecordForm.phone);
	}
	
	if (document.RecordForm.phone.value.length != 7)
	{
		return ShowError('מספר טלפון חייב להכיל 7 ספרות', document.RecordForm.phone);
	}
	
	if (document.RecordForm.area.value == "")
	{
		return ShowError('אנא בחר אזור', document.RecordForm.area);
	}
	
	if (document.RecordForm.upload_file.value != 0)
	{
		if (document.RecordForm.file.value == "")
		{
			return ShowError('אנא בחר קובץ', document.RecordForm.file);
		}
	}
		
	return true;
}

function SubmitContactForm()
{
	if (document.ContactForm.name.value == "")
	{
		return ShowError('אנא ציין שם מלא', document.ContactForm.name);
	}
	
	if (document.ContactForm.kidomet.value == "")
	{
		return ShowError('אנא ציין קידומת', document.ContactForm.kidomet);
	}
	
	if (document.ContactForm.phone.value == "")
	{
		return ShowError('אנא ציין מספר טלפון', document.ContactForm.phone);
	}
	
	if (document.ContactForm.phone.value.length != 7)
	{
		return ShowError('מספר טלפון חייב להכיל 7 ספרות', document.ContactForm.phone);
	}
	
	if (document.ContactForm.email.value == "")
	{
		return ShowError('אנא ציין כתובת דוא"ל', document.ContactForm.email);
	}
	
	if (document.ContactForm.subject.value == "")
	{
		return ShowError('אנא בחר את נושא הפניה', document.ContactForm.subject);
	}
		
	if (document.ContactForm.description.value == "")
	{
		return ShowError('אנא ציין את תוכן הפניה', document.ContactForm.description);
	}
	
	return true;
}

function SubmitMiniRecordForm()
{
	if (document.MiniRecordForm.catalog_id.value == "" && document.MiniRecordForm.groupsale_id.value == "")
	{
		return ShowError('שגיאה', document.MiniRecordForm.catalog_id);
	}
	
	if (document.MiniRecordForm.name.value == "")
	{
		return ShowError('אנא ציין שם מלא', document.MiniRecordForm.name);
	}
	
	if (document.MiniRecordForm.kidomet.value == "")
	{
		return ShowError('אנא ציין קידומת', document.MiniRecordForm.kidomet);
	}
	
	if (document.MiniRecordForm.phone.value == "")
	{
		return ShowError('אנא ציין מספר טלפון', document.MiniRecordForm.phone);
	}
	
	if (document.MiniRecordForm.phone.value.length != 7)
	{
		return ShowError('מספר טלפון חייב להכיל 7 ספרות', document.MiniRecordForm.phone);
	}
	
	if (!document.MiniRecordForm.terms.checked)
	{
		return ShowError('חובה להסכים לתקנון האתר', document.MiniRecordForm.terms);
	}
	
	return true;
}

function SubmitMarketingForm()
{
	try
	{
		if (document.MarketingForm.username.value == "")
		{
			return ShowError('אנא ציין שם משתמש', document.MarketingForm.username);
		}
		
		if (document.MarketingForm.username.value.length < 5)
		{
			return ShowError('שם משתמש מכיל לפחות 5 תווים', document.MarketingForm.username);
		}
	}
	catch(ex)
	{
		
	}
	
	if (document.MarketingForm.id.value == "")
	{
		if (document.MarketingForm.password.value == "")
		{
			return ShowError('אנא ציין סיסמה', document.MarketingForm.password);
		}
		
		if (document.MarketingForm.password.value.length < 6)
		{
			return ShowError('סיסמה מכילה לפחות 6 תווים', document.MarketingForm.password);
		}
		
		if (document.MarketingForm.password_confirm.value == "")
		{
			return ShowError('אנא ציין אימות סיסמה', document.MarketingForm.password_confirm);
		}
		
		if (document.MarketingForm.password_confirm.value != document.MarketingForm.password.value)
		{
			return ShowError('סיסמאות אינן זהות', document.MarketingForm.password_confirm);
		}
	}
	else
	{
		if (document.MarketingForm.password.value != "")
		{
			if (document.MarketingForm.password.value.length < 6)
			{
				return ShowError('סיסמה מכילה לפחות 6 תווים', document.MarketingForm.password);
			}
			
			if (document.MarketingForm.password_confirm.value == "")
			{
				return ShowError('אנא ציין אימות סיסמה', document.MarketingForm.password_confirm);
			}
			
			if (document.MarketingForm.password_confirm.value != document.MarketingForm.password.value)
			{
				return ShowError('סיסמאות אינן זהות', document.MarketingForm.password_confirm);
			}	
		}
	}
	
	if (document.MarketingForm.first_name.value == "")
	{
		return ShowError('אנא ציין שם פרטי', document.MarketingForm.first_name);
	}
	
	if (document.MarketingForm.last_name.value == "")
	{
		return ShowError('אנא ציין שם משפחה', document.MarketingForm.last_name);
	}
	
	try
	{
		if (document.MarketingForm.day.value == "")
		{
			return ShowError('בחר יום', document.MarketingForm.day);
		}
		
		if (document.MarketingForm.month.value == "")
		{
			return ShowError('בחר חודש', document.MarketingForm.month);
		}
		
		if (document.MarketingForm.year.value == "")
		{
			return ShowError('בחר שנה', document.MarketingForm.year);
		}
	}
	catch(ex)
	{
	}
	
	if (document.MarketingForm.phone_kidomet.value == "")
	{
		return ShowError('אנא ציין קידומת', document.MarketingForm.phone_kidomet);
	}
	
	if (document.MarketingForm.phone.value == "")
	{
		return ShowError('אנא ציין מספר טלפון', document.MarketingForm.phone);
	}
	
	if (document.MarketingForm.phone.value.length != 7)
	{
		return ShowError('מספר טלפון חייב להכיל 7 ספרות', document.MarketingForm.phone);
	}
	
	if (document.MarketingForm.mobile_kidomet.value == "")
	{
		return ShowError('אנא ציין קידומת', document.MarketingForm.mobile_kidomet);
	}
	
	if (document.MarketingForm.mobile.value == "")
	{
		return ShowError('אנא ציין מספר טלפון נייד', document.MarketingForm.mobile);
	}
	
	if (document.MarketingForm.mobile.value.length != 7)
	{
		return ShowError('מספר טלפון נייד חייב להכיל 7 ספרות', document.MarketingForm.mobile);
	}
	
	if (document.MarketingForm.email.value == "")
	{
		return ShowError('אנא ציין כתובת דוא"ל', document.MarketingForm.email);
	}
	
	if (document.MarketingForm.city.value == "")
	{
		return ShowError('אנא ציין עיר', document.MarketingForm.city);
	}
	
	if (document.MarketingForm.address.value == "")
	{
		return ShowError('אנא ציין כתובת', document.MarketingForm.address);
	}
	
	return true;
}

function SubmitMarketingLoginForm()
{
	if (document.MarketingLoginForm.username.value == "")
	{
		return ShowError('אנא ציין שם משתמש', document.MarketingLoginForm.username);
	}
	
	if (document.MarketingLoginForm.password.value == "")
	{
		return ShowError('אנא ציין סיסמה', document.MarketingLoginForm.password);
	}
	
	return (true);
}

function getPriceModel(id, catalog_id, parent_id)
{
	document.getElementById("name").focus();
	
	document.getElementById("catalog_type").value = parent_id;
	
	CatalogByType(parent_id, catalog_id);
	CatalogByParent(catalog_id, id);
}

function UploadFile()
{
	if (document.getElementById("upload_file").value == 0)
	{
		try
		{
			document.getElementById("catalog_type_field").style.display = "none";
			document.getElementById("catalog_parent_field").style.display = "none";
			document.getElementById("catalog_id_field").style.display = "none";
		}
		catch(ex){}
		
		document.getElementById("upload_file_tr").style.display = "";
		
		document.getElementById("upload_file_checkbox").src = "images/checkbox_selected.png";
		
		document.getElementById("upload_file").value = 1;
	}
	else
	{
		try
		{
			document.getElementById("catalog_type_field").style.display = "";
			document.getElementById("catalog_parent_field").style.display = "";
			document.getElementById("catalog_id_field").style.display = "";
		}
		catch(ex){}
		
		document.getElementById("upload_file_tr").style.display = "none";
		
		document.getElementById("upload_file_checkbox").src = "images/checkbox.png";
		
		document.getElementById("upload_file").value = 0;
	}
}

function ShowError(msg, object)
{
	alert(msg);
	object.focus();
	return false;
}

function isNumberKey(evt)
{
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	 return true;
}

function changeColour(elementId) {
    var interval = 500;
    var colour1 = "#ff0000"
    var colour2 = "#000000";
    if (document.getElementById) {
        var element = document.getElementById(elementId);
        element.style.color = (element.style.color == colour1) ? colour2 : colour1;
        setTimeout("changeColour('" + elementId + "')", interval);
    }
}


// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=2000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
	  //document.getElementById(foregroundID).src = newImage;
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  FadeInImage(pictureID,nextImage,backgroundID);
  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

