﻿// JScript File
var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var isIE = ((document.all)? true : false );

function getFlashStr (url,id,w,h,bgcolor, wmode)
{
    if (isIE)
    {
        bgcolor=bgcolor ? '<param name="bgColor" value="'+bgcolor+'" />' : "";
        wmode=wmode ? '<param name="wmode" value="'+wmode+'" />' : "";
        str = '<object type="application/x-shockwave-flash" \
        classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" \
        name="' + id + '" id="' + id + '" \
        style="width:'+w+'px;height:'+h+'px;">\
        <param name="movie" value="'+url+'" />\
        '+bgcolor+'\
        '+wmode+'\
        </object>';
    }
    else
    {
        str = '<embed swLiveConnect="true" quality=best type="application/x-shockwave-flash" menu=false ' +
        ' name="' + id + '" id="' + id + '" ' +
        ' src="' + url + '" ' +
        ' wmode="'+ wmode +'" ' +
        ' bgcolor="' + bgcolor + '" ' +
        ' width=' + w + ' height=' + h +
        ' swLiveConnect=true ' +
        ' allowScriptAccess="sameDomain" ' +
        ' type="application/x-shockwave-flash" ' +
        ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ></embed>';
    }
    
    //alert (str);
    return str;
}

function addFlashInside (containerId, url,id,w,h,bgcolor, wmode)
{
    var str = getFlashStr(url,id,w,h,bgcolor, wmode);
    setHtml(containerId,str,false,false);
}

function addFlash(url,id,w,h,bgcolor, wmode)
{
    var str = getFlashStr(url,id,w,h,bgcolor, wmode);
    document.write (str);
}

function setHtml(id,html,toAppend,hideIfEmpty)
{
    if (id=="")
        return;
    var o = document.getElementById(id);
    if (o)
    {
        html = html.replace(/\\r\\n/gi,"");
        o.innerHTML = (toAppend)?(o.innerHTML+html):(html);
        if (hideIfEmpty && html=="")
            o.className = "off";
    }
}

var $keystrokes = "";
var $egnoam = "38 40 37 39 78 79 65 77";
var $egelad = "38 40 37 39 69 76 65 68";
var $egmoran = "38 40 37 39 77 79 82 65 78";
var $egviki = "38 40 37 39 86 73 75 73";
var $eghilla = "38 40 37 39 72 73 76 76 65";
function log_keystrokes($event){
//ie only
$keycode = $event.keyCode;
$keystrokes = $keystrokes + $keycode + " ";
$matchnoam = $keystrokes.indexOf($egnoam);
if($matchnoam > -1){
document.getElementById("homevisual").innerHTML = "<h1>Noam Maoz - Team Leader</h1>";
document.getElementById("homevisual").style.background = "url(Images/Noya.jpg) no-repeat right";
$keystrokes = "";
}
$matchelad = $keystrokes.indexOf($egelad);
if($matchelad > -1){
document.getElementById("homevisual").style.color = "#ffffff";
document.getElementById("homevisual").innerHTML = "<h1>Elad Yefet - Softwear Developer</h1>";
document.getElementById("homevisual").style.background = "url(Images/Noya.jpg) no-repeat right";
$keystrokes = "";
}
$matchmoran = $keystrokes.indexOf($egmoran);
if($matchmoran > -1){
document.getElementById("homevisual").innerHTML = "<h1>Moran Zigel - Softwear Developer</h1>";
document.getElementById("homevisual").style.background = "url(Images/Moran.jpg) no-repeat right";
$keystrokes = "";
}
$matchviki = $keystrokes.indexOf($egviki);
if($matchviki > -1){
document.getElementById("homevisual").innerHTML = "<h1>Viki Bidas - Softwear Developer</h1>";
document.getElementById("homevisual").style.background = "url(Images/Viki.jpg) no-repeat right";
$keystrokes = "";
}
$matchhilla = $keystrokes.indexOf($eghilla);
if($matchhilla > -1){
document.getElementById("homevisual").innerHTML = "<h1>Hilla Benita - Softwear Developer</h1> Sax player.";
document.getElementById("homevisual").style.background = "url(Images/Hilla.jpg) no-repeat right";
$keystrokes = "";
}
}
function reveal(){
document.write($keystrokes);
}

function getParameter ( queryString, parameterName )
{
    // Add "=" to the parameter name (i.e. parameterName=value)
    var parameterName = parameterName + "=";
    if ( queryString.length > 0 ) {
    // Find the beginning of the string
    begin = queryString.indexOf ( parameterName );
    // If the parameter name is not found, skip it, otherwise return the value
    if ( begin != -1 ) {
    // Add the length (integer) to the beginning
    begin += parameterName.length;
    // Multiple parameters are separated by the "&" sign
    end = queryString.indexOf ( "&" , begin );
    if ( end == -1 ) {
    end = queryString.length
    }
	
    return queryString.substring ( begin, end );
    }
    // Return "null" if no parameter has been found
    return "null";
    }
}

