function hvr_Get_Cookie(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));
}

function hvr_is_valid_user() {
	return hvr_Get_Cookie('ValidUser');
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function hvr_do_load(){
//
// https://www.hvr.co.il	-> http://www.hvr.co.il
// https://www.hvr.co.il/	-> http://www.hvr.co.il
// http://www.hvr.co.il		-> http://www.hvr.co.il
// hvr.co.il			-> http://www.hvr.co.il
// hvr.co.il/			-> http://www.hvr.co.il
//
//	if after 'hvr.co.il' no more the 2 chars then change to 'http://www.hvr.co.il'
//
	var s;
	if ( !hvr_is_valid_user() ){
		Set_Cookie('MasterCookie','MasterCookie');
		var r = window.location.href;

		var f = 'hvr.co.il';
		if ( r.indexOf(f)>=0 ){
			if(r.indexOf(f)+f.length+2>=r.length) 
				r = 'http://www.hvr.co.il';
		}

		r = r.split("/");
		if ( r[2].substr(0,3) != 'www')
			s='https://www.'+r[2]+'/hvr_login.html?reffer='+r[0] + '//www.' + r[2];
		else
			s='https://'+r[2]+'/hvr_login.html?reffer='+r.join('/');

		window.location.href=s;
		//window.location.href='https://'+r[2]+'/hvr_login.html?reffer='+window.location.href;
		}
	hvr_do_redirect();

	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", hvr_set_interval, false);
		}
	else {
		document.onreadystatechange=hvr_doc_ready;
		}
}

function hvr_do_redirect(){
	var url = window.location.href;
	var ipos = url.indexOf("?");
	if(ipos>0){
		url = url.substr(ipos+1);
		if(url.length>1){
			var rFrame = document.getElementById("result");
			if(rFrame){
				rFrame.src = url;	
				}
			}
		}
}


function hvr_set_interval(){
	timer=setInterval("hvr_auto_logout()",300000); // 15 min 
}
 
function hvr_reset_interval()
{
	clearInterval(timer);
	hvr_set_interval();
}
 
function hvr_auto_logout()
{
	//document.location.href = "hvr_logoff.asp";
}


function hvr_doc_ready()
{
	if (document.readyState=="complete") {
		hvr_set_interval();
		}
}


hvr_do_load();


