﻿function popTicketsDisabled(event) {
    pageTracker._trackPageview('shabat-blocker');
    if (document.getElementById('windowLayer'))
        return;
    var width = BrowserWidth();
    
    var yLocation = GetMouseLocation(event)[1];
    var size = { 'height': 100, 'width': 450 };
    var windowLayer = document.createElement('div');
    windowLayer.name = 'windowLayer';
    windowLayer.id = 'windowLayer';
    windowLayer.onclick = CloseFullScreen;
    windowLayer.style.overflow = 'auto';
    windowLayer.style.direction = 'rtl';
    windowLayer.style.padding = '10px';
    windowLayer.style.height = size.height + 'px';
    windowLayer.style.width = size.width + 'px';
    windowLayer.style.position = 'absolute';
    windowLayer.style.zIndex = 3;
    windowLayer.style.backgroundColor = 'white';
    windowLayer.style.border = '4px solid #315A32';
    windowLayer.innerHTML = '<a href="#" title="Close" style="position:absolute; top:0; left:0;font: 12px Arial;"> \
                   <img src="App_Themes/Default/images/closebox.png" alt="Close" style="border:none; margin:0; padding:0;" /> \
                  </a><br /> לא ניתן לרכוש כרטיסים כעת. נשמח אם תשובו אלינו בצאת החג/שבת.';
    windowLayer.style.top = (parseInt(yLocation)) + 'px';
    windowLayer.style.left = (width / 2) - (size.width / 2) + 'px';
    document.body.appendChild(windowLayer);
}
//
//  Close the full message  view
//
function CloseFullScreen() {
    document.body.removeChild(document.getElementById('windowLayer'));
}
//
//  Get mouse location
//
function GetMouseLocation(e) {
    x = e.clientX;
    y = e.clientY + getScrollOffset().top;
    return [x, y]
}
//
//  Get the scroll offset top & left
//
function getScrollOffset() {
    var x, y;
    if (self.pageYOffset) {
        x = self.pageXOffset;
        y = self.pageYOffset;
    }
    else {
        if (document.documentElement && document.documentElement.scrollTop) {
            x = document.documentElement.scrollLeft;
            y = document.documentElement.scrollTop;
        }
        else {
            if (document.body) {
                x = document.body.scrollLeft;
                y = document.body.scrollTop;
            }
        }
    }
    return { left: parseInt(x), top: parseInt(y) };
}
// Get browser window width
function BrowserWidth() {
    if (window.innerWidth)
        return window.innerWidth;
    return document.body.clientWidth;
}

function ad_click(id,url,target,spaceid,ext) {
	if (url!='' && url!='none') {
		if (url.indexOf('mailto:')!=-1) {	// email link?
			document.location.href = url;
		} else {	// normal link
			if (target=='_blank') {
				window.open('adjump.asp?id=' + id + '&url=' + url + '&spaceid=' + spaceid,'adjump');
			} else {
				document.location.href = 'adjump.asp?id=' + id + '&url=' + url + '&spaceid=' + spaceid;
			}
		}
	}
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

//***************** survey functions ******************
function _vote(fid) {
	var frm = document.forms("survey" + fid);
	var voteid = null;
	for (var i=0;i<frm.item("vote").length;i++) {
		if (frm.item("vote").item(i).checked) {
			voteid = frm.item("vote").item(i).value;
		}
	}
	if (voteid==null) {
		alert("please choose a voting option");
		return(false)
	} else {
		if (getCookie('v' + fid)==1) {
			alert('Voting is only allowed once');
			return(false)
		}
		setCookie('v' + fid,1,now);
		var mywin = window.open('dynamic/survey/survey_results.asp?sid=' + fid + '&vid=' + voteid,'vote','width=490,height=300,status=no,toolbar=no,menubar=no,location=no');
		mywin.focus();
	}
}

function _vote_results(fid) {
	var mywin = window.open('dynamic/survey/survey_results.asp?sid=' + fid,'vote','width=490,height=300,status=no,toolbar=no,menubar=no,location=no');
}

//***************** cookie functions ******************
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function _preview(img,alt) {
    var x = window.open ('preview_image.aspx?img='+img+'&alt=' + alt,'imgPreview','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no');
}

// open talkback pannel
function openTB(oLink,tbId) {
	var tbDiv = document.getElementById('divTB' + tbId);
	if (tbDiv) {
		if (tbDiv.style.display=='none') {
			tbDiv.style.display = '';
		} else {
			tbDiv.style.display = 'none';
		}
	}
}

// post talkback
function postTB(id) {
	if (document.getElementById("articleid")) {
	    var aId = document.getElementById("articleid").value;
	} else {
	    aId = 0;
	}
	window.open ('talkback_post.asp?id='+aId,'postTB','width=350,height=260,toolbar=no, location=no, directories=no, status=yes, scrollbars=no');
}

function checkTB(frm) {
	if (frm.username.value=='' || frm.title.value=='') {
			alert("please enter name and title");
			return(false);
	}
	if (frm.user_email_display.checked) {
		if (frm.email.value=='') {
			alert("please enter a valid email address");
			return(false);
		}
	}
	return (true);
}

// Disable right click script on images - by Darren Mackintosh
function disableclick(e) {
	if (document.all) {
		if (event.button==2||event.button==3) {
			if (event.srcElement.tagName=="IMG"){
				alert(clickmessage);
			return false;
			}
		}
	}
	else if (document.layers) {
		if (e.which == 3) {
			alert(clickmessage);
		return false;
		}
	}
	else if (document.getElementById){
		if (e.which==3&&e.target.tagName=="IMG"){
			alert(clickmessage)
		return false
		}
	}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
	document.images[i].onmousedown=disableclick;
}

function popup_open(url,title,width,height)
{
    if (typeof (title) == 'undefined') title = 'popup';
    else title = title.replace(/ /g, "_"); // IE can't open pop up that have space in the title. (stupied IE)
	var myWin = window.open(url,title,'scrollbars=yes,width=' + width + ',height='+ height + ',status=no,toolbar=no,menubar=no,location=no',false);
    return false;
}

// ----------------------------------------------------------------------
// language selection
// this function will add setLanguage=x to the url, removing any previous
// params of this kind.
// ----------------------------------------------------------------------
function user_setLanguage(lang) {
	setCookie('user_language',lang,now);
    var sHref = document.location.href;
    if (sHref.indexOf("?") > -1 ){
        var sQueryString = sHref.substr(sHref.indexOf("?")).toLowerCase();
        sHref = sHref.substring(0,sHref.indexOf("?"));
        sQueryString = sQueryString.replace(/[?|&]setlanguage=[0-9a-zA-Z][0-9a-zA-Z]/g,"")

        if (sQueryString.indexOf('?')>-1)
            var sNewRef = sHref + sQueryString + "&setlanguage=" + lang;
        else
            var sNewRef = sHref + "?setlanguage=" + lang;
        
    } else {
        var sNewRef = "?setlanguage=" + lang;
    }
    document.location.href = sNewRef;
    return;
}

// get the body content before posting
function copyEditorText(target) {
    var editorText = '';
	if (document.frames["editor"].document.getElementById("Content")) {
        var editorText = document.frames["editor"].document.getElementById("Content").innerText;
		document.getElementById(target).value = editorText;		            
	}
    return;
}
