﻿
var Content3ID = "ctl00_middleContent_";
var sSelected = "";
var g_iMaxSelected = 5;
var g_arrCountries = new Array();
var oList = document.getElementById(Content3ID + 'lstSelectedCountries');

function OpenPop(url, n, w, h, s)
{
	window.open(url, n, "menubar=no,resizable=no,statusbar=no,width="+w+", height="+h+", top=130, left=150, scrollbars="+s);
}
function OpenPopGA(url, n, w, h, s)
{
    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'שם מפעיל ומפת כיסוי',currentCountry]);
	window.open(url, n, "menubar=no,resizable=no,statusbar=no,width="+w+", height="+h+", top=130, left=150, scrollbars="+s);
}
function OpenOtherWindow(url)
{
    window.open(url);
}

function LoadCountries()
{
    var oList = document.getElementById(Content3ID + 'lstCountries');
	var i = 0;
	var len = oList.options.length;
    
	for(i = 0; i < len; i++)
	{
		g_arrCountries[i] = new Array();
		g_arrCountries[i][0] = oList.options[i].text;
		g_arrCountries[i][1] = oList.options[i].value;
	}
}

function CleanField(el)
{
	el.value = "";
	el.className = "SelectCountry";
}

function UpdateCountries(value)
{	
	var lstCountries = document.getElementById(Content3ID + 'lstCountries');
	
	while(lstCountries.options.length > 0)
	    lstCountries.removeChild(lstCountries.childNodes[0]);
		//lstCountries.options.remove(0);
		
	var i = 0;
	var oOption;
	var len = g_arrCountries.length;
	
	for(i = 0; i < len; i++)
	{
		if(g_arrCountries[i][0].indexOf(value) == 0)
		{
			oOption = document.createElement("OPTION");
			lstCountries.options.add(oOption);
		
			oOption.text = g_arrCountries[i][0];
			oOption.value = g_arrCountries[i][1];
		}
	}
}

function UpdateTxtSelectCountry(value)
{
    
    
    var lstCountries = document.getElementById(Content3ID + 'lstCountries');
    var text = lstCountries.options[lstCountries.selectedIndex].text;
    
    var txtSelectCountry = document.getElementById(Content3ID + 'txtSelectCountry');
    txtSelectCountry.value = text;
}

function SelectCountry()
{
    var lstCountries = document.getElementById(Content3ID + 'lstCountries');
    var value = lstCountries.value;
	if(value == "")
	{
		alert("נא לבחור מדינה");
		return;
	}
    var lstSelectedCountries = document.getElementById(Content3ID + 'lstSelectedCountries');
	
	if( IsExists(value, lstSelectedCountries) )
	{
		alert("המדינה שבחרת כבר קיימת");
		return;
	}
	
	addItem(lstCountries.options[lstCountries.selectedIndex], lstSelectedCountries, -1);
}

function addItem(oItem, oList , iPos)
{
	if(oList.options.length>=g_iMaxSelected)
	{
		alert("ניתן לבחור עד " + g_iMaxSelected + " מדינות");
		return;
	}
	var oOption = document.createElement("OPTION");
	if(iPos == -1)
		oList.options.add(oOption);
	else
		oList.options.add(oOption, iPos);
		
	oOption.text = oItem.text;
	oOption.value = oItem.value;
}

function IsExists(oItem, oList)
{
	var i;
	var len = oList.options.length;
	for(i = 0; i < len; i++)
	{
		if( oList.options[i].value == oItem )					
		{
			return true;
		}
	}
	return false;
}

function OnKeyDown(obj)
{
	if( obj.selectedIndex<0 )
		return;
	if(event.keyCode==110 || event.keyCode==46)
	{
		RemoveCountry(obj);
	}
}

function OnKeyDown(obj,event)
{
	if( obj.selectedIndex<0 )
		return;
	if(event.keyCode==110 || event.keyCode==46)
	{
		RemoveCountry(obj);
	}
}

function RemoveCountry(obj)
{
    var obj = document.getElementById(Content3ID + 'lstSelectedCountries');
    
	if(obj.selectedIndex < 0)
	{
		alert("לא נבחרו מדינות");
		return;
	}
	$('#'+Content3ID + 'lstSelectedCountries' + ' option:selected').remove();		
	if(obj.options.length == 0){}
	else{obj.selectedIndex = 0;}
}

function ClearSelected(btnObj)
{
    var lstSelectedCountries = document.getElementById(Content3ID + 'lstSelectedCountries');
    
	if(lstSelectedCountries.options.length == 0)
	{
		btnObj.disabled = true;
		return;
	}
	
	$('#'+ Content3ID + 'lstSelectedCountries option').remove();
		
	btnObj.disabled = true;
}

