﻿// These are global variables used in multiple locations on the site
var isExplorer = (navigator.appName == "Microsoft Internet Explorer");
var isFirefox	= (navigator.appName == "Netscape");

String.prototype.trim = function() {
// skip leading and trailing whitespace
// and return everything in between
var trimmedString = this;
trimmedString = trimmedString.replace(/^\s+/,"");
trimmedString = trimmedString.replace(/\s+$/,"");
return trimmedString;
}

function validateEmail(email){
	var ptrn = /^[\w](([_\.-]?[\w]+)*)@([\w]+)(([\.-]?[\w]+)*)\.([A-Za-z]{2,})$/;
	return ptrn.test(email);
 }

function toggleStyle(thisElement, thisStyle){
	thisElement.className = thisStyle;
}

function swapImage(thisElementId,thisPic){
	document.getElementById(thisElementId).src = thisPic;
}

function setPageToBackground(){
	document.getElementById("setBackground").style.height		= document.getElementById("bodyMeasurer").offsetTop + "px";
	if (isExplorer) {
		document.getElementById("setBackground").style.backgroundColor = "#DDD"
		document.getElementById("setBackground").style.filter		= "Alpha(opacity=0)";
		showBackground(1);
	} else if (isFirefox){
		showBackgroundFirefox(1);
	}
	document.getElementById("setBackground").style.display	= "";
	//this deals with a Select control in the article page
	if(document.getElementById("drpRate") != null){
		document.getElementById("drpRate").style.visibility	= "hidden";
	}
	//this deals with Select controls in the NEWS page
	if(document.getElementById("controlsNews") != null){
		document.getElementById("controlsNews").style.visibility = "hidden";
	}
}

function showBackground(i){
	document.getElementById('setBackground').style.filter	= 'Alpha(opacity='+i*10+')';
	if(i<8){
		setTimeout("showBackground("+(i+1)+")",0);
	}
}

function showBackgroundFirefox(i){
	document.getElementById("setBackgroundPic").src	= "images/DDDxalpha" + i + "0.png";
	if(i<8){
		setTimeout("showBackgroundFirefox("+(i+1)+")",0);
	}
}

function showPage(){
	document.getElementById('setBackground').style.display	= "none";
	//this deals with a Select control in the article page
	if(document.getElementById("drpRate") != null){
		document.getElementById("drpRate").style.visibility	= "visible";
	}
	//this deals with Select controls in the NEWS page
	if(document.getElementById("controlsNews") != null){
		document.getElementById("controlsNews").style.visibility = "visible";
	}
}

function goToSimpleSearch(searchTerm, sectionId) {
	if (searchTerm == ""){
		alert("נא להזין מונח לחיפוש");
		return;
	}
	var url = "Search.aspx?term=" + escape(searchTerm);
	
	if (sectionId != null) {
		url += "&sectionId=" + sectionId;
	}
	
	location = url;
}

function goToMailinglistPage(email) {
	location = "MailSubscribe.aspx?email=" + email;
}