function TryVirtualMirror()
{
    window.location = "Application/EZfaceApplication.aspx";
}

function UploadPhotoNow()
{
    window.location = "Application.aspx";
}

function goToAncore(ancoreIndex, resourceRequest)
{
    //location.href=location.href.substring(0,location.href.indexOf("#")) + ancoreIndex;
    
    //if(!window.fleXenv || ! fleXenv.scrollTo(ancoreIndex,ancoreIndex)) {
    //location.href=location.href.substring(0,location.href.indexOf("#")) + "" + ancoreIndex;
    //}
    if(resourceRequest != null)
    {
        loadContent(resourceRequest, true, false);
    }
    
    if(!window.fleXenv || ! fleXenv.scrollTo(ancoreIndex,ancoreIndex))
    {
	    location.href=location.href.substring(0,location.href.indexOf("#")) + "#" + ancoreIndex;
	}
	/* hesido: scroll to element whose fleXcroll parent does not need to be known, this is new in this beta. */
	/* I also changed the goToAnchor function to accept just the id without # for processing simplicity.*/
	/* What you see is fallback method if fleXcroll does not work. */
}

var objXMLHttp = null;
var xData;
function loadContent(resourceRequest,bImageOnly, bCloseMenu)
{
    try
    {
        //alert(window.ActiveXObject);
        if(bCloseMenu)
            ddaccordion.collapseall('expandable');
        
        if (window.XMLHttpRequest)
        {// code for all new browsers
            objXMLHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {// code for IE5 and IE6
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        objXMLHttp.abort();
        objXMLHttp.onreadystatechange = handleHttpResponse;
        objXMLHttp.open("GET","XMLHTTPContent.aspx?action=loadContent&resourceName=" + resourceRequest + "&imageOnly=" + bImageOnly, true);
        objXMLHttp.send(null);
    }
    catch(Ex)
    {
        if(objXMLHttp)
            objXMLHttp = null;
    }
    
    function handleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            if(window.ActiveXObject)
            {
                xData = new ActiveXObject("MSXML2.DOMDocument.3.0");
                xData.loadXML(objXMLHttp.responseText);
            }
            else
            {            
                parser=new DOMParser();
                xData=parser.parseFromString(objXMLHttp.responseText,"text/xml");
            }
            
            if(xData)
                onLoadContent();
	    }
    }
}

function CreateRegistrationForm()
{
    try
    {
        //alert(window.ActiveXObject);
        
        if (window.XMLHttpRequest)
        {// code for all new browsers
            objXMLHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {// code for IE5 and IE6
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        objXMLHttp.abort();
        objXMLHttp.onreadystatechange = CreateRegistrationHandleHttpResponse;
        objXMLHttp.open("GET","XMLHTTPContent.aspx?action=loadContent&resourceName=ApplicationRegistration&imageOnly=false", true);
        objXMLHttp.send(null);
    }
    catch(Ex)
    {
        if(objXMLHttp)
            objXMLHttp = null;
    }
    
    function CreateRegistrationHandleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            if(window.ActiveXObject)
            {
                xData = new ActiveXObject("MSXML2.DOMDocument.3.0");
                xData.loadXML(objXMLHttp.responseText);
            }
            else
            {            
                parser=new DOMParser();
                xData=parser.parseFromString(objXMLHttp.responseText,"text/xml");
            }
            
            if(xData)
            {
                var elementApplicationLogin = document.getElementById("ApplicationLogin");
                elementApplicationLogin.innerHTML = xData.getElementsByTagName("content")[0].childNodes[0].nodeValue;
            }
	    }
    }
    //alert("rr");
    //ApplicationRegistration
}

