morinside.co.il Open in urlscan Pro
192.116.40.222  Public Scan

URL: https://morinside.co.il/wp-content/themes/mormar/js/ready.js
Submission Tags: falconsandbox
Submission: On October 07 via api from US — Scanned from IL

Form analysis 0 forms found in the DOM

Text Content

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    ChromeOnIos: function() {
        return navigator.userAgent.match(/CriOS/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.ChromeOnIos() || isMobile.Windows());
    }
};

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*3600*1000));
    if (exdays != 0){
    var expires = "expires="+d.toGMTString();
    document.cookie = cname + "=" + true + "; " + expires + "; path=/; domain=.mormar.co.il";
    }
    else {
	document.cookie = cname + "=" + false + "; path=/; domain=.mormar.co.il";
    }

}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}


$(document).ready(function() {

var theWidth=$(window).width();
var theHeight=$(window).height();
var minHeight = theHeight - $('#header').height()-55;

if ($('body').hasClass('home')){

$('#welcome').height(theHeight - theHeight/10);
$('#welcome').css('padding-top', theHeight/10);
$('#welcome .banner img').load(function(){
var bannerH= $('#welcome .banner').height();
	var imgH=$('#welcome .banner img').height();
	var paddH=(bannerH-imgH);
	$('#welcome .banner img').css('padding-top',paddH);
});

var langSwitch=$('#lang_sel_list').html();
$('#langCopy').html(langSwitch);

i = 0; //Start a counter
			setInterval(function(){
				i++;
				if (i% 2 === 0 ){
				$('#arrow').animate({bottom: '+=10'}, 250).animate({bottom: '-=10'}, 250);
				}
				else {
				$('#arrow').animate({bottom: '+=10'}, 500).delay(200).animate({bottom: '-=10'}, 500);
				}
				}
				,250);

var navH=$('.homeNav .icons').height();
var navImgH= navH * 54 / 100;
var imgText = navImgH + 30;
if (theHeight > 900) {
var imgText = navImgH + 40;
}

var paddImg=(navH - imgText) / 2;
$('.homeNav .icons li img').height(navImgH).css('margin-top', paddImg);


$('.homeNav .icons li').mouseenter(function() {
		$( this ).find('img').animate({marginTop: '-=5'}, 200, 'linear', function(){
			$( this ).animate({marginTop: '+=5'}, 200,'linear');
		});
		});

/*$('.homeNav .icons li').mouseenter(function() {
		$( this ).find('img').css('margin-top', paddImg-5);
		}).mouseleave(function() {
		$( this ).find('img').css('margin-top', paddImg);
});
*/

}

$('ul li:empty').remove();


if ($('#content').hasClass('info')) {


	$('#steps ul li p').each(function(){
		var pH= (152 - $(this).height()) / 2;
		$(this).css('padding-top', pH);
	});
	$('#sidebar-info ul li:first').addClass('current');

	 $('#faq-list h3').click(function() {
                $(this).next('.answer').slideToggle(500);
                $(this).toggleClass('close');
            });

    $('#sidebar-info ul li a, #topInfoMenu ul li a').click(function(e){
				if (!$(this).parent().hasClass('types')) {
				e.preventDefault();
			    var scrollToDiv= $(this).attr('href');
			    var theLink=$(this);
			    var toDiv= $(scrollToDiv).offset().top-130;
			    if (toDiv<0){
				    toDiv=0;
			    }
			    $('#sidebar-info ul li').removeClass('current');
					$(theLink).parent().addClass('current');
			    $('html, body').animate({scrollTop: toDiv}, 500, function() {
										});
										}
			});
}


if ($('#content').hasClass('testTypes')){
		$('#sidebar-info ul li:last').addClass('current');
		 $("#menu ul li:first").addClass('current-menu-item');
		 $('.post.type').each(function(){
		var postH= $(this).outerHeight();
		var thumbP= (postH - 153) / 2;
		$(this).find('.thumb').css('padding-top', thumbP);
	});


}

if ($('#content').hasClass('half')){

$(".chosen-select").chosen({
    placeholder_text_single: "׳‘׳—׳¨ ׳׳× ׳ ׳•׳©׳ ׳”׳₪׳ ׳™׳™׳”",
    width: "100%",
    disable_search: true
  });
$('#setAppointment').attr('disabled','disabled');

$('.rightSide').css('min-height', minHeight);
var rightSideH = $('.rightSide .cont').height();
var rightSideP = (minHeight - rightSideH) / 2;
if (rightSideH < minHeight){
$('.rightSide .cont').css('padding-top', rightSideP);
}


}




if ($('#content').hasClass('blog') || $('#content').hasClass('blog-single') ){

$('#experts-list ul li:gt(2)').hide();

if($('#experts-list ul li:gt(2)').length === 0){
	$('#moreExperts').hide();
}
$(document).on('click', '#moreExperts', function(e){
e.preventDefault();
$('#experts-list ul li:gt(2)').fadeIn(600, function(){
	$('#moreExperts').hide();
});
});

$('#content').css('min-height',minHeight);
}


$('.current-post-ancestor, .current-category-ancestor').addClass('current-menu-item');

$('#mailLink').on('click',
function() {
  return confirm('׳‘׳¨׳¦׳•׳ ׳ ׳• ׳œ׳”׳×׳¨׳™׳¢ ׳‘׳₪׳ ׳™׳™׳š ׳›׳™ ׳”׳©׳™׳ž׳•׳© ׳‘׳“׳•׳׳¨ ׳׳œ׳§׳˜׳¨׳•׳ ׳™ ׳׳™׳ ׳• ׳ ׳˜׳•׳œ ׳¡׳™׳›׳•׳ ׳™׳, ׳¡׳₪׳§׳™׳•׳× ׳“׳•׳"׳œ ׳—׳™׳ ׳ž׳™׳•׳× ׳”׳ ׳Ÿ ׳—׳©׳•׳₪׳•׳× ׳•׳₪׳’׳™׳¢׳•׳× ׳œ׳’׳ ׳™׳‘׳× ׳•׳׳•׳‘׳“׳Ÿ ׳ž׳™׳“׳¢ ׳׳™׳©׳™. ׳”׳©׳™׳ž׳•׳© ׳‘׳ž׳“׳™׳” ׳–׳• ׳ ׳×׳•׳ ׳” ׳œ׳©׳™׳§׳•׳œ ׳“׳¢׳×׳š ׳”׳׳™׳©׳™׳× ׳•׳‘׳׳—׳¨׳™׳•׳×׳š ׳‘׳œ׳¢׳“׳™׳×. ׳”׳©׳™׳ž׳•׳© ׳‘׳“׳•׳"׳œ ׳œ׳©׳œ׳™׳—׳× ׳ž׳¡׳ž׳›׳™׳ ׳¨׳₪׳•׳׳™׳™׳ ׳ž׳”׳•׳•׳” ׳”׳¡׳›׳ž׳” ׳œ׳×׳ ׳׳™ ׳”׳©׳™׳¨׳•׳× ׳•׳₪׳•׳˜׳¨/׳× ׳׳× ׳ž׳›׳•׳Ÿ ׳ž׳•׳¨-׳ž׳׳¨ ׳ž׳׳—׳¨׳™׳•׳× ׳‘׳ž׳§׳¨׳” ׳©׳œ ׳—׳©׳™׳₪׳× ׳ž׳™׳“׳¢ ׳¨׳₪׳•׳׳™ ׳•/׳׳• ׳׳—׳¨ ׳׳•׳“׳•׳×׳™׳™׳š. ׳¢׳ ׳”׳’׳¢׳× ׳”׳ž׳¡׳ž׳›׳™׳ ׳œ׳ž׳›׳•׳Ÿ ׳ž׳•׳¨-׳ž׳׳¨ ׳”׳ž׳™׳“׳¢ ׳ž׳׳•׳—׳¡׳Ÿ ׳‘׳©׳¨׳×׳™׳ ׳©׳œ ׳ž׳•׳¨ ׳ž׳׳¨. ׳”׳©׳¨׳×׳™׳, ׳›׳ž׳• ׳’׳ ׳›׳œ ׳ž׳¢׳¨׳›׳•׳× ׳”׳ž׳™׳“׳¢ ׳©׳œ ׳ž׳•׳¨ ׳ž׳׳¨, ׳ž׳׳•׳‘׳˜׳—׳™׳ ׳‘׳׳ž׳¦׳¢׳™׳ ׳”׳ž׳×׳§׳“׳ž׳™׳ ׳‘׳¢׳•׳œ׳, ׳•׳ž׳ ׳•׳˜׳¨׳™׳ ׳‘׳›׳œ ׳¢׳×. ׳ž׳•׳¨ ׳ž׳׳¨ ׳ ׳•׳§׳˜׳× ׳ž׳“׳™׳ ׳™׳•׳× ׳׳‘׳˜׳—׳× ׳ž׳™׳“׳¢ ׳§׳₪׳“׳ ׳™׳× ׳›׳“׳™ ׳œ׳”׳‘׳˜׳™׳— ׳׳× ׳—׳™׳¡׳™׳•׳Ÿ ׳”׳ž׳™׳“׳¢ ׳©׳œ ׳œ׳§׳•׳—׳•׳×׳™׳”. ׳‘׳”׳×׳׳ ׳œ׳×׳§׳Ÿ ISO 27799 ׳œ׳׳‘׳˜׳—׳× ׳ž׳™׳“׳¢ ׳¨׳₪׳•׳׳™.');
});


/*---------MENU-------*/

if ($('body').hasClass('home')){
		 var $el, leftPos, newWidth;
    if ($('body').hasClass('rtl')){
     $("#menu ul").append("<li id='magic-line'></li>");
     var $magicLine = $("#magic-line");
    $magicLine
        .width($("#top a").width())
        .css("left", $("#top a").position().left)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());

    $("#menu ul li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.width();

        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        });
    });
    }
    else {
	       $("#menu ul").append("<li id='magic-line'></li>");
     var $magicLine = $("#magic-line");
    $magicLine
        .width($("#top a").width())
        .css("left", $("#top a").position().left - 300)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());

    $("#menu ul li").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.width();

        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        });
    });
    }
    }

