String.prototype.trim = function() 
{
    return this.replace(/^\s*|\s*$/g,"");
}
//////////////////////////////////////////////////////////////////////
//Global Vars
//////////////////////////////////////////////////////////////////////
var PostForm=false;
var ObjDisplayed = new Object();
var theTimeOut=null;
var tickerSpeed=50;
var tickerStep=1;
ObjDisplayed.id="";
var curDiv="indexDiv_1";
var oldDiv="";
var divOpacity = 100;
var	steps = 10;
var oAmount = 10;
//////////////////////////////////////////////////////////////////////
function CheckFormPostBack(){
return PostForm;
}
//////////////////////////////////////////////////////////////////////
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}
//////////////////////////////////////////////////////////////////////
function readCookie(name)
{
	var cookieArr = document.cookie.split(";");

    for (j = 0; j < cookieArr.length; j++)
    {
		var currentCookieArr = cookieArr[j].split("=");
        var cookieName = currentCookieArr[0];
        var cookieValue = currentCookieArr[1];
        
        if (cookieName.trim() == name)
        {
            if (cookieValue != null)
            {
                return cookieValue;
            }
        }

    }
    
    return "";
}
//////////////////////////////////////////////////////////////////////
function disp(id)
{
if(id=="")
	return;
if (ObjDisplayed.id!="") {ObjDisplayed.style.display="none";}
//var Obj = eval("document.all.tr"+id);
var Obj = document.getElementById(id);
if (Obj!=ObjDisplayed)
	{
		ObjDisplayed=Obj;
		Obj.style.display="inline"; //OR LEAVE "" (EMPTY) FOR FIREFOX ALLSO
	}
else {
	ObjDisplayed= new Object();
	ObjDisplayed.id="";
	}
}


function Redirect(urlTemplate)
{
	try
	{
		parent.document.location.href = urlTemplate;
	}
	catch(e)
	{
	}
}

//////////////////////////////////////////////////////////////////////
//THE CALENDAR CALL FUNCTION
function popupCal(formName,fieldName,dateFormat,seperatore)
{
	
	formName = document.forms[0].name;
	document.getElementById("fromDate" +"_DIV").innerHTML="";
	document.getElementById("toDate" +"_DIV").innerHTML="";
     if(typeof(fieldName)!= "undefined")  
     { 
	   fieldName = formName + "__" + fieldName;
	 }else{
	   fieldName = formName;
	 }
	 
	
   if(typeof(dateFormat)!= "undefined") fieldName = fieldName + "__" + dateFormat;
   if(typeof(seperatore)!= "undefined") fieldName = fieldName + "__" + seperatore;

	var divName=fieldName.split("__")[2];
	
	if(parent==window ){	
	document.getElementById(divName +"_DIV").innerHTML="<iframe name='"+fieldName+"' src='include/calendar.html' width='185' height='179' frameborder='0' border='no'></iframe>";	
	}
	else
	{	
		parent.document.getElementById(divName +"_DIV").style.left=(event.screenX -document.body.scrollWidth + top.document.body.scrollLeft) + 157;
		parent.document.getElementById(divName +"_DIV").style.top=(event.screenY -document.body.scrollHeight + top.document.body.scrollTop) + 80;
		parent.document.getElementById(divName +"_DIV").innerHTML="<iframe name='"+fieldName+"' src='include/calendar.html' width='185' height='179' frameborder='0' border='no'></iframe>";
	}
	
	
	//if (window.showModalDialog) {
	  //ie
	 // var win = window.open('include/calendar.html', fieldName, 'width=185,height=179,left=10,top=50,resizable=no,modal=yes');
	//} else {
	  //ff
	 //  var win = window.open('include/calendar.html', fieldName, 'width=185,height=179,left=10,top=50,resizable=no,modal=yes');
	  // win.focus();
	//}
}





//////////////////////////////////////////////////////////////////////
//THE CALENDAR CALL FUNCTION
function popupCalNew(formName,fieldName,dateFormat,seperatore)
{		
	var divName=fieldName +"_DIV";		
	if(parent==window ){	
	document.getElementById(divName).innerHTML="<iframe name='"+fieldName+"' src='include/calendar.html' width='185' height='179' frameborder='0' border='no'></iframe>";		
	}
	else
	{			
		var divName = 'fromDate_DIV';		
				
		parent.document.getElementById(divName).style.left =(event.screenX -document.body.scrollWidth + top.document.body.scrollLeft) + 157;
		parent.document.getElementById(divName).style.top  =(event.screenY -document.body.scrollHeight + top.document.body.scrollTop) + 80;
		parent.document.getElementById(divName).innerHTML="<iframe name='"+fieldName+"' src='include/calendar.html' width='185' height='179' frameborder='0' border='no'></iframe>";
		
	}
	
	//document.getElementById(fieldName +"_DIV").innerHTML="<iframe name='"+fieldName+"' src='include/calendar.html' width='185' height='179' frameborder='0' border='no'></iframe>";					
}