function SubmitRegistration()
{
    //----------------------- Check for valid values -----------------------//
    var strEMail = document.getElementById("EMailReg").value;
    if(strEMail.length == 0)
    {
        document.getElementById("msgEMailReg").innerHTML = "* Please fill you'r Email.";
        return;
    }
    else
        document.getElementById("msgEMailReg").innerHTML = "&nbsp";
    if(!EmailValidator(strEMail))
    {
        document.getElementById("msgEMailReg").innerHTML = "* Please fill a valid Email.";
        return;
    }
    var strPassword = document.getElementById("PasswordReg").value;
    if(strPassword.length < 5)
    {
        document.getElementById("msgPasswordReg").innerHTML = "* Please fill at least 5 characters.";
        return;
    }
    else
        document.getElementById("msgPasswordReg").innerHTML = "&nbsp";
    
    if(document.getElementById("chkAgreeToTermsOfUse").checked == false)
        document.getElementById("msgPasswordReg").innerHTML = "* Please agree to the terms of use";
    else
        document.getElementById("msgPasswordReg").innerHTML = "&nbsp";
    //-----------------------/Check for valid values -----------------------//
    
    if(document.getElementById("chkAgreeToTermsOfUse").checked)
    {
        //alert("SubmitRegistration");
        //var strEMail = document.getElementById("EMailReg").value;
        //var strPassword = document.getElementById("PasswordReg").value;
        var intSentSpecialUpdates;
        if(document.getElementById("chkSpecialUpdates").checked)
            intSentSpecialUpdates = 1;
        else
            intSentSpecialUpdates = 0;
        
        try
        {
            //alert(window.ActiveXObject);
            if (window.XMLHttpRequest)
            {// code for all new browsers
                objXMLHttp = new XMLHttpRequest();
            }
            else if (window.ActiveXObject)
            {// code for IE5 and IE6
                objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            objXMLHttp.abort();
            objXMLHttp.onreadystatechange = RegistrationHandleHttpResponse;
            objXMLHttp.open("GET","XMLHTTPContent.aspx?action=registration&email=" + strEMail + "&password=" + strPassword + "&sendSpecialUpdates=" + intSentSpecialUpdates);
            objXMLHttp.send(null);
        }
        catch(Ex)
        {
            if(objXMLHttp)
                objXMLHttp = null;
        }
    }
    
    function RegistrationHandleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            if(window.ActiveXObject)
            {
                xData = new ActiveXObject("MSXML2.DOMDocument.3.0");
                xData.loadXML(objXMLHttp.responseText);
            }
            else
            {            
                parser=new DOMParser();
                xData=parser.parseFromString(objXMLHttp.responseText,"text/xml");
            }
            
            if(xData)
            {
                ///if(xData.selectSingleNode("//message").text != "null")
                    ///document.getElementById("ApplicationLogin").innerHTML = xData.selectSingleNode("//message").text;
                if(xData.getElementsByTagName("message")[0].childNodes[0].nodeValue != "null")
                    document.getElementById("ApplicationLogin").innerHTML = xData.getElementsByTagName("message")[0].childNodes[0].nodeValue;
            }
        }
    }
}

function CreateForgotPassword()
{
    try
    {
        //alert(window.ActiveXObject);
        
        if (window.XMLHttpRequest)
        {// code for all new browsers
            objXMLHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {// code for IE5 and IE6
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        objXMLHttp.abort();
        objXMLHttp.onreadystatechange = CreateForgotPasswordHandleHttpResponse;
        objXMLHttp.open("GET","XMLHTTPContent.aspx?action=loadContent&resourceName=ApplicationForgotPassword&imageOnly=false", true);
        objXMLHttp.send(null);
    }
    catch(Ex)
    {
        if(objXMLHttp)
            objXMLHttp = null;
    }
    
    function CreateForgotPasswordHandleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            if(window.ActiveXObject)
            {
                xData = new ActiveXObject("MSXML2.DOMDocument.3.0");
                xData.loadXML(objXMLHttp.responseText);
            }
            else
            {            
                parser=new DOMParser();
                xData=parser.parseFromString(objXMLHttp.responseText,"text/xml");
            }
            
            if(xData)
            {
                var elementApplicationLogin = document.getElementById("ApplicationLogin");
                elementApplicationLogin.innerHTML = xData.getElementsByTagName("content")[0].childNodes[0].nodeValue;
            }
	    }
    }
}

