﻿ var ContextId = 'ctl00_middleContent_';
 
 function CheckKeys()
{
    var numVals = "1234567890";
    var counter;
    if ((event.keyCode == 46)||
		    (event.keyCode == 12)||
		    (event.keyCode >= 34 && event.keyCode <= 40)||
		    (event.keyCode >= 16 && event.keyCode <= 18))
    {
	    return true;
    }
    if (event.keyCode != 8 && event.keyCode != 13)
    {
	    if (event.keyCode == 9)
	    {
		    return true;
	    }
        for (var counter = 0; counter < numVals.length; counter++)
        {
			        if (event.keyCode == numVals.charCodeAt(counter) || event.keyCode == numVals.charCodeAt(counter)+48)
				        return true;
        }			    
        return false;
    }
    return true;
}

function CheckKeysString(obj)
{
	if (event.keyCode == 16)
	{
	    return true;
	}
	else
	{
	    if(event.keyCode >64 && event.keyCode<91 || event.keyCode == 186 || event.keyCode == 188 || event.keyCode == 190 || event.keyCode == 8 || event.keyCode == 13 || event.keyCode == 32 || event.keyCode == 46 || event.keyCode == 9 || event.keyCode == 20)
	    {
	        return true;
	    }
	    else
	    {
	        return false;
	    }
	}
}

function CheckForm(par)
{
	var el = document.getElementById(ContextId + "txtPName");
	var str,sErr;
	sErr = "";
	
	str = el.value;//.replace(" ","g");
	if(str.length==0)
	{
		sErr += "<div>נא למלא שם פרטי</div>";
	}
	
	el = document.getElementById(ContextId + "txtLName");
	str = el.value;
	if(str.length==0)
	{
		sErr += "<div>נא למלא שם משפחה</div>";
	}

    if(par == 1){
        el = document.getElementById(ContextId + "txtId");
	    str = el.value;
	    if(str.length!=9)
	    {
		    sErr += " <div>נא למלא מספר ת.ז</div>";
	    }
    }
    try{
    el = document.getElementById(ContextId + "tbxAddress");
	str = el.value;
	if(str.length==0)
	{
		sErr += "<div>נא להזין כתובת מגורים</div>";	    
	}}
	catch(e){}
	
	el = document.getElementById(ContextId + "txtCell");
	str = el.value;
	if(str.length!=7)
	{
		sErr += " <div>נא למלא מספר ליצירת קשר</div>";
	}
	
	
	
	el = document.getElementById(ContextId + "txtEmail");
	str = el.value;
	if(str.length>1)
	{
		 if(!isValidEmail(el.value)){
		sErr += "<div> נא להזין אי-מייל חוקי </div>";
	    }
	}
	
	if(sErr.length>0)
	{
	    var tdError = document.getElementById(ContextId + "tdError");
	    tdError.innerHTML = sErr;
		tdError.style.backgroundColor="#DADADA";
		tdError.style.color = "Red";
		tdError.style.fontSize = "11px";
		tdError.style.fontWeight = "normal";
	}
	
	return sErr.length==0;
}

//function isValidEmail(str) {
//	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
//}
function isValidEmail(str)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(str)) 
	{
		return false;
	}
	return true;
}

function DoPost(param)
{
    var selectCustomer = document.getElementById(ContextId + "selectCustomer");
    var tdError = document.getElementById(ContextId + "tdError");    
    if(selectCustomer.selectedIndex <= 0)
    {
        tdError.innerHTML = "נא לבחור סוג לקוח";
        tdError.style.backgroundColor="#DADADA";
        tdError.style.color = "Red";
        tdError.style.fontSize = "11px";
        tdError.style.fontWeight = "normal";
        return;
    }
    DoPostOld(param);
}