else if (!$('body').hasClass('page-template-resultsServiceN-php')) {

$(window).load(function() {
	var $el, leftPos, newWidth;
     $("#menu ul").append("<li id='magic-line'></li>");
     var $magicLine = $("#magic-line");
     if($("#menu .current-menu-item a").length){
		 var magicWidth=$("#menu .current-menu-item a").width();
		 var magicLeft=$("#menu .current-menu-item a").position().left;
		 $("#magic-line").width(magicWidth).css("left", magicLeft);
		 $magicLine.data("origLeft", magicLeft)
			 .data("origWidth", magicWidth);
	 }

    $("#menu ul li").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.width();

        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
    var magicWidth=$("#menu .current-menu-item").width();
     var magicLeft=$("#menu .current-menu-item").position().left;
        $magicLine.stop().animate({
            left: magicLeft,
            width: magicWidth
        });
    });
    });
      }
	//end menu

	$('.welcomeFooter .social a, #footer .social a').hover(
function() {
var hoverSrc=$(this).find('img.bottom').attr('src');
var regSrc=$(this).find('img.top').attr('src');
$(this).find('img.top').attr('src',hoverSrc);
$(this).find('img.bottom').attr('src',regSrc);
}, function() {
var regSrc=$(this).find('img.bottom').attr('src');
var hoverSrc=$(this).find('img.top').attr('src');
$(this).find('img.top').attr('src',regSrc);
$(this).find('img.bottom').attr('src',hoverSrc);
});