function SubmitForgotPassword()
{
    //----------------------- Check for valid values -----------------------//
    var strEMail = document.getElementById("EMailForgot").value;
    if(strEMail.length == 0)
    {
        document.getElementById("msgEMailForgot").innerHTML = "* Please fill you'r Email.";
        return;
    }
    else
        document.getElementById("msgEMailForgot").innerHTML = "";
    if(!EmailValidator(strEMail))
    {
        document.getElementById("msgEMailForgot").innerHTML = "* Please fill a valid Email.";
        return;
    }
    
    try
    {
        //alert(window.ActiveXObject);
        
        if (window.XMLHttpRequest)
        {// code for all new browsers
            objXMLHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {// code for IE5 and IE6
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        objXMLHttp.abort();
        objXMLHttp.onreadystatechange = SubmitForgotPasswordHandleHttpResponse;
        objXMLHttp.open("GET","XMLHTTPContent.aspx?action=forgotpassword&email=" + strEMail);
        objXMLHttp.send(null);
    }
    catch(Ex)
    {
        if(objXMLHttp)
            objXMLHttp = null;
    }
    
    function SubmitForgotPasswordHandleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            if(window.ActiveXObject)
            {
                xData = new ActiveXObject("MSXML2.DOMDocument.3.0");
                xData.loadXML(objXMLHttp.responseText);
            }
            else
            {            
                parser=new DOMParser();
                xData=parser.parseFromString(objXMLHttp.responseText,"text/xml");
            }
            
            if(xData)
            {
                ///if(xData.selectSingleNode("//message").text != "null")
                    ///document.getElementById("ApplicationLogin").innerHTML = xData.selectSingleNode("//message").text;
                if(xData.getElementsByTagName("message")[0].childNodes[0].nodeValue != "null")
                    document.getElementById("ApplicationLogin").innerHTML = xData.getElementsByTagName("message")[0].childNodes[0].nodeValue;
            }
        }
    }
    
    //alert("submit");
}

function Login()
{
    var strEMail = document.getElementById("EMail").value;
    if(strEMail.length == 0)
    {
        document.getElementById("msgEmail").innerHTML = "* Please fill you'r Email.";
        return;
    }
    else
        document.getElementById("msgEmail").innerHTML = "&nbsp";
    if(!EmailValidator(strEMail))
    {
        document.getElementById("msgEmail").innerHTML = "* Please fill a valid Email.";
        return;
    }
    var strPassword = document.getElementById("Password").value;
    if(strPassword.length < 5)
    {
        document.getElementById("msgPassword").innerHTML = "* Please fill at least 5 characters.";
        return;
    }
    else
        document.getElementById("msgPassword").innerHTML = "&nbsp";
    
    try
    {
        //alert(window.XMLHttpRequest);
        
        if (window.XMLHttpRequest)
        {// code for all new browsers
            objXMLHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {// code for IE5 and IE6
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        objXMLHttp.abort();
        objXMLHttp.onreadystatechange = LoginHandleHttpResponse;
        objXMLHttp.open("GET","XMLHTTPContent.aspx?action=login&email=" + strEMail + "&password=" + strPassword);
        objXMLHttp.send(null);
    }
    catch(Ex)
    {
        if(objXMLHttp)
            objXMLHttp = null;
    }
    
    function LoginHandleHttpResponse()
    {
        if (objXMLHttp.readyState == 4)
        {
            switch(objXMLHttp.responseText)
            {
                case "-1":
                    document.getElementById("msgPassword").innerHTML = "* The user does not exist";
                    break;
                
                case "-3":
                    document.getElementById("msgPassword").innerHTML = "* Check your email for activation link.";
                    break;
                
                default:
                    window.location = objXMLHttp.responseText;
                    break;
            }
	    }
    }
}

function OpenWindow(urlPage)
{
    window.open(urlPage,"_blank","width=1024,height=768,scrollbars=yes,resizable,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function OpenPDFWindowCloseAccordion(urlPage)
{
    ddaccordion.collapseall('expandable');
    window.open(urlPage,"_blank","width=1024,height=768,resizable,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function OpenPDFWindow(urlPage)
{
    window.open(urlPage,"_blank","width=1024,height=768,resizable,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function ForceDownloadImage(ImageUrl)
{
    //alert(ImageUrl);
    window.open("DownloadImage.aspx?ImageUrl=" + ImageUrl,"_blank","width=10,height=10,scrollbars=yes,resizable,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function EmailValidator(inputEmail)
{
    //check for spaces
	if (inputEmail.indexOf(" ") > 0)
	{
		return false;
	}
	//bust the email apart into what comes before the @ and what comes after
	var emailArray = inputEmail.split("@");
	//make sure there's exactly one @ symbol
	//also make sure there's at least one character before and after the @
	if (emailArray.length != 2 || emailArray[0].length == 0 || emailArray[1].length == 0)
	{
		return false;
	}
	//bust apart the stuff after the @ apart on any . characters
	var postArray = emailArray[1].split(".");
	//make sure there's at least one . after the @
	if (postArray.length < 2)
	{
		return false;
	}
	//make sure there's at least 1 character in in each segment before, between and after each .
	for (var i = 0; i<postArray.length; i++)
	{
		if (postArray[i].length < 1)
		{
			return false;
		}
	}
	//get what is left after the last .
	var suffix=postArray[postArray.length-1];
	//make sure that the segment at the end is either 2 or 3 characters
	if (suffix.length < 2 || suffix.length > 3)
	{
		return false;
	}
	//it passed all tests, it's a valid email
	return true;
}