//////////////////////////////////////////////////////////////////////
function fadeDiv() {
	divOpacity = divOpacity + oAmount;

		if (divOpacity <100) {
			setOpacity(curDiv,divOpacity)
			setTimeout("fadeDiv()",1);
		}
}
//////////////////////////////////////////////////////////////////////
function fadeDivOut() {
	divOpacity = divOpacity - oAmount;
	
	if (divOpacity >0) {
		setOpacity(oldDiv,divOpacity)
		setTimeout("fadeDivOut()",1);
	}
}
//////////////////////////////////////////////////////////////////////
function setOpacity(objectId,objectOpacity) {

	if (document.all)
	{
	
		document.all(objectId).filters.alpha.opacity = objectOpacity;
	}
	else if (!document.all && document.getElementById) 
	{		
		document.getElementById(objectId).style.MozOpacity = objectOpacity/100;
	}
}

var FlashActive=true;

function CancelFlashChange(){
FlashActive=false;
}

function changeTabClass(whoPressed,numOfTabs)
{
//,tabsId,tabsClass

	
	
	var theId;
	//divOpacity=0;

	//if(FlashActive){
		if (curDiv!="")
		{
		
			oldDiv=curDiv;
			fadeDivOut();	
		}
		//divOpacity=0;
		var obj="indexDiv_"+whoPressed;
		for (i=1;i<=numOfTabs;i++)
		{
		
			eval("indexDiv_"+i).style.display="none";
		}
		
		if (document.all)
		{
			document.all(obj).filters.alpha.opacity = 0;
		}
		else if (!document.all && document.getElementById) 
		{		
			document.getElementById(obj).style.MozOpacity = 0;
		}
		
		
		
		
		eval("indexDiv_"+whoPressed).style.display="";
		eval("indexDiv_"+whoPressed).style.width="276px";
		eval("indexDiv_"+whoPressed).style.height="149px";
		curDiv="indexDiv_"+whoPressed;
		
		divOpacity=0;
		
		fadeDiv(curDiv);
	//}	
	
}


///Ticker Functions
///Ewave


function stopTicker(){if(theTimeOut!="")clearTimeout(theTimeOut);}
 
 function goTicker()
 {
 
 try{
	 if(theTimeOut!="")clearTimeout(theTimeOut);
	 
	 var theTickerLeft = document.getElementById('theTicker').style.left;
	 var theParentDivWidth = document.getElementById('theParentDiv').style.width;
	 
	 var strLeftSplit = theTickerLeft.substring(0,theTickerLeft.lastIndexOf("px"));
	 var strWidthSplit = theParentDivWidth.substring(0,theParentDivWidth.lastIndexOf("px"));
	 
     if (eval(tickerStep)<0){
		 if (strLeftSplit>(eval(-1 * strWidthSplit - 450))){
		     document.getElementById('theTicker').style.left = eval(strLeftSplit + tickerStep);
		 }
		 else{
		     document.getElementById('theTicker').style.left = parseInt(strWidthSplit) - 5;
		 }
	 }else{
	
	    if (strLeftSplit==0 || (parseInt(strLeftSplit)<(parseInt(strWidthSplit) + 450))){
		     document.getElementById('theTicker').style.left = parseInt(strLeftSplit) + parseInt(tickerStep);
		 }
		 else{
		     document.getElementById('theTicker').style.left = parseInt(-1) * parseInt(strWidthSplit);
		 }
	 }
	 }catch(e){
	 
	 }
	 
	 theTimeOut = setTimeout('goTicker()', tickerSpeed);
}


function dispP(id){
	var Obj = document.getElementById(id);
if (Obj.style.display == 'inline'){
                Obj.style.display = 'none';
			}else{
                Obj.style.display = "inline"; //OR LEAVE "" (EMPTY) FOR FIREFOX ALLSO
            }
			
	}




var State;
function ChangeImg(N_Img,State){
			var myImg = N_Img;		
			var N_Img=document.getElementById(N_Img);			
			if(N_Img!=null){
				if (State==1)
				{		
					N_Img.src=N_Img.src.replace("_off","_on");				
				}
				else {											
					N_Img.src=N_Img.src.replace("_on","_off");
				}			
			}
		}




function changeBack(Obj,State){
var myImg = Obj;
          if(myImg!=null){
				if (State==1)
				{		
					 myImg.background=myImg.background.replace("_off","_on");			
				}
				else {		
				    myImg.background=myImg.background.replace("_on","_off");
				}			
			}	
}

