﻿function OpenGallery(path, catName)
{
	var imgUrl = "http://www.hanesibot.com/Images/" + path;
	var height, width;
	if (window.screen.height == 1024)
	{
        height = "850";
        width = "1150";
    }
    else if (window.screen.height == 768)
    {
        height = "600";
        width = "850";
	}
	else if (window.screen.height == 800)
    {
        height = "570";
        width = "1150";
	}

	//Clicktale tag
	if (typeof ClickTaleTag == "function") {
		ClickTaleTag("Open_Gallery");
	}  
	
	window.open(imgUrl,"","width=" + width + ", height=" + height + ", top=50,left=50,menubar=0,status=0,toolbar=0,resizable=1");
}

function ViewVideoInPopup(videoURL)
{
    window.open("VideoPopup.aspx?vu=" + escape(videoURL),"The_Circumstances_media","width=640, height=505, top=150,left=150,menubar=0,status=0,toolbar=0,resizable=1");
}

function ResizeOnLoad()
{
    if (window.screen.height == 1024)
        MainSiteTable.width = "1020";
    else if (window.screen.height == 768)
        MainSiteTable.width = "100%";
    else if (window.screen.height < 768)
    {
        MainSiteTable.width = "100%";
        alert("This site is better viewed with 1024x768 resolution");
    }
}

function ViewCategory(fileName, catId)
{
    document.location.href = fileName + ".aspx?CatID=" + catId;
}

function OpenTalkBacks(rowID)
{
	if (typeof ClickTaleExec == "function") {
		if(rowID) {
			ClickTaleExec("OpenTalkBacks('" + rowID + "')");
		}
	}

    var obj = document.getElementById(rowID);
    var img = document.getElementById(rowID + "_gif");
    if (obj.style.display == "")
    {
        obj.style.display = 'none';
        img.src = '/Images/Minus.gif';
    }
    else if (obj.style.display == "none")
    {
        obj.style.display = 'block';
        img.src = '/Images/Minus.gif';
    }
    else if (obj.style.display == "block")
    {
        obj.style.display = 'none';
        img.src = '/Images/Plus.gif';
    }
    
    //Clicktale tag
    if (typeof ClickTaleTag == "function") {
    	ClickTaleTag("OpenClose_Talkback");
    }    
}

function AddUser2MailList()
{
    var email = document.getElementById("Groopymail").value;
    var name = document.getElementById("GroopyName").value;
    
    if (!ValidateEmail(email))
    {
        alert('כתובת הדואר שהכנסת אינה תקינה');
        document.getElementById("Groopymail").focus();
        return;
	}
	if (trim(name) == "")
	{
	    alert('נא למלא שם');
        document.getElementById("GroopyName").focus();
        return;
	}
	
	var sURL = "JoinMailingList.aspx?Name=" + escape(name) + "&email=" + email;
	
	var xmlhttp=false;
     try
     {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); /* for IE < 5 */
     }
     catch (e)
     {
        try
        {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
        xmlhttp = false;
        }
     }
     
     /* mozilla & opera */
     if (!xmlhttp && typeof XMLHttpRequest!='undefined')
     {
       xmlhttp = new XMLHttpRequest();
     }
	
	xmlhttp.open("GET",sURL,false);
	xmlhttp.send();
	
	if (String(xmlhttp.responseText).indexOf("Success") > -1)
	{
	    alert('פרטיך נקלטו בהצלחה');
	}
	else
	{
	    alert('כתובת דואר אלקטרוני זאת כבר קיימת במערכת');
	    document.getElementById("Groopymail").focus();
	}
}

function ValidateEmail(email)
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (!filter.test(email)) 
	{
		return false;
	}
	else
	    return true;
}

function trim(str)
{
	try {
		return str.replace(/^\s+|\s+$/g,'');
	} catch (e) {
		return str;
	}
}
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}

function AddResponse(docID)
{
    window.open("AddResponse.aspx?DocID=" + docID,"AddResponse","width=400, height=300, menubar=0,status=0,toolbar=0,resizable=0");
}

function SendResponse()
{
    var title = document.ResponseForm.ResponseTitle.value; 
    if (trim(title) == "" || isnull(title))
    {
        alert("נא למלא כותרת");
        document.ResponseForm.ResponseTitle.focus();
        return;
    }
    
    var content = document.ResponseForm.ResponseContent.value; 
    if (trim(content) == "" || isnull(content))
    {
        alert("נא למלא תוכן התגובה");
        document.ResponseForm.ResponseContent.focus();
        return;
    }
    
    var email = document.ResponseForm.ResponseEmail.value;
    if (!isnull(email) && trim(email) != "")
    {
        if (!ValidateEmail(email))
        {
            alert('כתובת הדואר שהכנסת אינה תקינה');
            document.ResponseForm.ResponseEmail.focus();
            return;
	    }
	}

	if (typeof ClickTaleTag == "function") {
		ClickTaleTag("Submit_Response");
	}
    document.ResponseForm.submit();
}

function ClickTaleIsIn (testFor) {
	var topLocation = top.location;
 
	if(testFor == "recording" && window.location == topLocation) {
		return true;
	} else if(testFor == "recording" || window.location == topLocation) {
		return false;
	}
 
	switch(testFor.toLowerCase()) {
	case "report":
		var fn = arguments.callee;
		return fn("scroll-heatmap") || fn("click-heatmap") || fn("form-analytics");
	case "scroll-heatmap":
		var regex = new RegExp("Heatmap.aspx\?", "i");
		return regex.test(topLocation);
	case "click-heatmap":
		var regex = new RegExp("ClickHeatMap.aspx\?", "i");
		return regex.test(topLocation);
	case "form-analytics":
		var regex = new RegExp("FormAnalytics.aspx\?", "i");
		return regex.test(topLocation);
	case "playback":
		var regex = new RegExp("Player.aspx\?", "i");
		return regex.test(topLocation);
	}
}
