/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*/

var dateFormat = function() {
    var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function(val, len) {
		    val = String(val);
		    len = len || 2;
		    while (val.length < len) val = "0" + val;
		    return val;
		};

    // Regexes and supporting functions are cached through closure
    return function(date, mask, utc) {
        var dF = dateFormat;

        // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
        if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
            mask = date;
            date = undefined;
        }

        // Passing date through Date applies Date.parse, if necessary
        date = date ? new Date(date) : new Date;
        if (isNaN(date)) throw SyntaxError("invalid date");

        mask = String(dF.masks[mask] || mask || dF.masks["default"]);

        // Allow setting the utc argument via the mask
        if (mask.slice(0, 4) == "UTC:") {
            mask = mask.slice(4);
            utc = true;
        }

        var _ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
			    d: d,
			    dd: pad(d),
			    ddd: dF.i18n.dayNames[D],
			    dddd: dF.i18n.dayNames[D + 7],
			    m: m + 1,
			    mm: pad(m + 1),
			    mmm: dF.i18n.monthNames[m],
			    mmmm: dF.i18n.monthNames[m + 12],
			    yy: String(y).slice(2),
			    yyyy: y,
			    h: H % 12 || 12,
			    hh: pad(H % 12 || 12),
			    H: H,
			    HH: pad(H),
			    M: M,
			    MM: pad(M),
			    s: s,
			    ss: pad(s),
			    l: pad(L, 3),
			    L: pad(L > 99 ? Math.round(L / 10) : L),
			    t: H < 12 ? "a" : "p",
			    tt: H < 12 ? "am" : "pm",
			    T: H < 12 ? "A" : "P",
			    TT: H < 12 ? "AM" : "PM",
			    Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
			    o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
			    S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

        return mask.replace(token, function($0) {
            return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
        });
    };
} ();

// Some common format strings
dateFormat.masks = {
    "default": "ddd mmm dd yyyy HH:MM:ss",
    shortDate: "m/d/yy",
    mediumDate: "mmm d, yyyy",
    longDate: "mmmm d, yyyy",
    fullDate: "dddd, mmmm d, yyyy",
    shortTime: "h:MM TT",
    mediumTime: "h:MM:ss TT",
    longTime: "h:MM:ss TT Z",
    isoDate: "yyyy-mm-dd",
    isoTime: "HH:MM:ss",
    isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
    isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
    dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
    monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function(mask, utc) {
    return dateFormat(this, mask, utc);
};



function goBack()
{
	try
	{
		history.go(-1);
	}
	catch(e)
	{}
}
function onCarouselItemChange(i_iCarouselItemIndex)
{
	
}
function onCarouselItemClicked(i_iCarouselItemIndex)
{
	
	var oCarouselItemFormContainer = document.getElementById("CarouselItemContent_" + i_iCarouselItemIndex);
	if (!oCarouselItemFormContainer)
		return;
	
	if (onCarouselItemChange.Current != null)
		onCarouselItemChange.Current.style.display = "none";
	oCarouselItemFormContainer.style.display = "block";
	onCarouselItemChange.Current = oCarouselItemFormContainer;
}



function goFibi(url)
{
	location.href = url;
}

function doSearch(sInput)
{
	var input =document.getElementById("search").value;
	
	try
	{
		if(input=='' || input == "search" || input == "חיפוש" )
		{
			alert('אנא הכנס מילת חיפוש. \n Please enter search word');
			return;
		}
				
		if(input.indexOf("script")>-1)
		{
			alert('מילה לא חוקית');
			document.all[input].value="";
			document.all[input].focus();
			return;
		}
		else
		{
			document.SearchForm.submit();
		}
	}
	catch(e)
	{
		alert("doSearch: "+e.message);
	}
}
function openWind(winHref, winName, winWidth, winHeight, winLeft, winTop)
{
	var left;
	var top;
		
	if (winLeft=='0' && winTop=='0')
	{
		left = parseInt((screen.availWidth/2) - (winWidth/2));
		top = parseInt((screen.availHeight/2) - (winHeight/2));
    }
   
	var winStr = "width=" + winWidth + ",height=" + winHeight + ",location=0, menubar=0,left=" + left + ",top=" + top + ",resizable=0,scrollbars=0,status=0,toolbar=0"
	window.open(winHref,"PopUPCampaigns",winStr);
}
function openWind(winHref,winName,parameters)
{
	window.open(winHref,"PopUPCampaigns",parameters);
}



// trim
function trim(str)
{
	if (!str.match(/\S/))
		return '';
	return str.replace(/^\s+|\s+$/g,'');
}

// extend String object
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/, '');
}