function changetdBack(Obj,State){
var myImg = Obj.parentElement;

          if(myImg!=null){
				if (State==1)
				{		
					 myImg.background=myImg.background.replace("_off","");			
				}
				else {		
				    myImg.background=myImg.background.replace("_on","");
				}			
			}	

}

function changetsBack(Obj,State){


		var myImg = Obj.parentElement;
		
		
          if(myImg!=null){
				if (State==1)
				{		
					 myImg.background=myImg.background.replace("_off","_on");			
				}
				else {		
				    myImg.background=myImg.background.replace("_on","_off");
				}			
			}	
}

function changeTab(objId,objNum,tabId,NumOfTabs)
{
  var theNumOfTabs = parseInt(NumOfTabs);

  var theObjId = "";
  var theTabId = "";
  for(i=1;i <= theNumOfTabs ; i++)
  {
	  try{
     theObjId = document.getElementById(objId + '_' + i);
	 theObjId.style.display = 'none';

     theTabId = document.getElementById(tabId + '_' + i);
	 theTabId.className = theTabId.className.replace('_On','_Off');
	  }catch(e){}
  }
  
  theObjId = document.getElementById(objId + '_' + objNum);
  theObjId.style.display = '';
  
  theTabId = document.getElementById(tabId + '_' + objNum);
  theTabId.className = theTabId.className.replace('_Off','_On');
}

function changeDiv(divId,divNum,NumOfDivs)
{
  var theNumOfDivs = parseInt(NumOfDivs);

  for(i=1;i <= theNumOfDivs ; i++)
  {
     theDivId = document.getElementById(divId + '_' + i);
	 theDivId.style.display = 'none';
  }

  theDivId = document.getElementById(divId + '_' + divNum);
  theDivId.style.display = '';
}
		
