/*
* This file was modified by Kampyle LTD.
*/

/*
*
* Copyright (c) 2007 Andrew Tetlaw
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* FastInit
* http://tetlaw.id.au/view/javascript/fastinit
* Andrew Tetlaw
* Version 1.4.1 (2007-03-15)
*/
var FastInit = {
	onload : function() {
		if (FastInit.done) { return; }
		FastInit.done = true;
		for(var x = 0, al = FastInit.f.length; x < al; x++) {
			FastInit.f[x]();
		}
	},
	addOnLoad : function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') {
				if (FastInit.done ) {
					a[x]();
				} else {
					FastInit.f.push(a[x]);
				}
			}
		}
	},
	listen : function() {
		if (/WebKit|khtml/i.test(navigator.userAgent)) {
			FastInit.timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(FastInit.timer);
					delete FastInit.timer;
					FastInit.onload();
				}}, 10);
		} else if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', FastInit.onload, false);
		} else if(!FastInit.iew32) {
			if(window.addEventListener) {
				window.addEventListener('load', FastInit.onload, false);
			} else if (window.attachEvent) {
				return window.attachEvent('onload', FastInit.onload);
			}
		}
	},
	f:[],done:false,timer:null,iew32:false
};
/*@cc_on @*/
/*@if (@_win32 || @_win64)
FastInit.iew32 = true;
document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInit.onload(); }};
/*@end @*/
FastInit.listen();