$(window).resize(function(){

var theWidth=$(window).width();
var theHeight=$(window).height();
var minHeight = theHeight - $('#header').height();
if ($('body').hasClass('home')){
$('#welcome').height(theHeight - theHeight/10);
$('#welcome').css('padding-top', theHeight/10);
var bannerH= $('#welcome .banner').height();
	var imgH=$('#welcome .banner img').height();
	var paddH=(bannerH-imgH);
	$('#welcome .banner img').css('padding-top',paddH);
	var navH=$('.homeNav .icons').height();
var navImgH=$('.homeNav .icons li:first img').height()+30;
if (theHeight > 900) {
	var navImgH=$('.homeNav .icons li:first img').height()+40;
}
var paddImg=(navH - navImgH) / 2;
$('.homeNav .icons li img').css('margin-top', paddImg);




}

$('.rightSide').css('min-height', minHeight);
var rightSideH = $('.rightSide .cont').outerHeight();
var rightSideP = (minHeight - rightSideH) / 2;
$('.rightSide .cont').css('padding-top', rightSideP);

$('.leftSide').height(theHeight - 80);

		});
//end resize start scroll stuff

if($('#content').hasClass('info')) {
			$(window).scroll(function() {
			var theHeight=$(window).height();
			var lastQP= $('#faq').offset().top + $('#faq').height() - $('#sidebar-info').height() - 110;
			/*
			if(theWidth > 1360) {
				if($('#topInfoMenu').offset().top < $(window).scrollTop() ){
			$('#sidebar-info').addClass('in');

			}
			else {
							$('#sidebar-info').removeClass('in');
			}
			}
			else {
			if($('#child-1').offset().top - 150 < $(window).scrollTop() ){
			$('#sidebar-info').addClass('in');

			}
			else {
							$('#sidebar-info').removeClass('in');
			}
			*/

				$('#sidebar-info ul li a').each(function(){
			if (!$(this).parent().hasClass('types')) {
			var scrollToDiv= $(this).attr('href');
			if($(scrollToDiv).offset().top-145 < $(window).scrollTop() ) {
				$('#sidebar-info ul li').removeClass('current');
				$(this).parent().addClass('current');
			}
			}
			});

			if (lastQP < $(window).scrollTop() ) {
			if ($('#sidebar-info').hasClass('fixed')) {
				$('#sidebar-info').css({position: 'absolute', top: lastQP+30 });
				$('#sidebar-info').removeClass('fixed');
				}
			}
			else {
								$('#sidebar-info').css({position: 'fixed', top: '110px'});
												$('#sidebar-info').addClass('fixed');
			}
});
}