function DoBack()
{
    var divBack = document.getElementById(ContextId + "divBack");
    divBack.style.display = 'none';

    var tableMain = document.getElementById(ContextId + "tableMain");
    tableMain.style.display = 'block';
  
    var tdError = document.getElementById(ContextId + "tdError");
    tdError.innerHTML = '';
        
    var selectCustomer = document.getElementById(ContextId + "selectCustomer");
    var txtPName = document.getElementById(ContextId + "txtPName");
    var txtLName = document.getElementById(ContextId + "txtLName");
    try
    {
        var txtId = document.getElementById(ContextId + "txtId");
    }catch(e){}
    var txtEmail = document.getElementById(ContextId + "txtEmail");
    var txtCell = document.getElementById(ContextId + "txtCell");
    var drpPrefix = document.getElementById(ContextId + "drpPrefix");
       
    selectCustomer.selectedIndex = 0;
   
    txtPName.value = "";
    txtLName.value = "";
     try
     {
        txtId.value = "";
    }catch(e){}
    txtEmail.value = "";
    txtCell.value = "";
    drpPrefix.value = "050";
}

// Function For SiteFormsOld
function DoPostOld(param){
    if(CheckForm(param)){
        document.forms[0].submit();
    }
}

function SetClient(i)
{
	g_iPeleClient = i;
	if(i)
	{
		document.getElementById(ContextId + "drpPrefix").selectedIndex = 0;
		//document.getElementById(ContextId + "drpPrefix").disabled = true;
		document.getElementById(ContextId + "drpPrefix").disabled = false;
	}
	else
	{
		document.getElementById(ContextId + "drpPrefix").disabled = false;
	}
}