String.isNullOrEmpty = function(str)
{
	return str == undefined || str == null || str.toString().length == 0;
}

/*
 * preloading an image. creating an image object with given source
 * imgObj: name of object to be created
 * imgSrc: URL of image 
 */
function preload(imgObj,imgSrc)
{
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
    }
}

/*
 * This function receives a comma separated string where each
 * pair is an image object name and an image URL.
 * the function then goes over these pairs array and invokes the
 * preload function to load the images into the browser's memory
*/
function preloadThem(str)
{
	var arr = str.split(/\s*,\s*/)
	for (i = 0; i < arr.length; i += 2)
	{
		//alert(arr[i]+"\n"+arr[i+1])
		preload(arr[i],arr[i+1])
	};
}

/*
 * Used to invoke preloadThem() function.
 * Please read the preloadThem() documentation.
 */
function preloadImages(str)
{
	document.onload = preloadThem(str);
}

/*
 * change a layer's image elemnt's source
 * layer: name of a non nesting layer. if null look for image in document.images
 * img: name of image element or an image object (or input type="image")
 * imgObjName: name of preloaded image object
 * -> image element of layer source would be replaced with image object's source
 */
function changeImage(img,imgObjName,layer)
{
	var imgObjSrc = eval(imgObjName+".src");
	// handle image object
	if (typeof(img) == 'object')
		img.src = imgObjSrc
	// handle image name
	else if (document.images && typeof(img) == 'string') {
        if (document.all || document.getElementById || layer == null)
            document.images[(img)].src = imgObjSrc;
        else eval('document.'+layer+'.document.images["'+img+'"].src = ' + imgObjSrc);
    }
}

// parse file name from file's path
function getFileName(filePath)
{
    var p = Math.max(filePath.lastIndexOf('/'),filePath.lastIndexOf('\\'))
    return filePath.substring(p + 1,filePath.length)
}

// This function opens a new window in the middle of the screen
// Parameters:
// w - the width of the window
// h - the height of the window
// ur - the URL of the window
// target - optional target of the window
// params - optional window parameters
function openwindow(w,h,ur,target,params)
{
	var winleft = screen.width/2 - w/2
	var wintop = screen.height/2 - h/2 - 30
	var fullParams = 'width=' + w + ',height=' + h + ',' + 'top=' + wintop + ',left=' + winleft + ','
	if (!params)
		params = 'scrollbars=auto,menubar=no,resizable=yes,toolbar=no,location=no,status=no'
	fullParams += params
	if (!target) target = ''
	var newWinObj = window.open(ur,target,fullParams)
	if (newWinObj) newWinObj.focus()
	return newWinObj
}

// return reference to an object.
// compatible with IE4 and above, NS6 and above
function getObjectById(id)
{
	if (document.all)
		return document.all(id)
	else if (document.getElementById)
		return document.getElementById(id)
	else
		return null
}

// display number with given precision
// returns a string
function precision(num,p)
{
	if (!p || isNaN(num) || num.length == 0)
		return num
	num *= Math.pow(10,p)
	num = Math.round(num)
	num = num*10 + 1
	num /= Math.pow(10,p+1)
	num = num.toString()
	num = num.substring(0,num.length-1)
	return num
}

// trim long strings to a limit of chars and replace with ...
function RTrimWith3dots(str, nChars)
{
	var reg = new RegExp('^(.{' + (nChars - 3) + '})(.{4,})$')
	if (reg.test(str))
		str = str.replace(reg,'$1...')
	return str
}

function displayDate()
{
	try
	{
		var now = new Date();
		datestr = now.format("dd/mm/yyyy");				
		document.write(datestr);
	}
	catch(e)
	{
	
	}
}