if($('#content').hasClass('testTypes')) {
			$(window).scroll(function() {
			var theHeight=$(window).height();
			var lastQP= $('#content .postTypesWrap').offset().top + $('#content .postTypesWrap').height() - $('#sidebar-info').height() - 110;

			if (lastQP < $(window).scrollTop() ) {
			if ($('#sidebar-info').hasClass('fixed')) {
				$('#sidebar-info').css({position: 'absolute', top: lastQP+30 });
				$('#sidebar-info').removeClass('fixed');
				}
			}
			else {
								$('#sidebar-info').css({position: 'fixed', top: '110px'});
												$('#sidebar-info').addClass('fixed');
			}
});
}

//end scroll in info pages



 $(window).scroll(function(){
 if ($('#postsWrapper .postsWrap .navigation').length > 0){
    if($("#postsWrapper .postsWrap .navigation:last").position().top > ($(window).scrollTop() - theHeight)){
    if (loading==false){
      $("#postsWrapper .postsWrap .navigation:last").find('a').click();
      }
}
}
});


var loading=false;
$('#content.blog').on('click', '.navigation a', function(e){
		 loading=true;
        e.preventDefault();
        $(this).hide();
        $('.ajaxLoader').fadeIn(500);
        var link = $(this).attr('href');
        $("<div>").load(link, function() {
          $("#postsWrapper .postsWrap").append($(this).find("#postsWrapper .postsWrap").html());
                  $('.ajaxLoader').fadeOut(500, function(){
	                  $('.post').click(function(){
						var theLink=$(this).find('.readMore').attr('href');
						location.href=theLink;
					});
                  });

                  loading=false;
    });
             });




				if ( $('body').hasClass('home')){
					(function() {

				// detect if IE : from http://stackoverflow.com/a/16657946
				var ie = (function(){
					var undef,rv = -1; // Return value assumes failure.
					var ua = window.navigator.userAgent;
					var msie = ua.indexOf('MSIE ');
					var trident = ua.indexOf('Trident/');

					if (msie > 0) {
						// IE 10 or older => return version number
						rv = parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
					} else if (trident > 0) {
						// IE 11 (or newer) => return version number
						var rvNum = ua.indexOf('rv:');
						rv = parseInt(ua.substring(rvNum + 3, ua.indexOf('.', rvNum)), 10);
					}

					return ((rv > -1) ? rv : undef);
				}());


				// disable/enable scroll (mousewheel and keys) from http://stackoverflow.com/a/4770179
				// left: 37, up: 38, right: 39, down: 40,
				// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
				var keys = [33, 37, 34, 38, 39, 40], wheelIter = 0;

				function preventDefault(e) {
					e = e || window.event;
					if (e.preventDefault)
					e.preventDefault();
					e.returnValue = false;
				}

				function keydown(e) {
					for (var i = keys.length; i--;) {
						if (e.keyCode === keys[i]) {
							preventDefault(e);
							return;
						}
					}
				}

				function touchmove(e) {
				}

				function wheel(e) {
					// for IE
					//if( ie ) {
						//preventDefault(e);
					//}
				}

				function disable_scroll() {
					window.onmousewheel = document.onmousewheel = wheel;
					document.onkeydown = keydown;
				}

				function enable_scroll() {
					window.onmousewheel = document.onmousewheel = document.onkeydown =  null;
				}

				var docElem = window.document.documentElement,
					scrollVal,
					isRevealed,
					noscroll,
					isAnimating,
					container = document.getElementById( 'welcome' ),
					trigger = document.getElementById( 'arrow' );

				function scrollY() {
					return window.pageYOffset || docElem.scrollTop;
				}

				function scrollPage() {
					scrollVal = scrollY();
					var windowWidth= $(window).width();
				if (windowWidth > 800){

					if( noscroll && !ie ) {
						if( scrollVal < 0 ) return false;
						// keep it that way
						window.scrollTo( 0, 0 );
					}

					if( classie.has( container, 'notrans' ) ) {
						classie.remove( container, 'notrans' );
						return false;
					}

					if( isAnimating ) {
						return false;
					}

					if( scrollVal <= 0 && isRevealed ) {
						toggle(0);
					}
					else if( scrollVal > 0 && !isRevealed ){
						toggle(1);
					}

				}
				}

				function toggle( reveal ) {
					isAnimating = true;

					if( reveal ) {
						classie.add( container, 'modify' );
						$('#header').stop(true,true).animate({marginLeft:'0'},700,function(){
											$(this).addClass('open');
										isAnimating = false;
										});
					}
					else {
						noscroll = true;
						disable_scroll();
						classie.remove( container, 'modify' );
						$('#header').stop(true,true).animate({marginLeft:'-341px'},700,function(){
											$(this).removeClass('open');
																	isAnimating = false;
										});
					}

					// simulating the end of the transition:
					setTimeout( function() {
						isRevealed = !isRevealed;
						if( reveal ) {
							noscroll = false;
							enable_scroll();
						}
					}, 700 );
				}

				// refreshing the page...
				var pageScroll = scrollY();
				noscroll = pageScroll === 0;
				disable_scroll();
				if( pageScroll ) {
					isRevealed = true;
					classie.add( container, 'notrans' );
					classie.add( container, 'modify' );
				}
				var windowWidth= $(window).width();
				if (windowWidth > 800){
				$(window).scroll(function(){
					scrollPage();
				});
				$(trigger).click(function(){
					toggle( 'reveal' );
				});

				}

			})();

			}