function drawDateGifs(mode){

	var monthNames = new Array(
	"1","2","3","4","5","6","7",
	"8","9","10","11","12");
	
	var now = new Date();

	var theYear = now.getFullYear();
	var theMonth = monthNames[now.getMonth()]
	var theDay = now.getDate();

	theYear = theYear.toString();
	theMonth = theMonth.toString();
	theDay = theDay.toString();

	var theYearArr = new Array();
	var theMonthArr = new Array();
	var theDayArr = new Array();
	
	
	for (i=2;i<(theYear.length);i++){
	  theYearArr[i] = theYear.charAt(i);
	}
	
	for (i=0;i<(theMonth.length);i++){
	  theMonthArr[i] = theMonth.charAt(i);
	}
	
	if(theMonth.length<2){
	  theMonthArr[1] = theMonthArr[0];
	  theMonthArr[0] = 0;
	}
	
	
	for (i=0;i<(theDay.length);i++){
	  theDayArr[i] = theDay.charAt(i);
	}
	
	
	if(theDay.length<2){
	  theDayArr[1] = theDayArr[0];
	  theDayArr[0] = 0;
	}
if (mode!="layla"){
	if (mode!="small"){
		document.write('<img src="images/icons/'+ theYearArr[3] + '.gif">');
		document.write('<img src="images/icons/'+ theYearArr[2] + '.gif">');
		document.write('<img src="images/icons/dot.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[1] + '.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[0] + '.gif">');
		document.write('<img src="images/icons/dot.gif">');
		document.write('<img src="images/icons/'+ theDayArr[1] + '.gif">');
		document.write('<img src="images/icons/'+ theDayArr[0] + '.gif">');
		}else{
		document.write('<img src="images/icons/'+ theYearArr[3] + 's.gif">');
		document.write('<img src="images/icons/'+ theYearArr[2] + 's.gif">');
		document.write('<img src="images/icons/dots.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[1] + 's.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[0] + 's.gif">');
		document.write('<img src="images/icons/dots.gif">');
		document.write('<img src="images/icons/'+ theDayArr[1] + 's.gif">');
		document.write('<img src="images/icons/'+ theDayArr[0] + 's.gif">');
		}
	}else{
		document.write('<img src="images/icons/'+ theYearArr[3] + 'L.gif">');
		document.write('<img src="images/icons/'+ theYearArr[2] + 'L.gif">');
		document.write('<img src="images/icons/dotL.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[1] + 'L.gif">');
		document.write('<img src="images/icons/'+ theMonthArr[0] + 'L.gif">');
		document.write('<img src="images/icons/dotL.gif">');
		document.write('<img src="images/icons/'+ theDayArr[1] + 'L.gif">');
		document.write('<img src="images/icons/'+ theDayArr[0] + 'L.gif">');
	}
}	
		
	
	//for the gallery pictures forword and backwords
	var arrIndex = 0
	 function changeThePic2(direction){
	
	    var the_pic = document.images['thePic'] ;
		direction = eval(direction)
		
		  if ((arrIndex+direction >= 0) && (arrIndex+direction <= imgArr.length-1)){
			document.images['thePic'].src = imgArr[arrIndex+direction];
			arrIndex = arrIndex+direction;
			}
	 }
	
	function changeTheBigPic(direction)
	{
	
	
	    var the_pic = document.images['thePic'] ;
		direction = eval(direction)
		
		  if ((arrIndex+direction >= 0) && (arrIndex+direction <= imgArr.length-1)){
			document.images['thePic'].src = imgArr[arrIndex+direction];
			arrIndex = arrIndex+direction;
			}
	 }

   function changeThePic1(whoPressed,numOfPics){
	    var the_pic = document.images['thePic'] ;
		the_pic.src = imgArr[whoPressed-1];
		changeClass1(whoPressed,numOfPics);
	 }


	 //for the clicling thr little pics in the gallary
	function changeThePic2(whoPressed,numOfPics){
	    var the_pic = document.images['thePic'] ;
		the_pic.src = imgArr[eval(whoPressed)-1];
	 } 
	 
	 
	 function changeClass1(whoPressed,numOfPics){
	   
	   for (i=1;i<=numOfPics;i++){
		  var theId;
	      theId = document.getElementById("num_"+ i)
		  theId.className = "num_Off";
	   }

		  theId = document.getElementById("num_"+ whoPressed);
		  theId.className = "num_On";
	 }
	 
	 
function openWindow(url,w,h) {
	 var l = (screen.width - w) / 2;
	 var t = (screen.height - h) / 2;
	 var sURL = url
	 var sName = "popName"
	 var sFeatures = "menubar=no,scrollbars=no,resizable=no"
	 sFeatures = sFeatures + ",width=" + w + ",height=" + h +',top='+t+',left='+l+'w';
	 var wizWin = window.open(sURL, sName, sFeatures);
}



 function changeThePic(theImgNum,numOfPics,whoPressed){
	    var the_pic=document.images['thePic'] ;
	    var thePath = the_pic.src.substring(0,(the_pic.src.lastIndexOf("/")+1));
        the_pic.src = thePath + theImgNum;
		changeClass1(theImgNum,numOfPics,whoPressed);
	 }

function EnsureNumeric(fld)
{
	if (event.keyCode>=37 && event.keyCode<=40)
		return true;
	if (event.keyCode>=96 && event.keyCode<=105)
		return true;
		
	if (event.keyCode<32)
		return true;
	if (event.keyCode==46)
		return true;

	var ch = String.fromCharCode( event.keyCode ); 

	if (/[^0-9]/.test(ch))
	{
		event.returnValue = false;
		event.cancel = true
	}
}

function ValidateNumeric(val)
{
	return /^[0-9]*\.{0,1}[0-9]*$/.test(val);
}
	 
 
function ValidateEmail(email)
{
	return /^([A-Za-z0-9\-_]*[\.A-Za-z0-9\-_]+@[A-Za-z0-9\-_]+(\.[A-Za-z0-9\-_]+){1,3})*$/.test(email);
}




///// print function
function PrintMe(){
window.open("PrintPage.aspx");
}
function PrintMe2(pageUrl){
window.open("PrintPage2.aspx?pageUrl="+pageUrl);
}

function PrintMeCoupon(){
window.open("PrintPageCoupon.aspx");
}

///// print function


function calcSurveyHeight(height)
{	
  document.getElementById('SurveyIframe').height=height;
}

function calcSearchHeight(height)
{	
	
	document.getElementById('SearchResults').height=height;
}

function calcResponseHeight(height)
{
	//FIX : when responses loading from browser cache, it loads too quick and iframe.dcoument.scrollheight is returning 0
  if (height > 0 )
  {
	document.getElementById('ResponsesIframe').height=height;
  }
 
		
	
		
}

function calcDepSearchHeight(height)
{
  document.getElementById('DepartmentSearch').height=height;
}



function LTrim(str)
{
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}
		
function RTrim(str)
{
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}

function Trim(str)
{
	return LTrim(RTrim(str));
}

var tabTag = "Tab";
var tabContentTag = "Content";
var tabSeparator = "_";

function SelectTab(tab)
{
	var tabId = tab.id;
	var tabName = tab.name;
	var tabGroup = document.getElementsByName(tabName);
	for (i=0; i<tabGroup.length; i++)
	{
		// unselect all tab buttons within current group
		tabGroup[i].parentNode.className = "";
		
		// hide all content elements controlled by tab
		var contentId = tabGroup[i].id.replace(tabTag, tabContentTag);
		document.getElementById(contentId).style.display = "none";
	}
	// select 'this' tab
	tab.parentNode.className = "chosen";
	
	// show 'this' tab controlled element
	var selectedContentId = tabId.replace(tabTag, tabContentTag);
	document.getElementById(selectedContentId).style.display = "block";
}