//=============================================================
//	Function: Decode()
//
//	description:
//		an inline select case function which accept a variant
//		arguments length. function itereate through arguments list,
//		built of compare value, return value pairs, and compare each
//		compare value to its first argument. if a match is found its
//		following return value is returned. function must get at least
//		3 arguments.
//
//	input parameters:
//		i_vCompare			- variant. all compare values are matched to first argument
//		i_vCompareTo1		- variant. 1st compare value
//		i_vRetVal1			- variant. 1st return value
//		...
//		i_vCompareToN		- variant. N-th compare value
//		i_vRetValN			- variant. N-th return value
//		i_vDefaultRetVal	- variant. optinal default return value. returned if no match is found
//
//	return value:
//		variant
//=============================================================
function Decode(/*
	i_vCompare, 
	i_vCompareTo1, i_vRetVal1, ..., i_vCompareToN, i_vRetValN, 
	i_vDefaultRetVal
	*/)
{
	if (arguments.length < 3)
		return;
	
	var vCompare = arguments[0];
	var vCompareTo, vRetVal;
	
	// go through <compare to, return value> pairs. if a match is found return the
	// following return value
	for (var i = 1; i + 1 < arguments.length; i += 2) {
		vCompareTo = arguments[i];
		vRetVal = arguments[i + 1];
		if (vCompare == vCompareTo)
			return vRetVal;
	}
	
	// return optional default return value
	return arguments[i];
}

function debug()
{
	var str = '';
	do {
		str = prompt('input exp:',str);
		if (str)
			alert(str + ': ' + eval(str));
	} while(str.length > 0);
}

// get html elements offset top and left relative to window
// function returns an object with left and top properties
function getElementOffset(oElement)
{
	var oReturnObj = new Object();
	
	oReturnObj.left = 0;
	oReturnObj.top = 0;
	while(oElement) {
		oReturnObj.left += oElement.offsetLeft;
		oReturnObj.top += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	
	return oReturnObj;
}

// handle ilegal chars in url search parameter's value (?param1=value1&param2=value2)
// ilegal chars are: '&', '+', ' ', ','
// ilegal chars are replaced using the myEscape function
// cannot use the escape function since it converts hebrew characters to utf-8
function urlParam(str)
{
	var tmp = ''
	if (typeof(str) == 'string') {
		for (var i = 0; i < str.length; i++)
			tmp += myEscape(str.charAt(i))
	}
	return tmp
}

function myEscape(ch)
{
	switch(ch) {
	case '&':
	case ' ':
	case ',':
	case '=':
	case '?':
	case '%':
	case '#':
		return escape(ch);
	case '+':
		return '%2b'; // escape('+') == '+' and '+' converted to ' ' in url
	default:
		return ch;
	}
}

// extend String object
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/, '');
}


//=============================================================
//	function: resizeToFitContent()
//
//	description: fit window width and height to content
//
//	input parameters:
//		i_sObjId		-	string. object id by which window is to be extended. object must
//							be specified with style "overflow:hidden; width:100%; height:100%;"
//		i_bVerticalOnly	-	boolean. optional flag indicating whether resize should be applied
//							in vertical direction only. false by default
//=============================================================
function resizeToFitContent(i_sObjId, i_bVerticalOnly)
{
	var oContentContainer = document.getElementById(i_sObjId);
	if (!oContentContainer)
		return;
	
	i_bVerticalOnly = (i_bVerticalOnly == true);
	
	if (oContentContainer.scrollWidth > oContentContainer.offsetWidth || oContentContainer.scrollHeight > oContentContainer.offsetHeight) {
		var iWidthDiff = i_bVerticalOnly? 0: oContentContainer.scrollWidth - oContentContainer.offsetWidth;
		var iHeightDiff = oContentContainer.scrollHeight - oContentContainer.offsetHeight;
		if (!window.dialogHeight) {
			window.resizeBy(iWidthDiff, iHeightDiff);
			window.moveBy(-iWidthDiff/2, -iHeightDiff/2);
		}
		else {
			window.dialogHeight = (parseInt(window.dialogHeight) + iHeightDiff) + 'px';
			window.dialogTop = (parseInt(window.dialogTop) - iHeightDiff/2) + 'px';
			if (!i_bVerticalOnly) {
				window.dialogWidth = (parseInt(window.dialogWidth) + iWidthDiff) + 'px';
				window.dialogLeft = (parseInt(window.dialogLeft) - iWidthDiff/2) + 'px';
			}
		}
	}
}

//=============================================================
//	function: addFavorite()
//
//	description: add page to favorites
//
//	input parameters:
//		i_sUrl		-	string. optional favorite URL. if not specified then location.href will be used
//		i_sTitle	-	string. optional favorite title. if not specified then window.title will be used
//=============================================================
function addFavorite(i_sUrl, i_sTitle)
{
	var sUrl = i_sUrl || location.href;
	var sTitle = i_sTitle || window.title;
	
	if (window.sidebar) // Mozilla Firefox Bookmark
		window.sidebar.addPanel(sTitle, sUrl, "");
	else if (window.external) // IE Favorite
		window.external.AddFavorite(sUrl, sTitle);
	else if (window.opera && window.print) // opera
	{
		var oElem = document.createElement("a");
		oElem.setAttribute("href", sUrl);
		oElem.setAttribute("title", sTitle);
		oElem.setAttribute("rel", "sidebar");
		oElem.click();
	}
}