function SubmitCountry_Click()
{
    var i;
	var oList = document.getElementById(Content3ID + 'lstSelectedCountries');
	
	if(oList.options.length > 0)
	{
		var sStates = "";
		_gaq.push(['_trackEvent', 'Abroad Rates Search', 'כמות מדינות בחיפוש', oList.options.length]);                
		for(i = 0; i < oList.options.length; i++)
		{
		    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'מדינות שחופשו', oList.options[i].innerHTML]);		    
			sStates += oList.options[i].value;
			sStates += ".";		
		}
		
		if(i > 1)
		{
			document.getElementById("tdRemark").style.display = "block";
		}
		else
		{
			document.getElementById("tdRemark").style.display = "none";
		}
		
		var inpCountryIdList = document.getElementById(Content3ID + 'inpCountryIdList');
		inpCountryIdList.value = sStates;
				
		__doPostBack('ctl00$middleContent$lbtSubmit','')
	}
}

//************************ AbroadPrices_Results *****************************//
var oSelectedState = null;
var iSelectedStateId = -1;
var oSelectedTech = null;
var oSelectedTechImg = null;	

var oSelectedTechAdv = null;
var oSelectedTechAdvImg = null;

function ShowHideDiv(sObj, id)
{
    var elem = document.getElementById(sObj);
    var bShow = iSelectedStateId != id;
	
	if( bShow )
	{
	    elem.style.display = "block";
		if(oSelectedState != null)
		{
			oSelectedState.style.display = 'none';
		    var img = document.getElementById("img_arrow_"+iSelectedStateId);
		    img.src = img.src.replace('arrow_down', 'arrow_left');
		}
		oSelectedState = elem;
		iSelectedStateId = id;
		oSelectedTech = null;
		
		var img = document.getElementById("img_arrow_"+id);
		img.src = img.src.replace('arrow_left', 'arrow_down');
	}
	else
	{
		var img = document.getElementById("img_arrow_"+id);
		img.src = img.src.replace('arrow_down', 'arrow_left');
		
		elem.style.display = 'none';
		iSelectedStateId = -1;
		oSelectedState = null;
	}
}
var currentCountry = '';
var isFirst = true;
function ShowHideDivGA(sObj, id, country)
{
    var elem = document.getElementById(sObj);
    var bShow = iSelectedStateId != id;
	
	if( bShow )	
	{
	    currentCountry = country;
//	    if(!isFirst)	    
    	    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'הרחבת מידע תעריפים למדינה',country]);    	        	
  //  	else
    //	    isFirst = false;    
    	
	    elem.style.display = "block";
		if(oSelectedState != null)
		{
			oSelectedState.style.display = 'none';
		    var img = document.getElementById("img_arrow_"+iSelectedStateId);
		    img.src = img.src.replace('arrow_down', 'arrow_left');
		}
		oSelectedState = elem;
		iSelectedStateId = id;
		oSelectedTech = null;
		
		var img = document.getElementById("img_arrow_"+id);
		img.src = img.src.replace('arrow_left', 'arrow_down');
	}
	else
	{
		var img = document.getElementById("img_arrow_"+id);
		img.src = img.src.replace('arrow_down', 'arrow_left');
		
		elem.style.display = 'none';
		iSelectedStateId = -1;
		oSelectedState = null;
	}
}

function ShowHideDivTech( sObj, imgObj, imgName )
{
    var elem = document.getElementById(sObj);
	var elemImg = document.getElementById(imgObj);
	
	var bShow = elem.style.display == "none";
	
	if( bShow )
	{
		elem.style.display = "block";
		elemImg.src = imgName + "_on.gif";
		if(oSelectedTech != null)
		{
			oSelectedTech.style.display = "none";
			//replace the old selected category image from "on" to "off"
			oSelectedTechImg.src = oSelectedTechImg.src.replace("_on","_off");
		}
		oSelectedTech = elem;
		oSelectedTechImg = elemImg;
	}
	else
	{
		elem.style.display = "none";
		elemImg.src = imgName + "_off.gif";
		oSelectedTech = null;
	}
}

function ShowHideDivTechAdv( sObj ,imgObj, imgName )
{
	var elem = document.getElementById(sObj);
	var elemImg = document.getElementById(imgObj);
	
	var bShow = elem.style.display=="none";
	
	if( bShow )
	{
		elem.style.display="block";
		elemImg.src = imgName+"_on.gif";
		if( oSelectedTechAdv!=null)
		{
			oSelectedTechAdv.style.display="none";
			//replace the old selected category image from "on" to "off"
			oSelectedTechAdvImg.src = oSelectedTechAdvImg.src.replace("_on","_off");
		}
		oSelectedTechAdv = elem;
		oSelectedTechAdvImg = elemImg;
	}
	else
	{
		elem.style.display="none";
		elemImg.src = imgName+"_off.gif";
		oSelectedTechAdv = null;
	}
	
	_gaq.push(['_trackEvent', 'Abroad Rates Search', 'High Speed GSM', currentCountry]);
}

