﻿
function mouseoverMenu(obj, objNumber) {
    var topBar = document.getElementById("topBar");
    if (obj.className == 'topMenuSelected_' + objNumber) {
        obj.className = 'Section_' + objNumber;
        topBar.className = "topBar";
    }
    else {
        obj.className = 'topMenuSelected_' + objNumber;
        topBar.className = "Logo_Section_" + objNumber;
        //alert("Logo_Section_" + objNumber);  
    }
}

function OpenPrintPage(link) {
    window.open(link, 'PrintPage', 'menubar=0,resizable=1,width=770,height=600,scrollbars=1');
}

var font = 1;
function changeFontSize() {
    var topMenuHolder = document.getElementById("topMenuHolder");
    if (document.body.style.fontSize == "" || document.body.style.fontSize == "80%") {
        document.body.style.fontSize = "100%";
        document.getElementById('changeFont').innerHTML = "הקטן טקסט";
        topMenuHolder.style.width = '530px';
    }
    else {
        document.body.style.fontSize = "80%";
        document.getElementById('changeFont').innerHTML = "הגדל טקסט";
        topMenuHolder.style.width = '460px';
    }
}

function changeAnchors() {
    var docAnchors = document.getElementsByTagName("a")
    var thePath = new String("");
    for (var i = 0; i < docAnchors.length; i++) {
        thePath = docAnchors[i].href
        if (Number(thePath.search("testsite.akt.co.il")) == -1 && thePath.search("javascript") == -1 && thePath.search("mailto") == -1) {
            docAnchors[i].onclick = function() { return goOutofSite(thePath); }
        }


    }
}
function goOutofSite(theURL) {
    var answer = confirm("בלחיצה על כפתור אישור, הינך מאשר כי בכוונתך לעזוב את האתר.")
    if (answer)
        return true;
    else
        return false
}

function chkBox(id) {
    if (document.getElementById('nl_'+id).value != "") {
        document.getElementById('img_' + id).style.display = 'block';
        document.getElementById('img_' + id + '_on').style.display = 'none';
        document.getElementById('nl_'+id).value = "";
    }
    else {
        document.getElementById('img_' + id).style.display = 'none';
        document.getElementById('img_' + id + '_on').style.display = 'block';
        document.getElementById('nl_'+id).value = id;
    }
}

function checkNlValue(obj, act) {
    if (act == 'focus' && obj.value == 'הכנס דוא\'\'ל ולחץ \'\'שלח\'\'') {
        obj.value = '';
    }
    if (act == 'blur' && obj.value == '') {
        obj.value = 'הכנס דוא\'\'ל ולחץ \'\'שלח\'\'';
    }
}

function sendNL(sitePath) {
    if (document.getElementById("nl_email_input").value == '') 
    {
        alert('יש להזין כתובת אימייל');
        return;
    }
    if (document.getElementById("nl_approve_input").checked == false) 
    {
        alert('יש לאשר קבלת דיוור מהתיאטרון');
        return;
    }
    var name = document.getElementById("nl_name_input").value;
    var member;
    if (document.getElementById("nl_member_input").checked)
        member = 1;
    else
        member = 0;
    var approve = document.getElementById("nl_approve_input").value;
    var email = document.getElementById("nl_email_input").value;
    if (isValidEmail(email)) {
        xmlHttp = GetXmlHttpObject();
        if (xmlHttp == null) {
            alert("Browser does not support HTTP Request");
            return;
        }
        var url = sitePath + "/webSite/Controls/AjaxFunctions.aspx";
        url = url + "?f=sendNewsletter" + "&email=" + email + "&member=" + member + "&approve=" + approve + "&name=" + escape(name);
        xmlHttp.onreadystatechange = stateChanged;
        xmlHttp.open("GET", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1255");
        xmlHttp.send(null);
    } else {
        alert('יש להזין כתובת אימייל תקינה');
    }
}

function siteSearch(sitePath){
    if(document.getElementById("searchText").value != 'חיפוש')
        window.location.href = sitePath + '/website/Modules/Search.aspx?searchText=' + escape(document.getElementById("searchText").value);
	else
        alert('יש להזין ערך לחיפוש');
}

function checkValue(obj, act, lang) {
    if ((act == 'focus' && obj.value == 'חיפוש') || (act == 'focus' && obj.value == 'Search'))
        obj.value = '';
    if (act == 'blur' && obj.value == '')
        if (lang=='1')
            obj.value = 'חיפוש';
        else
            obj.value = 'Search';
}

function changeOver(obj, act) {
    var re = new RegExp('\\bT6imgResize\\b'); 
    var els = obj.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
        if (re.test(els[i].className)) 
        {
            if (act == 'over') {
                els[i].style.backgroundColor = '#CACACA';
            } else {
                els[i].style.backgroundColor = '#ECECEC';
            }
        }
}

function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }

    return true
}

function isValidEmail(email) {
    if ((email == null) || (email == "")) {
        return false
    }
    if (echeck(email) == false) {
        return false
    }
    return true
}

function printNow(){
    window.print();
}

function stateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        alert(xmlHttp.responseText)
    }
}

function GetXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else
        if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
} 

function noError(){return true;}
//This script will stop all the errors alerts of javascript
//window.onerror = noError;

function openPrint(pageToView){
    //alert(pageToView);
    
    OpenWin = this.open(pageToView, "printWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=600,height=600,left=50,top=50");
    OpenWin.document.print();
}

function stripHTML(strToStrip){
    
    var re= /<\S[^><]*>/g;
    var thestrToStrip = new String(strToStrip);
    thestrToStrip=thestrToStrip.replace(re, "");
    return thestrToStrip;
    
}
    
function NewWindow(page,width,height,top,left)
{
	OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+left+",top="+top+"");
}

function NavTo(url){window.location = url }

function ChangeIframeHeight(theFrameName)
{
	if (parent == window) return;
	else parent.setIframeHeight(theFrameName);
}

function getDocHeight(doc) 
{
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
	if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
	if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
	if (sh && oh) docHt = Math.max(sh, oh);
  }
  if(docHt<=250)
  	docHt=500;
  return docHt;
}

function setIframeHeight(iframeName) {

  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
	iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
	var docHt = getDocHeight(iframeWin.document);
	//alert(docHt)
	// need to add to height to be sure it will all show
	if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}


function addToFavorites()
{
    var chr = 'CTRL-D';
    var agt=navigator.userAgent.toLowerCase();
    if(agt.substr(agt.indexOf('opera')+6,1) < 9) 
        chr = 'CTRL-T';
    if(window.external) 
        document.write('<a href="javascript:window.external.AddFavorite(self.location,document.title)">Add to Favorites<\/a>');
    else 
        document.write('Press '+chr+' to bookmark this page.');
}

function createCookie(name,value,days) {
        if (days) {
	        var date = new Date();
	        date.setTime(date.getTime()+(days*24*60*60*1000));
	        var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

function readCookie(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;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