//=============================================================
//	function: setHomePage()
//
//	description: set page as default browser's home page IE only!!
//=============================================================
function setHomePage()
{
	if (document.body && document.body.style && document.body.style.behavior)
	{
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(window.location.href);
	}
}

//=============================================================
//	function: addRuntimeClass()
//
//	description: set an element's class.
//
//	parameters:
//		i_oElement	-	object. HTML element reference
//		i_sClassName	-	string. class name
//=============================================================
function addRuntimeClass(i_oElement, i_sClassName)
{
	if (!i_oElement || i_oElement.className == undefined || String.isNullOrEmpty(i_sClassName))
		return;
	
	var oReg = new RegExp("^" + i_sClassName + "$|^" + i_sClassName + "\\s+|\\s+" + i_sClassName + "\\s+|\\s+" + i_sClassName + "$", "i");
	if (!oReg.test(i_oElement.className))
		i_oElement.className += (i_oElement.className.length == 0 ? "" : " ") + i_sClassName;
}

//=============================================================
//	function: removeRuntimeClass()
//
//	description: remove an element's class.
//
//	parameters:
//		i_oElement	-	object. HTML element reference
//		i_sClassName	-	string. class name
//=============================================================
function removeRuntimeClass(i_oElement, i_sClassName)
{
	if (!i_oElement || i_oElement.className == undefined || String.isNullOrEmpty(i_sClassName))
		return;
	
	var sClassName = i_oElement.className.replace(/\s\s+/g, " ");
	var aClassNames = sClassName.split(" ");
	i_sClassName = i_sClassName.toLowerCase();
	for (var i = aClassNames.length - 1; i >= 0; i--)
	{
		if (aClassNames[i].toLowerCase() == i_sClassName)
			aClassNames.splice(i, 1);
	}
	
	i_oElement.className = aClassNames.join(" ");
}

//=============================================================
//	function: toggleMenu()
//
//	description: remove an element's class.
//
//	parameters:
//		i_oElement				-	object. HTML element reference
//		i_sMenuOpenedClassName	-	string. class name
//=============================================================
function toggleMenu(i_oElement, i_sMenuOpenedClassName)
{
	if (!i_oElement || i_oElement.className == undefined || String.isNullOrEmpty(i_sMenuOpenedClassName))
		return;
	
	if (!i_oElement.isMenuOpened)
		addRuntimeClass(i_oElement, i_sMenuOpenedClassName);
	else
		removeRuntimeClass(i_oElement, i_sMenuOpenedClassName);
	i_oElement.isMenuOpened = !i_oElement.isMenuOpened;
}


///////////////Cardiolog Statistics 19/4/2010 By Emil///////////////////////
//Intlock tracking code start

function __initCardioLogAgent() 
{
	try
	{
		if (typeof(document.__cardiolog) == "undefined") {
			document.__cardiolog = true;
			var script = document.createElement("script");
			script.src = "/CardioLogAgent/AgentEmbed.aspx?env=BasicAgent&r="+Math.random()*100000;
			document.body.appendChild(script);
		}
	}
	catch(e)
	{
		
	} 
}
try
{
	if (typeof(document.__jsloaderInterval) == "undefined") {
		if (navigator.userAgent.match(/Safari/i)) {
			document.BrowserType = "safari";
			document.__jsloaderInterval = window.setInterval(function() {
									if(document.readyState == "loaded" || document.readyState == "complete") {
										window.clearInterval(document.__jsloaderInterval);
										__initCardioLogAgent();
									}}, 10);
		} else if (document.addEventListener) {
			document.BrowserType = "ff";
			document.addEventListener("DOMContentLoaded", __initCardioLogAgent, false);
		} else if (document.all && !window.opera) {
			document.BrowserType = "safari";
			document.__jsloaderInterval = window.setInterval(function() {
									if(document.readyState == "loaded" || document.readyState == "complete") {
										window.clearInterval(document.__jsloaderInterval);
										__initCardioLogAgent();
									}}, 10);
		}  
	}
}
catch(e)
{
	
}
//Intlock tracking code end