function SetSelectedTechAdv(obj){
	oSelectedTechAdv = document.getelementById(obj);
}

function AdvancedRatesOn(sObj1, sObj2){
	var elem = document.getElementById(sObj1);
	var elem2 = document.getElementById(sObj2);
	
	elem.style.display="block";
	elem2.style.display="none";
}

function ReplaceDivs(sObj1, sObj2, sObj3, sRem1, sRem2, sRem3, img1, img2, img3){
	var elem1 = document.getElementById(sObj1);
	var elem2 = document.getElementById(sObj2);
	var elem3 = document.getElementById(sObj3);
	elem1.style.display="block";
	if(elem2 != null)
	{
	    elem2.style.display="none";
	}
	if(elem3 != null)
	{
	    elem3.style.display="none";
	}
	
	var elemRem1 = document.getElementById(sRem1);
	var elemRem2 = document.getElementById(sRem2);
	var elemRem3 = document.getElementById(sRem3);
	elemRem1.style.display="block";
	if(elemRem2 != null)
	{
	    elemRem2.style.display="none";
	}
	if(elemRem3 != null)
	{
	    elemRem3.style.display="none";
	}
	
	var elemImg1 = document.getElementById(img1);
	var elemImg2 = document.getElementById(img2);
	var elemImg3 = document.getElementById(img3);
	elemImg1.src = elemImg1.src.replace('_off.jpg', '_on.jpg');
	if(elemImg2 != null)
	{
	    elemImg2.src = elemImg2.src.replace('_on.jpg', '_off.jpg');
	}
	if(elemImg3 != null)
	{
	    elemImg3.src = elemImg3.src.replace('_on.jpg', '_off.jpg');
	}
	
	if(sObj1.indexOf('Taarifon') > -1)
	    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'SMS-שיחות ו', currentCountry]);
	else if(sObj1.indexOf('Surf') > -1)
	    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'שירותי גלישה', currentCountry]);
	else if(sObj1.indexOf('Video') > -1)
	    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'שיחות וידאו', currentCountry]);
}

function PrintResult(sCountryId, CategoryType, TechnologyType, EnableShowVideo){
    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'הדפס',currentCountry]);

    var url = SiteUrl+'/Corporate/Abroad/AbroadPrices_Results.aspx';
    var param = '?iExp=3&sStates=' + sCountryId + '&CategoryType=' + CategoryType + '&iTech=' + TechnologyType+ '&EnableShowVideo=' + EnableShowVideo;
    document.location.href = url + param;
}
function SendSmsPrice(CountryId, CategoryType, TechnologyType){
    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'שלח SMS',currentCountry]);

    var href = window.location.href;
    var Left = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
    var Top = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

    var url = AppRoot + '/3G/Corporate/PlelephoneAbroad/SendPricesSms/.aspx';
    var param = '?CountryId=' + CountryId + '&CategoryType=' + CategoryType + '&TechnologyType=' + TechnologyType;

    if(href.indexOf('PlelephoneAbroad/info_device/.aspx') > -1)
    {
        Top = 180;
    }
    document.getElementById("iframePopup" + CountryId).src = url + param;
    $("#divPopUp" + CountryId).css('top', Top - 70);
    $("#divPopUp" + CountryId).show();    
}
function CloseDivPopup(CountryId){
    document.getElementById("iframePopup" + CountryId).src = '';
    $("#divPopUp" + CountryId).hide();
}

function OrderService(sCountryId, iIsAdv, iTech){
	parent.location.href="abroadorder.aspx";
}

function ShowSendDiv(obj){
    _gaq.push(['_trackEvent', 'Abroad Rates Search', 'שלח מייל',currentCountry]);
    var elem = $('#' + obj);
	var isShow = elem.css('display') == 'none';
	
	if(isShow)
	    elem.show();
	else
		elem.hide();
}

function SendService(sCountryId, CategoryType, iTech){
	var elem = $('#txtEmailTo' + sCountryId + '_' + CategoryType);
	if(elem.val().length == 0)
	{
		alert("נא להכניס כתובת אימייל");
		return;
	}
	
	if(isValidEmail(elem.val())==false)
	{
		alert("נא להכניס כתובת אימייל חוקית");
		return;
	}
	
    var url = SiteUrl+'/Corporate/Abroad/AbroadPrices_Results.aspx';
    var param = '?iExp=2&sStates=' + sCountryId + '&CategoryType=' + CategoryType + '&iTech=' + iTech + '&sEmail=' + elem.val();
	window.open(url + param, "SendEmail", "width=300, height=200");
	ShowSendDiv('dvSendEmail' + sCountryId); 
}

