﻿function getCookie(search_name,noescape) 
{
	var tab_cookies = document.cookie.split(';');
	for (var i = 0; i<tab_cookies.length;i++)
	{
		var cookie_tmp = tab_cookies[i].split('=');
		var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
		if (cookie_name==search_name)
		{
			if (cookie_tmp.length>1)
			{
				if(typeof noescape == 'undefined')
				{
					return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
				}
				else
				{
					return ( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
				}
			}
			return '';
		}
	}
	return '';
}

function pageHeightFoto() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function pageWidthFoto() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function windowResizeAndMoveIndexFoto(e)
{
	if (document.getElementById('transparentBackgroundPopup') && document.getElementById('transparentBackgroundPopup').style.display == "block")
	{
		dialogmask = document.getElementById('transparentBackgroundPopup');
		dialogmask.style.height = pageHeightFoto() + 'px';
		dialogmask.style.top = document.documentElement.scrollTop + 'px';
	}
}
function closeNotiFoto()
{
	document.getElementById('transparentBackgroundPopup').style.display = "none";
	document.getElementById(popupDivName).style.display = "none";
}

function karartKontrolFoto()
{
	
	if(!document.getElementById('transparentBackgroundPopup')) {
		ccontent = document.createElement('div');
		ccontent.id = 'transparentBackgroundPopup';
		ccontent.className = 'ratecampcss';
		document.body.appendChild(ccontent);
	}
	
	
	document.getElementById('transparentBackgroundPopup').style.display = "none";
	document.getElementById(popupDivName).style.display = "none";

	document.getElementById("transparentBackgroundPopup").style.display = 'block';
	dialogmask = document.getElementById('transparentBackgroundPopup');
	dialogmask.className = 'ratecampcssb';
	dialogmask.style.height = pageHeightFoto() + 'px';
	dialogmask.style.top = document.documentElement.scrollTop + 'px';
	
	document.getElementById(popupDivName).style.display = 'block';
	dialogmaskt = document.getElementById(popupDivName);
}

function notiredirectFoto(type)
{
	var exdate=new Date();
	//exdate.setDate(exdate.getDate()+popupExpireDays);
	exdate.setHours(exdate.getHours()+1);
	document.cookie=popupCookieName+"=1" +((popupExpireDays==null) ? "" : ";expires="+exdate.toGMTString()) + ";domain=.hayrat.com;path=/";

	closeNotiFoto();
	if (type == 1)
	{
		
	}else if (type == 2)
	{
		window.setTimeout(function(){
			window.location.href = popupRedirectUrl;
		},100);	
	}
}

function readCookieFoto(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


window.onresize = windowResizeAndMoveIndexFoto;
window.onscroll = windowResizeAndMoveIndexFoto;


if (readCookieFoto(popupCookieName) == null)
{
		window.setTimeout(function(){
			try{
				karartKontrolFoto();
			} catch(e){}
		},500);
}
