﻿var filename;
function ValidateTextBox(ValidateDiv) {
    var MainDiv = document.getElementById('box')
    var TextBoxs = MainDiv.getElementsByTagName("INPUT")
    for (var i = 0; i < TextBoxs.length; i++) {
        if (TextBoxs[i].value == "") {
            ShowValidateDiv(true, "חובה למלא את כל השדות", ValidateDiv)
            return false
        } 
    }
    return true
}
function Login(TextBoxUserName, TextBoxPassword) {
    var UserName = document.getElementById(TextBoxUserName)
    var Password = document.getElementById(TextBoxPassword)
    var params = String.prototype.format('{ UserName:"{0}", Password:"{1}" }', UserName.value, Password.value)
    CallServer("Login", params)
    
    setTimeout(CloseLightBox, 2000);
}
function LoginMain(TextBoxUserName, TextBoxPassword) {
    var UserName = document.getElementById(TextBoxUserName)
    var Password = document.getElementById(TextBoxPassword)
    var params = String.prototype.format('{ UserName:"{0}", Password:"{1}" }', UserName.value, Password.value)
    CallServer("LoginMain", params)
}
function ContactUs(TextBoxFirstNameName, TextBoxLastNameName, TextEmailName, TextMobileName, TextSubjectName, TextBodyName, ValidateDivName) {
    
    var ValidateDiv = document.getElementById(ValidateDivName)
    
    var TextBoxEmail = document.getElementById(TextEmailName).value
    var TextBoxFirstName = document.getElementById(TextBoxFirstNameName).value
    var TextBoxLastName = document.getElementById(TextBoxLastNameName).value
    var TextBoxMobile = document.getElementById(TextMobileName).value
    var TextBoxSubject = document.getElementById(TextSubjectName).value
    var TextBoxBody = document.getElementById(TextBodyName).value
    
    
     TextBoxEmail = TextBoxEmail.replace(/"/gi,"&quot;");
     TextBoxFirstName = TextBoxFirstName.replace(/"/gi,"&quot;");
     TextBoxLastName = TextBoxLastName.replace(/"/gi,"&quot;");
     TextBoxMobile = TextBoxMobile.replace(/"/gi,"&quot;");
     TextBoxSubject = TextBoxSubject.replace(/"/gi,"&quot;");
     TextBoxBody = TextBoxBody.replace(/"/gi,"&quot;");
    
     
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    var params = String.prototype.format('{ FirstName:"{0}", LastName:"{1}", Email:"{2}", Mobile:"{3}", Subject:"{4}", Body:"{5}" }', TextBoxFirstName, TextBoxLastName, TextBoxEmail, TextBoxMobile, TextBoxSubject, TextBoxBody)
    CallServer("ContactUs", params)
    setTimeout(CloseLightBox, 2000)
}
function redMail(TextBoxFirstNameName, TextBoxLastNameName, TextEmailName, TextMobileName, TextSubjectName, TextBodyName, ValidateDivName, file)
{
    var ValidateDiv = document.getElementById(ValidateDivName)
    var TextBoxEmail = document.getElementById(TextEmailName).value
    var TextBoxFirstName = document.getElementById(TextBoxFirstNameName).value
    var TextBoxLastName = document.getElementById(TextBoxLastNameName).value
    var TextBoxMobile = document.getElementById(TextMobileName).value
    var TextBoxSubject = document.getElementById(TextSubjectName).value
    var TextBoxBody = document.getElementById(TextBodyName).value
    
     TextBoxEmail = TextBoxEmail.replace(/"/gi,"&quot;");
     TextBoxFirstName = TextBoxFirstName.replace(/"/gi,"&quot;");
     TextBoxLastName = TextBoxLastName.replace(/"/gi,"&quot;");
     TextBoxMobile = TextBoxMobile.replace(/"/gi,"&quot;");
     TextBoxSubject = TextBoxSubject.replace(/"/gi,"&quot;");
     TextBoxBody = TextBoxBody.replace(/"/gi,"&quot;");
    
    
    
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    if(typeof(file) == 'undefined')
    {
       file="";
    }
    var params = String.prototype.format('{ FirstName:"{0}", LastName:"{1}", Email:"{2}", Mobile:"{3}", Subject:"{4}", Body:"{5}", FileName:"{6}"}', TextBoxFirstName, TextBoxLastName, TextBoxEmail, TextBoxMobile, TextBoxSubject, TextBoxBody,file)
    CallServer("RedMail", params)
    setTimeout(CloseLightBox, 2000)
}
function AdvUs(TextBoxFirstNameName, TextBoxLastNameName, TextEmailName, TextMobileName, TextSubjectName, TextBodyName) {
    
    var ValidateDiv = document.getElementById('IncorrectPassword')
    
    var TextBoxEmail = document.getElementById(TextEmailName).value
    var TextBoxFirstName = document.getElementById(TextBoxFirstNameName).value
    var TextBoxLastName = document.getElementById(TextBoxLastNameName).value
    var TextBoxMobile = document.getElementById(TextMobileName).value
    var TextBoxSubject = document.getElementById(TextSubjectName).value
    var TextBoxBody = document.getElementById(TextBodyName).value
    
     TextBoxEmail = TextBoxEmail.replace(/"/gi,"&quot;");
     TextBoxFirstName = TextBoxFirstName.replace(/"/gi,"&quot;");
     TextBoxLastName = TextBoxLastName.replace(/"/gi,"&quot;");
     TextBoxMobile = TextBoxMobile.replace(/"/gi,"&quot;");
     TextBoxSubject = TextBoxSubject.replace(/"/gi,"&quot;");
     TextBoxBody = TextBoxBody.replace(/"/gi,"&quot;");
    
    var params = String.prototype.format('{ FirstName:"{0}", LastName:"{1}", Email:"{2}", Mobile:"{3}", Subject:"{4}", Body:"{5}" }', TextBoxFirstName, TextBoxLastName, TextBoxEmail, TextBoxMobile, TextBoxSubject, TextBoxBody)
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    CallServer("AdvUs", params)
    setTimeout(CloseLightBox, 2000)
}
function MobileVerification(TextBoxMobileNumberName, ValidateDivName) {
    var ValidateDiv = document.getElementById(ValidateDivName)
    var TextBoxMobileNumber = document.getElementById(TextBoxMobileNumberName).value
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    TextBoxMobileNumber = TextBoxMobileNumber.replace(/"/gi,"&quot;");
    var params = String.prototype.format('{MobileNumber:"{0}"}', TextBoxMobileNumber)
    CallServer("MobileVerification", params)
    setTimeout(CloseLightBox, 2000)
}
function RecoverPassword(TextBoxEmailName, ValidateDivName) {
    var ValidateDiv = document.getElementById(ValidateDivName)
    var TextBoxEmail = document.getElementById(TextBoxEmailName).value
    
    TextBoxEmail = TextBoxEmail.replace(/"/gi,"&quot;");
    
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    var params = String.prototype.format('{Email:"{0}"}', TextBoxEmail)
    CallServer("RecoverPassword", params)
    setTimeout(CloseLightBox, 2000)
}
function PasswordChange(oldPassword, newPassword, newPassword1) {
    if ($(newPassword).val() != $(newPassword1).val()) {
        ShowValidateDiv(true, "אימות סיסמא ניכשל", document.getElementById('IncorrectPassword'))
        return
    }
    if (ValidateTextBox(document.getElementById('IncorrectPassword')) == false) {
        return
    }
    var params = String.prototype.format('{OldPass:"{0}",NewPass:"{1}"}', $(oldPassword).val(), $(newPassword).val())
    CallServer("ChangePassword", params)
    setTimeout(CloseLightBox, 2000)
}
function CharityAd(CharityType, CharityName, CharityDescription, City, Address, Phone1, Phone2, ContactName) {
    if ($(CharityName).val() == '' || $(CharityDescription).val() == '' || $(Phone1).val() == '' || $(ContactName).val() == '') {
        ShowValidateDiv(true, "חובה למלא את כל השדות *", document.getElementById('IncorrectPassword'))
        return
    }
    var params = String.prototype.format('{CharityType:"{0}",CharityName:"{1}",CharityDescription:"{2}",City:"{3}",Address:"{4}",Phone1:"{5}" ,Phone2:"{6}",ContactName:"{7}"}', $(CharityType).val(), $(CharityName).val(), $(CharityDescription).val(), $(City).val(), $(Address).val(), $(Phone1).val(), $(Phone2).val(), $(ContactName).val())
    CallServer("CharityAd", params)
    setTimeout(CloseLightBox, 2000)
}
function ShowValidateDiv(Show, ValidateText, ValidateDiv) {
    if (Show == true) {
        ValidateDiv.style.display = 'block'
        ValidateDiv.innerHTML = ValidateText
    }
    else {
        ValidateDiv.style.display = 'none'
    } 
}
function ChangePassword(ButtonChangePasswordName, TextCurrentPassowrdName, TextNewPasswordName, TextReTypeNewPasswordName) {
    var TextCurrentPassowrd = document.getElementById(TextCurrentPassowrdName)
    var TextReTypeNewPassword = document.getElementById(TextReTypeNewPasswordName)
    var TextNewPassword = document.getElementById(TextNewPasswordName)
    var ButtonChangePassword = document.getElementById(ButtonChangePasswordName)
    if (ButtonChangePassword.getAttribute("IsDisabled") == "true") {
        return
    }
    var params = String.prototype.format('{ CurrentPassowrd:"{0}", NewPassowrd:"{1}", ReTypeNewPassword:"{2}", Mobile:"{3}", Subject:"{4}", Body:"{4}" }', TextCurrentPassowrd.value, TextNewPassword.value, TextReTypeNewPassword.value)
    CallServer("ChangePassword", params)
    setTimeout(CloseLightBox, 2000)
}
function TexbBoxsValidation(MainTextBoxName, SubTextBoxName, ButtonRegisterName, ValidateDivName, LetterCount) {
    var MainTextBox = document.getElementById(MainTextBoxName)
    var SubTextBox = document.getElementById(SubTextBoxName)
    var ButtonRegister = document.getElementById(ButtonRegisterName)
    var ValidateDiv = document.getElementById(ValidateDivName)
    if (MainTextBox.value.length < LetterCount) {
        ButtonRegister.setAttribute("IsDisabled", "true")
        ShowValidateDiv(true, ' לפחות ' + LetterCount + ' תווים ', ValidateDiv)
        return
    }
    if (MainTextBox.value != SubTextBox.value) {
        ButtonRegister.setAttribute("IsDisabled", "true")
        ShowValidateDiv(true, 'הסיסמה אינה זהה', ValidateDiv)
    }
    else {
        ButtonRegister.setAttribute("IsDisabled", "false")
        ShowValidateDiv(false, '', ValidateDiv)
    } 
}
function Register(EmailName, NickNameName, PasswordName, ReTypePasswordName, ValidateDivName) {
    var Email = document.getElementById(EmailName)
    var NickName = document.getElementById(NickNameName)
    var Password = document.getElementById(PasswordName)
    var ReTypePassword = document.getElementById(ReTypePasswordName)
    var ValidateDiv = document.getElementById(ValidateDivName)
    var Register = document.getElementById('ButtonRegister')
    if (Register.getAttribute("IsDisabled") == "true") {
        return
    }
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    var params = String.prototype.format('{ Email:"{0}", NickName:"{1}", Password:"{2}", ReTypePassword:"{3}", Body:"{4}"}', Email.value, NickName.value, Password.value, ReTypePassword.value)
    CallServer("Register", params)
    setTimeout(CloseLightBox, 2000)
}
function CloseLightBox() {
    document.body.removeChild(document.getElementById('layer'))
    document.body.removeChild(document.getElementById('box'))
    ChangeCorserDefault()
}
function SendToFriend(TextToName, TextEmailTo, TextSenderName, TextSenderEmail, TextMessageBody, ValidateDivName) {
    var Link = location.href
    var ValidateDiv = document.getElementById(ValidateDivName)
    
    var ToName = document.getElementById(TextToName).value
    var EmailTo = document.getElementById(TextEmailTo).value
    var SenderName = document.getElementById(TextSenderName).value
    var SenderEmail = document.getElementById(TextSenderEmail).value
    var Body = document.getElementById(TextMessageBody).value
    
    
    
    
   
     ToName = ToName.replace(/"/gi,"&quot;");
     EmailTo = EmailTo.replace(/"/gi,"&quot;");
     SenderName = SenderName.replace(/"/gi,"&quot;");
     SenderEmail = SenderEmail.replace(/"/gi,"&quot;");
     Body = Body.replace(/"/gi,"&quot;");
    
    
    if (ValidateTextBox(ValidateDiv) == false) {
        return
    }
    //if ($('#hf') != null) { Link = "http://www.bhol.co.il/videopage.aspx?ClipId=" + $('#hf').val(); }
  
    var params = String.prototype.format('{ To:"{0}", EmailTo:"{1}", SenderName:"{2}", SenderEmail:"{3}", Body:"{4}",Link:"{5}",Location:"{6}"}', ToName, EmailTo, SenderName, SenderEmail, Body, Link,window.location)
      
    CallServer("SendToFriend", params)
    setTimeout(CloseLightBox, 2000)
}
$.getDocHeight = function(){
    return Math.max(
        $(document).height(),
        $(window).height(),
        /* For opera: */
        document.documentElement.clientHeight
    );
};
function showBox(ControlName) {
    
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft
    var layer = document.createElement('div')
    layer.style.zIndex = 2
    layer.id = 'layer'
    layer.style.position = 'absolute'
    layer.style.top = '0px'
    layer.style.left = '0px'
    layer.style.height = document.documentElement.clientHeight+ 'px';//$.getDocHeight() + 'px'
    layer.style.width = width + 'px'
    layer.style.backgroundColor = 'black'
    layer.style.opacity = '.6'
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)")
    layer.style.zIndex = "998"
    document.body.appendChild(layer)
    var div = document.createElement('div')
    div.style.zIndex = 3
    div.id = 'box'
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absoltue' : 'fixed'
    div.style.top = '200px'
    div.style.left = (width / 2) - (400 / 2) + 'px'
    div.style.backgroundColor = 'white'
    div.style.zIndex = "999"
    document.body.appendChild(div)
    var params = '{LightBoxName:"' + ControlName + '"}'
 
    
    CallServer("CreateLightBox", params)
   
      
}
function showBox1(Clip) {
    
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft
    var layer = document.createElement('div')
    layer.style.zIndex = 2
    layer.id = 'layer'
    layer.style.position = 'absolute'
    layer.style.top = '0px'
    layer.style.left = '0px'
    layer.style.height = $(document).height()+ 'px';//document.documentElement.clientHeight+ 'px';//$.getDocHeight() + 'px'
    layer.style.width = width + 'px'
    layer.style.backgroundColor = 'black'
    layer.style.opacity = '.6'
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)")
    layer.style.zIndex = "1998"
    document.body.appendChild(layer)
    var div = document.createElement('div')
    div.style.zIndex = 3
    div.id = 'box'
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absoltue' : 'fixed'
    div.style.top = '20px'
    div.style.left = (width / 2) - (700 / 2) + 'px'
    div.style.backgroundColor = 'white'
    div.style.zIndex = "1999"
    document.body.appendChild(div)
    var params = '{Clip:"'+Clip+'"}'
 
    
    CallServer("CreateLightBoxVideo", params)
   
      
}
function showBox1(Clip,cult) {
    
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft
    var layer = document.createElement('div')
    layer.style.zIndex = 2
    layer.id = 'layer'
    layer.style.position = 'absolute'
    layer.style.top = '0px'
    layer.style.left = '0px'
    layer.style.height = $(document).height()+ 'px';//document.documentElement.clientHeight+ 'px';//$.getDocHeight() + 'px'
    layer.style.width = width + 'px'
    layer.style.backgroundColor = 'black'
    layer.style.opacity = '.6'
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)")
    layer.style.zIndex = "1998"
    document.body.appendChild(layer)
    var div = document.createElement('div')
    div.style.zIndex = 3
    div.id = 'box'
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absoltue' : 'fixed'
    div.style.top = '20px'
    div.style.left = (width / 2) - (700 / 2) + 'px'
    div.style.backgroundColor = 'white'
    div.style.zIndex = "1999"
    document.body.appendChild(div)
    var params = '{Clip:"' + Clip + '",cult:"'+cult+'"}'
 
    
    CallServer("CreateLightBoxVideo", params)
   
      
}
function CallServer(FunctionName, params) {
    $.ajax({
        type: "POST",
        url: "LightBoxManager.aspx/" + FunctionName,
        data: params,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Content-type", "application/json; charset=utf-8")
        },
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg, status) {
            if (msg.d.indexOf("UserLogin;") == -1) {
                var Text = msg.d.split("{IncorrectText}")
                if (Text.length > 1) {
                    var ValidateDiv = document.getElementById("IncorrectPassword")
                    ShowValidateDiv(true, Text[1], ValidateDiv)
                }
                else {
                    var txt = msg.d.split(":Login:")
                    if (txt.length > 1) {
                        var logdata = txt[1].split(";")
                        if (logdata.length > 1) {
                            subcookiejar.bake('HydeUser_Ver01', {
                                Member_ID: logdata[0],
                                Name: logdata[1],
                                Pword: logdata[2]
                            }, 365)
                            hide_login()
                        }
                        else { }
                        var div = document.getElementById('box')
                        div.innerHTML = txt[0]
                    }
                    else {
                        var div = document.getElementById('box')
                        div.innerHTML = msg.d
                    } 
                } 
            }
            else {
                var logindata = msg.d.split(";")
                subcookiejar.bake('HydeUser_Ver01', {
                    Member_ID: logindata[1],
                    Name: logindata[2],
                    Pword: logindata[3]
                }, 365)
                hide_login()
            }
           if (params =='{LightBoxName:"RedMail"}')
                LoadUploader();
        },
        error: function(xhr, msg, e) {
            //alert(msg)
        }
    })
}
function ChangeCorserPointer() {
    this.document.body.style.cursor = "pointer"
}
function ChangeCorserDefault() {
    this.document.body.style.cursor = "default"
}
String.prototype.format = function() {
    if (arguments.length < 1) {
        return undefined
    }
    else {
        var t = arguments[0]
        for (var i = 1; i < arguments.length; i++) {
            var reg = new RegExp("\\{" + (i - 1) + "\\}", "gi")
            t = t.replace(reg, arguments[i])
        }
        return t
    } 
}

function LoadUploader() {
    /* Example 1 */
    var button = $('#button1'), interval;
    if (button) {
        new AjaxUpload(button, {
            action: 'FileHandler.ashx',
            name: 'myfile',
            onSubmit: function(file, ext) {
                // change button text, when user selects file			
               button.text('מעלה');

                // If you want to allow uploading only 1 file at time,
                // you can disable upload button
                this.disable();

                // Uploding -> Uploading. -> Uploading...
                interval = window.setInterval(function() {
                    
                   
                    var text = button.text();
                    if (text.length < 4) {
                        button.text('...'+text);
                    } else {
                        buttons.text("מעלה");
                    }
                }, 200);
            },
            onComplete: function(file, response) {
                window.clearInterval(interval);
                button.text("צרף קובץ");
                $("#my_image").css("display","block");
                $("#my_image").attr("src","imagebank3/"+file);
                filename = file;
            }
        });
    }
}