function OpenExplanation(sCountryID, CategoryType, boneId){

    if(boneId == '941')
        _gaq.push(['_trackEvent', 'Abroad Rates Search', 'GSM - הבהרות',currentCountry]);
    else if(boneId == '1154')
        _gaq.push(['_trackEvent', 'Abroad Rates Search', 'High Speed GSM - הבהרות',currentCountry]);
    
    var url = SiteUrl+"/Corporate/Abroad/ExplanationPopUp.aspx?";
    var param = 'sStates=' + sCountryID + '&CategoryType=' + CategoryType + '&boneId=' + boneId + '&isPrint=0';
    window.open(url + param,"","width=785,height=600,top=50,left=150,scrolling=yes,scrollbars=yes");
}

function OpenMoreDetails(iSaleId, sStateName){
	if(iSaleId==0)
		return;
	
	switch(iSaleId)
	{
		case 1:
			window.open("http://www.pelephone.co.il/templatearticle.asp?catId=324&pgId=1997","","width=250,height=200");
			break;
		case 2:
			window.open("http://www.z-kit.com/projects/issta/ski/minisite-01.html","","width=760,height=600,toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes,scrollbars=yes, resizable=yes");
			break;
		case 3:
			window.open("http://www.pelephone.co.il/popups/general_pop.asp?iCatId=142&iPageId=1980&iTitle=0","","width=500,height=350");
			break;
	}
}

function OpenCoverMap(str){
	var features = "";
	if(str.indexOf("http://")<0)
	{
	    //"http://www.gsmworld.com/cgi-bin/ni_map_ilpe.pl?"
		str = "http://www.europa.uk.com/cgi-bin/ni_map_ilpe.pl?"+str;
		features = "width=516,height=518,location=0,resizable=0,titlebar=0,left=0,top=0";
	}
	else
	{
		features = "width=516,height=518,location=0,left=0,top=0,resizable=1";
	}
	
	_gaq.push(['_trackEvent', 'Abroad Rates Search', 'שם מפעיל ומפת כיסוי',currentCountry]);

    window.open(str,"",features);	
}


/*---------------------------------------------------------------------------------------------
----------------------------------  Send Sms Popup  -------------------------------------------
---------------------------------------------------------------------------------------------*/
function ShowOtherPhone(divHide, divShow){
    $('#SmsPopup').removeClass("SmsPopupMin");
    $('#SmsPopup').addClass("SmsPopup");
    
    var iframe = top.document.getElementById('iframePopup' + CountryId);
    iframe.style.height = '394px';
    
    $('#'+divHide).hide();
    $('#'+divShow).show();
}

function SendSmsPopup(){
    var details = new Array();
    var arrIndex = 0;
    for(var i = 1; i < 6; i++)
    {
        $('#lblPel' + i).html('');
        var pel = $('#selectPre' + i).val() + $('#txtPel' + i).val();
        if(pel.length > 3 && pel.length < 10)
        {   
            $('#lblPel' + i).html('נא למלא מספר חוקי');
            return;
        }
        else if(pel.length == 10)
        {
            var obj = new Object();
            obj.Index = i;
            obj.Pel = pel;
            obj.IsOK = false;
            obj.IsSend = false;
            obj.Type = 0;
            details[arrIndex] = obj;
            arrIndex++;
        }
    }
    if(details.length > 0)
    {
        Waiting_ucWaiting.DisplayFloatingDiv();
        PageMethods.SendSmsPopup(details, callBackSendSmsPopup);
    }
    else
    {
        $('#lblPel' + 1).html('יש להזין מספר טלפון');
    }
}

function callBackSendSmsPopup(details){
    Waiting_ucWaiting.HiddenFloatingDiv();

    var isOk = true;
    var isAllSend = true;
    for(var i = 0; i < details.length; i++)
    {
        if(!details[i].IsOK)
        {
            isOk = false;
        }
        if(!details[i].IsSend)
        {
            isAllSend = false;
        }
    }
    if(isOk && isAllSend)
    {
        $('#divStep1').hide();
        $('#divStep2').show();
    }
    else
    {
        for(var i = 0; i < details.length; i++)
        {
            var lbl = $('#lblPel' + details[i].Index)
            lbl.html('');
            if(!(details[i].IsOK))
            {
                lbl.html('המספר שהוזן אינו מנוי בחברת פלאפון');
            }
            else if(!(details[i].IsSend) && isOk)
            {
                lbl.html('קרתה תקלה בשליחת ההודעה');
            }
        }
    }
}

function CloseSmsPopup(CountryId){
    top.CloseDivPopup(CountryId);
}