//end scrollthing


	$('#fade').click(function(){
		$('#terms, #confirm').hide();
		$(this).hide();
	});


});
//end ready


if (isMobile.any()){
$(document).ready(function() {
	var langSwitch=$('#lang_sel_list').html();
	$('#langMobile').html(langSwitch);
	var headerOpenH= $('#header').height() + $('#mobile-menu').height() - 4;
	$('#mobileMenu').click(function(){
	if ($('#header').hasClass('open')){
	$('#mobileMenu').removeClass('rotated');
		$('#header').animate({height: '4.73rem'}, 400, function(){
		$(this).removeClass('open');
	});
	}
	else {
		$('#mobileMenu').addClass('rotated');
			$('#header').animate({height: headerOpenH}, 400, function(){
				$(this).addClass('open');
			});
	}
	});
	$('#top').click(function(){
		window.location= '/';
	});

	var visited=getCookie("visited");
 		if (visited != null && visited!="" && visited !='false') {
	    }
	    else{
		    	if( ($('body').hasClass('home') || $('body').hasClass('page-id-21') || $('body').hasClass('page-id-24'))  && $('body').hasClass('rtl') ){
		    		$('#bannerWrap').addClass('shown');
					setCookie("visited", visited, 1);
					setTimeout(function(){
						$('#bannerWrap').removeClass('shown');
						}, 5000);
				}
		}
	$('#bannerWrap .close').click(function(e){
		e.preventDefault();
		$('#bannerWrap').removeClass('shown');
	});

});

}