/////////////////////////////////////////////////////////////////
var aaa = 0; 
if (typeof(k_push_vars) == "undefined")
{
	k_push_vars = {}
}
var k_push = {
	"popup_w": 380,
	"popup_h": 150,

	"myWidth": 0,
	"myHeight": 0,
	"popup_open": false,
	"counter": 0,
	"lastPosy": null,

	"getSize": function () {
		//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
	  if (typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    k_push.myWidth = window.innerWidth;
	    k_push.myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    k_push.myWidth = document.documentElement.clientWidth;
	    k_push.myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    k_push.myWidth = document.body.clientWidth;
	    k_push.myHeight = document.body.clientHeight;
	  }
	},
	
	"getScrollY": function () {
		var scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
		//	alert(1)
		} else if( document.body && (document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
		} else if (document.documentElement && (document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
		}
		return scrOfY;
	},

	"mousePos": function (e){
		if (k_push.popup_open) 
			return;
		k_push.getSize();
		//http://www.quirksmode.org/js/events_properties.html
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			//posy = e.clientY + document.body.scrollTop
			//	+ document.documentElement.scrollTop;
			posy = e.clientY + k_push.getScrollY();
		}
		aaa = k_push.myHeight/2-k_push.popup_h/2+document.body.scrollTop;
		if (k_push.lastPosy == null)
		{
			k_push.lastPosy = posy;
		}
		else
		{
			if (k_push.lastPosy < posy)
			{
				k_push.lastPosy = posy;
			}
			else
			{
				//if (posy < document.body.scrollTop + document.documentElement.scrollTop + 15) 
				if (posy < k_push.getScrollY() + 15) 
				{
					k_push.openPopup();
				}
			}
		}
	},

	"popup_init": function () {

		document.onmousemove = k_push.mousePos;
		var maskBG = document.createElement('div');
		maskBG.setAttribute('id','k_maskBG');
		
		document.body.appendChild(maskBG);
		
		var popup = document.createElement('div');
		popup.setAttribute('id','k_popup');
		popup.style.width=k_push.popup_w+'px';
		popup.style.height=k_push.popup_h+'px';
		popup.style.position='absolute';
		popup.style.top='0px';
		popup.style.left='0px';
		popup.style.zIndex='999';
		popup.style.fontFamily = 'arial';
		popup.style.fontWeight = 'bold';
		popup.style.color = (k_push_vars.popup_font_color) ? k_push_vars.popup_font_color : '#000000';
		k_push.ff_link_id = (k_push_vars.ff_link_id) ? k_push_vars.ff_link_id : 'kampylink';

		popup.innerHTML="<div style='border-bottom: 1px solid #ffffff; text-align: center; font-size: 20px; padding: 10px;'><strong>Your feedback is important to us!</strong></div><div style='border-bottom: 1px solid #ffffff; font-size: 11px; padding: 10px 0 10px 0; text-align: center;  '>Would you be willing to give us a short (1 minute) feedback?<div style='margin: 0 auto; width: 138px; padding: 10px 0 0 0;'><a style='background-color:#76AC78;border-color:#D9DFEA rgb(14, 31, 91) rgb(14, 31, 91) rgb(217, 223, 234);border-style:solid;border-width:1px;padding:2px 15px 3px;text-align:center;font-size:11px;font-weight: bold; text-decoration: none; color: black; width: 26px; float: left;' href='javascript: void(0)' onclick='document.getElementById(\""+k_push.ff_link_id+"\").onclick();k_push.closePopup(); return false;'>Yes</a><a style='background-color:#8D9B86;border-color:#D9DFEA rgb(14, 31, 91) rgb(14, 31, 91) rgb(217, 223, 234);border-style:solid;border-width:1px;padding:2px 15px 3px;text-align:center;font-size:11px;font-weight: bold; text-decoration: none; color: black;  width: 26px; float: right;' href='javascript: void(0)' onclick='k_push.closePopup(); return false;'>No</a><div style='clear:both'></div></div></div><div style='font-size: 11px; padding: 10px 0 6px 0; text-align: center;'>Thank you for helping us improve our website</div>";
		popup.style.background= (k_push_vars.popup_background) ? k_push_vars.popup_background : '#D0DDE5';
		popup.style.display='none';
		
		document.body.appendChild(popup);
	},


	"openPopup": function () {
		k_push.Set_Cookie('k_push8', '1', '21', '/', '', '' );
		if ((k_push.popup_open) || (k_push.counter > 0) || (!document.getElementById(k_push.ff_link_id)))
			return;

		k_push.counter++;
		k_push.popup_open=true;
		var maskBG=document.getElementById('k_maskBG')
		var popup=document.getElementById('k_popup')

		//popup.style.top=k_push.myHeight/2-k_push.popup_h/2+document.body.scrollTop+document.documentElement.scrollTop+'px';

		//popup.style.top=k_push.myHeight/2-k_push.popup_h/2+k_push.getScrollY()+'px';

		popup.style.top=(k_push.myHeight/2)-(k_push.popup_h/2)+document.body.scrollTop+'px';
		popup.style.left=k_push.myWidth/2-k_push.popup_w/2+'px';
		
		popup.style.display = 'block';

		maskBG.innerHTML = '<div style="width: 100%; height: 100%; opacity: .7; filter: alpha(opacity=70); background-color:transparent !important;	background-color: #333333; background-image/**/: url(\'/images/maskBG.png\') !important; background-image:none; background-repeat: repeat;"></div>';
		maskBG.style.position='absolute';
		maskBG.style.top='0px';
		maskBG.style.left='0px';
		maskBG.style.zIndex='998';
		maskBG.style.width=document.body.scrollWidth+'px';
		//maskBG.style.height=document.body.scrollHeight+'px';
		//maskBG.style.height='100%';
		
		//maskBG.style.height = (document.documentElement.scrollHeight > document.body.scrollHeight) ? document.documentElement.scrollHeight : document.body.scrollHeight;
		//maskBG.style.height = window.innerHeight+'px';
		var h = (document.documentElement.scrollHeight > document.body.scrollHeight) ? document.documentElement.scrollHeight : document.body.scrollHeight;
		maskBG.style.height = h+'px';
		maskBG.style.display='block';
		//if (!document.all)
			//document.body.style.overflow='hidden';
	},

	"closePopup": function () {
		k_push.popup_open=false;
		var maskBG=document.getElementById('k_maskBG');
		var popup=document.getElementById('k_popup');
		popup.style.display='none';
		maskBG.style.display='none';
		//if (!document.all)
			//document.body.style.overflow='auto';
	},
	
	"Set_Cookie": function ( name, value, expires, path, domain, secure ) 
	{
		var today = new Date();
		today.setTime( today.getTime() );
		
		if ( expires )
		{
		expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	},

	"Get_Cookie": function (name) 
	{
	
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) &&
		( name != document.cookie.substring( 0, name.length ) ) )
		{
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
		
	}
};
/*
if (window.addEventListener){ // Mozilla, Netscape, Firefox
	window.addEventListener('load', k_push.popup_init, false);
} else { // IE
	window.attachEvent('onload', k_push.popup_init);
}*/
k_push.n = (k_push_vars.view_percentage && ((k_push_vars.view_percentage >= 0) && (k_push_vars.view_percentage <= 100))) ? k_push_vars.view_percentage : 10;
	
if (((k_push.n==null) || ( ((Math.random() * 100) < k_push.n) )))
{
	if (!k_push_vars.disable_cookie)
	{
		if (!k_push.Get_Cookie('k_push8'))
		{
			FastInit.addOnLoad(k_push.popup_init);
		}
	}
	else
	{
		FastInit.addOnLoad(k_push.popup_init);
	}
}