function DoBackOld()
{
    var divBack = document.getElementById(ContextId + "divBack");
    divBack.style.display = 'none';

    var tableMain = document.getElementById(ContextId + "tableMain");
    tableMain.style.display = 'block';
  
    var tdError = document.getElementById(ContextId + "tdError");
    tdError.innerHTML = '';
        
    var txtPName = document.getElementById(ContextId + "txtPName");
    var txtLName = document.getElementById(ContextId + "txtLName");
    try
    {
        var txtId = document.getElementById(ContextId + "txtId");
    }catch(e){}
    var txtEmail = document.getElementById(ContextId + "txtEmail");
    var txtCell = document.getElementById(ContextId + "txtCell");
    var drpPrefix = document.getElementById(ContextId + "drpPrefix");
       
    txtPName.value = "";
    txtLName.value = "";
     try
     {
        txtId.value = "";
    }catch(e){}
    txtEmail.value = "";
    txtCell.value = "";
    drpPrefix.value = "050";
}
$(function(){
var u = location.href.toLowerCase();
    var ind = u.indexOf('3g');    
    var ind2 = u.substr(ind+3).indexOf('/',u.substr(ind+3).indexOf('/')+1);    
    u = u.substr(ind+3,ind2);
    $('.mi > a').filter(function() {
        return this.href.toLowerCase().indexOf(u) > -1;
    }).parent().addClass('boneM'); if(($('.boneM').next().size()==0)&&($('.boneM').size()>0)){$('.leftM').addClass('leftOnBone')}; if($('.boneM').next().size()==0){$('.leftM').addClass('leftOnBone')}; 
    $('.rightM').hover(function(){$(this).addClass('rightMHover');},function(){$(this).removeClass('rightMHover');});    
    $('#menu li.mi').hover(
	function() {$(this).addClass('currentM');if($(this).next().size()==0){$('.leftM').addClass('leftOn')};displayMenu()},
	function() {$('.leftM').removeClass('leftOn');$('.mi.currentM iframe').hide();$(this).removeClass('currentM');$('.notLast,.last', this).fadeOut('fast').slideUp('fast')});
    $('#menu .mi .notLast:last,#menu .mi .last:last').removeClass('notLast').addClass('last');	
    $('.mi .notLast a,.mi .last a').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});        
    $('li.mi nobr a').click(function(){
        try{
            var t = $(this);
            var ItemName = jQuery.trim(t.text());
            var TabName = jQuery.trim(t.parents('li.mi').find('.menuImg').attr('alt'));
            _gaq.push(['_trackEvent', 'Top Menu', TabName + ' - ' + ItemName, document.title]); 
        }catch(e){}
    });    
    $('li.mi > a').click(function(){
        try{                   
            var TabName = jQuery.trim($(this).find('.menuImg').attr('alt'));
            _gaq.push(['_trackEvent', 'Top Menu', TabName, document.title]); 
        }catch(e){}
    });    
});
ends = function(){ $('.mi .notLast:visible,.mi .last:visible').parent().find('iframe').show();}
function displayMenu(){$('select').trigger('blur'); $('.mi.currentM .notLast,.mi.currentM .last').fadeIn('fast').slideDown('fast',ends); }
var originalUrl;
$(function(){    
    $('#menu nobr a,.submenu a').click(function(event){
        try{
            var isLoggedIn = $('#panelYesSession:visible').size();
            if (isLoggedIn > 0){
                event.preventDefault();
                originalUrl = $(this).attr('href');
                callPtp('LoginRedirect', 'id:"' + $(this).attr('id').replace('mi','').replace('rn','') + '"', ajaxAnswer,function(){
                    location.href = originalUrl;                
                });
            }
        }
        catch(e){
            location.href = originalUrl;
        }    
    });
});
ajaxAnswer = function(resp){
    if($.trim(resp).length > 0)
        location.href = resp;
    else        
        location.href = originalUrl;
}
function callPtp(methodName, params, onsuccess,fail){        
    $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: AppRoot+"/new/services/SessionManager.asmx/" + methodName,
      data: "{" + params + "}",
      dataType: "json",
      success: onsuccess,
      error: fail
    });
}
var clickedUrl = '';
$(function(){
    $('a[href*="login.do?u"]:not(.notPopup)').click(login);
    $('.openRegister').click(login2);
    $('.openReset').click(login3);
});
login = function(event){
    try{
        event.preventDefault();
        /*var isLoggedIn = $('#panelYesSession:visible').size();
        if (isLoggedIn > 0){            */
            clickedUrl = $(this).attr('href');
            var cUrl = clickedUrl;
            cUrl = cUrl.substr(cUrl.indexOf('login.do?u')+11);
            callLogin('IsLoggedIn2','id : "' + cUrl + '"',isLoggedIn2,showLogin);
        /*}
        else
            showLogin();*/
    }
    catch(e){}    
}
login2 = function(event){
    try{
        event.preventDefault();
        showLogin2();
    }
    catch(e){}    
}
login3 = function(event){
    try{
        event.preventDefault();
        showLogin3();
    }
    catch(e){}    
}
isLoggedIn2 = function(resp){
    if(resp == 1)
        location.href = clickedUrl;
    else        
        showLogin();
}
showLogin = function(){
    var w = 485;
    var h = 310;
    var b = '</div></div><div style="float:right"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -115px no-repeat"></div><div style="float:right;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -179px repeat-x;width:' + (w-16) + 'px" class="boLinks"><a style="float:right;color:#3082D6;font-weight:bold;margin-top:8px;cursor:pointer;text-decoration:underline" onclick="closeModal();showLogin2()" class="boLinksReg">הרשמה לאתר פלאפון</a><div style="float:right;color:#3082D6;font-weight:bold;margin-top:8px">&nbsp;&nbsp;|&nbsp;&nbsp;</div><a style="float:right;color:#3082D6;font-weight:bold;margin-top:8px;cursor:pointer;text-decoration:underline" onclick="closeModal();showLogin3()" class="boLinksReset">שכחתי סיסמה</a><a style="float:left;color:#3082D6;font-weight:bold;margin-top:8px" href="https://www.pelephone.co.il/web/login.do?u=vlEm67m25" target="_parent" class="boLinksReset">לכניסת לקוחות עסקיים</a></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -51px no-repeat"></div></div></div>';    
    var t = '<div style="float:right;width:' + (w) + 'px"><div style="float:right;height:29px"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -237px no-repeat"></div><div style="float:right;width:' + (w-16) + 'px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -266px repeat-x"><div class="titleLog" style="float:right;color:#0E6FCD;font-weight:bold;margin-top:6px;text-align:right;direction:rtl;font-size:14px">זיהוי משתמש</div><div style="float:left;width:15px;height:16px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px 0px no-repeat;margin-top:6px;cursor:pointer;_overflow:hidden" onclick="closeModal()"></div></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -208px no-repeat"></div></div><div style="width:' + (w) + 'px"><div style="float:right;width:' + (w-2) + 'px;background:#ffffff;border-right:solid 1px #3276A5;border-left:solid 1px #3276A5">';    
    var c = '<img src="/web/App_Themes/default/Images/login/LOAD-ANIMATION_shadow.gif" style="width:240px;height:140px;position:absolute;top:160px;left:123px;z-index:1" /><iframe width="'+(w-2)+'px" height="'+h+'px" frameBorder="0" scrolling="no" src="https://www.pelephone.co.il/web/login/pages/login.aspx" name="loginFrame" style="position:relative;z-index:1" allowtransparency="true"></iframe>';
    t = t+c+b;    
    $.modal(t, {minHeight:h,minWidth: w});                    
}
showLogin2 = function(){
    var w = 485;
    var h = 485;
    var b = '</div></div><div style="float:right"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -115px no-repeat"></div><div style="float:right;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -179px repeat-x;width:' + (w-16) + 'px" class="boLinks"></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -51px no-repeat"></div></div></div>';    
    var t = '<div style="float:right;width:' + (w) + 'px"><div style="float:right;height:29px"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -237px no-repeat"></div><div style="float:right;width:' + (w-16) + 'px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -266px repeat-x"><div class="titleLog" style="float:right;color:#0E6FCD;font-weight:bold;margin-top:6px;text-align:right;direction:rtl;font-size:14px">זיהוי משתמש</div><div style="float:left;width:15px;height:16px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px 0px no-repeat;margin-top:6px;cursor:pointer;_overflow:hidden" onclick="closeModal()"></div></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -208px no-repeat"></div></div><div style="width:' + (w) + 'px"><div style="float:right;width:' + (w-2) + 'px;background:#ffffff;border-right:solid 1px #3276A5;border-left:solid 1px #3276A5">';    
    var c = '<iframe width="'+(w-2)+'px" height="'+h+'px" frameBorder="0" scrolling="no" src="https://www.pelephone.co.il/web/login/pages/register.aspx" name="loginFrame2" allowtransparency="true"></iframe>';
    t = t+c+b;    
    $.modal(t, {minHeight:h,minWidth: w});                    
    $('.titleLog').text('ברוך הבא, הרשמה לאתר פלאפון');
}
showLogin3 = function(){
    var w = 485;
    var h = 390;
    var b = '</div></div><div style="float:right"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -115px no-repeat"></div><div style="float:right;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -179px repeat-x;width:' + (w-16) + 'px" class="boLinks"></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -51px no-repeat"></div></div></div>';    
    var t = '<div style="float:right;width:' + (w) + 'px"><div style="float:right;height:29px"><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -237px no-repeat"></div><div style="float:right;width:' + (w-16) + 'px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -266px repeat-x"><div class="titleLog" style="float:right;color:#0E6FCD;font-weight:bold;margin-top:6px;text-align:right;direction:rtl;font-size:14px">זיהוי משתמש</div><div style="float:left;width:15px;height:16px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px 0px no-repeat;margin-top:6px;cursor:pointer;_overflow:hidden" onclick="closeModal()"></div></div><div style="float:right;width:8px;height:29px;background:url(/web/App_Themes/default/images/laptops/popup/box.gif) 0px -208px no-repeat"></div></div><div style="width:' + (w) + 'px"><div style="float:right;width:' + (w-2) + 'px;background:#ffffff;border-right:solid 1px #3276A5;border-left:solid 1px #3276A5">';    
    var c = '<iframe width="'+(w-2)+'px" height="'+h+'px" frameBorder="0" scrolling="no" src="https://www.pelephone.co.il/web/login/pages/resetPassword.aspx" name="loginFrame3" allowtransparency="true"></iframe>';
    t = t+c+b;    
    $.modal(t, {minHeight:h,minWidth: w});                    
    $('.titleLog').text('איפוס סיסמה');    
}
redirectToLink = function(){
    location.href = clickedUrl;
}
function callLogin(methodName, params, onsuccess,fail){        
    $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: AppRoot+"/login/ws/login.asmx/" + methodName,
      data: "{" + params + "}",
      dataType: "json",
      success: onsuccess,
      error: fail
    });
}