/*!
 * classie v1.0.1
 * class helper functions
 * from bonzo https://github.com/ded/bonzo
 * MIT license
 *
 * classie.has( elem, 'my-class' ) -> true/false
 * classie.add( elem, 'my-new-class' )
 * classie.remove( elem, 'my-unwanted-class' )
 * classie.toggle( elem, 'my-class' )
 */

/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, module: false */

( function( window ) {

'use strict';

// class helper functions from bonzo https://github.com/ded/bonzo

function classReg( className ) {
  return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}

// classList support for class management
// altho to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;

if ( 'classList' in document.documentElement ) {
  hasClass = function( elem, c ) {
    return elem.classList.contains( c );
  };
  addClass = function( elem, c ) {
    elem.classList.add( c );
  };
  removeClass = function( elem, c ) {
    elem.classList.remove( c );
  };
}
else {
  hasClass = function( elem, c ) {
    return classReg( c ).test( elem.className );
  };
  addClass = function( elem, c ) {
    if ( !hasClass( elem, c ) ) {
      elem.className = elem.className + ' ' + c;
    }
  };
  removeClass = function( elem, c ) {
    elem.className = elem.className.replace( classReg( c ), ' ' );
  };
}

function toggleClass( elem, c ) {
  var fn = hasClass( elem, c ) ? removeClass : addClass;
  fn( elem, c );
}

var classie = {
  // full names
  hasClass: hasClass,
  addClass: addClass,
  removeClass: removeClass,
  toggleClass: toggleClass,
  // short names
  has: hasClass,
  add: addClass,
  remove: removeClass,
  toggle: toggleClass
};

// transport
if ( typeof define === 'function' && define.amd ) {
  // AMD
  define( classie );
} else if ( typeof exports === 'object' ) {
  // CommonJS
  module.exports = classie;
} else {
  // browser global
  window.classie = classie;
}

})( window );



var _debug = false;
var _placeholderSupport = function() {
    var t = document.createElement("input");
    t.type = "text";
    return (typeof t.placeholder !== "undefined");
}();

window.onload = function() {
    var arrInputs = document.getElementsByTagName("input");
    var arrTextareas = document.getElementsByTagName("textarea");
    var combinedArray = [];
    for (var i = 0; i < arrInputs.length; i++)
        combinedArray.push(arrInputs[i]);
    for (var i = 0; i < arrTextareas.length; i++)
        combinedArray.push(arrTextareas[i]);
    for (var i = 0; i < combinedArray.length; i++) {
        var curInput = combinedArray[i];
        if (!curInput.type || curInput.type == "" || curInput.type == "text" || curInput.type == "textarea")
            HandlePlaceholder(curInput);
        else if (curInput.type == "password")
            ReplaceWithText(curInput);
    }

    if (!_placeholderSupport) {
        for (var i = 0; i < document.forms.length; i++) {
            var oForm = document.forms[i];
            if (oForm.attachEvent) {
                oForm.attachEvent("onsubmit", function() {
                    PlaceholderFormSubmit(oForm);
                });
            }
            else if (oForm.addEventListener)
                oForm.addEventListener("submit", function() {
                    PlaceholderFormSubmit(oForm);
                }, false);
        }
    }
};

function PlaceholderFormSubmit(oForm) {
    for (var i = 0; i < oForm.elements.length; i++) {
        var curElement = oForm.elements[i];
        HandlePlaceholderItemSubmit(curElement);
    }
}

function HandlePlaceholderItemSubmit(element) {
    if (element.name) {
        var curPlaceholder = element.getAttribute("placeholder");
        if (curPlaceholder && curPlaceholder.length > 0 && element.value === curPlaceholder) {
            element.value = "";
            window.setTimeout(function() {
                element.value = curPlaceholder;
            }, 100);
        }
    }
}

function ReplaceWithText(oPasswordTextbox) {
    if (_placeholderSupport)
        return;
    var oTextbox = document.createElement("input");
    oTextbox.type = "text";
    oTextbox.id = oPasswordTextbox.id;
    oTextbox.name = oPasswordTextbox.name;
    //oTextbox.style = oPasswordTextbox.style;
    oTextbox.className = oPasswordTextbox.className;
    for (var i = 0; i < oPasswordTextbox.attributes.length; i++) {
        var curName = oPasswordTextbox.attributes.item(i).nodeName;
        var curValue = oPasswordTextbox.attributes.item(i).nodeValue;
        if (curName !== "type" && curName !== "name") {
            oTextbox.setAttribute(curName, curValue);
        }
    }
    oTextbox.originalTextbox = oPasswordTextbox;
    oPasswordTextbox.parentNode.replaceChild(oTextbox, oPasswordTextbox);
    HandlePlaceholder(oTextbox);
    if (!_placeholderSupport) {
        oPasswordTextbox.onblur = function() {
            if (this.dummyTextbox && this.value.length === 0) {
                this.parentNode.replaceChild(this.dummyTextbox, this);
            }
        };
    }
}

function HandlePlaceholder(oTextbox) {
    if (!_placeholderSupport) {
        var curPlaceholder = oTextbox.getAttribute("placeholder");
        if (curPlaceholder && curPlaceholder.length > 0) {
            Debug("Placeholder found for input box '" + oTextbox.name + "': " + curPlaceholder);
            oTextbox.value = curPlaceholder;
            oTextbox.setAttribute("old_color", oTextbox.style.color);
            oTextbox.style.color = "#094c67";
            oTextbox.onfocus = function() {
                var _this = this;
                if (this.originalTextbox) {
                    _this = this.originalTextbox;
                    _this.dummyTextbox = this;
                    this.parentNode.replaceChild(this.originalTextbox, this);
                    _this.focus();
                }
                Debug("input box '" + _this.name + "' focus");
                _this.style.color = _this.getAttribute("old_color");
                if (_this.value === curPlaceholder)
                    _this.value = "";
            };
            oTextbox.onblur = function() {
                var _this = this;
                Debug("input box '" + _this.name + "' blur");
                if (_this.value === "") {
                    _this.style.color = "#094c67";
                    _this.value = curPlaceholder;
                }
            };
        }
        else {
            Debug("input box '" + oTextbox.name + "' does not have placeholder attribute");
        }
    }
    else {
        Debug("browser has native support for placeholder");
    }
}

function Debug(msg) {
    if (typeof _debug !== "undefined" && _debug) {
        var oConsole = document.getElementById("Console");
        if (!oConsole) {
            oConsole = document.createElement("div");
            oConsole.id = "Console";
            document.body.appendChild(oConsole);
        }
        oConsole.innerHTML += msg + "<br />";
    }
}