﻿// JScript File
function SelectMenuItem(sFormName)
{
    window.open("./" + sFormName + ".aspx","_self");
}

function showHide(myobjid,img)
{	
    if (myobjid.style.display == "none")
    {
        myobjid.style.display = "";						
        img.src="pictures/up.jpg";	
        img.alt="Kapa";
    }
    else
    {
        myobjid.style.display = "none";
        img.src="pictures/down.jpg";					
        img.alt="Aç";
    }   
}
function CheckFlyCriteria()
{
    var sMessage="";
    if(document.all("DDL_FROMWHERE").options[document.all("DDL_FROMWHERE").selectedIndex].value=="-1")
        sMessage+="Kalkış Yeri Seçilmedi!!!\n";
    if(document.all("DDL_TOWHERE").options[document.all("DDL_TOWHERE").selectedIndex].value=="-1")
        sMessage+="Varış Yeri Seçilmedi!!!\n";
    if(document.all("TXT_FROMDATE").value=="")
        sMessage+="Gidiş Tarihi Seçilmedi!!!\n";
    if(document.all("DDL_TRIPTYPE").options[document.all("DDL_TRIPTYPE").selectedIndex].value=="roundtrip")   
        if(document.all("TXT_TODATE").value=="")
            sMessage += "Dönüş Tarihi Seçilmedi!!!";
    if(sMessage!="")
    {
        alert(sMessage);
        return false;
    }

    else
    {
        var from = document.all("DDL_FROMWHERE").options[document.all("DDL_FROMWHERE").selectedIndex].value;
        var to = document.all("DDL_TOWHERE").options[document.all("DDL_TOWHERE").selectedIndex].value;
        document.all("CHK_THY").checked = true;
        document.all("CHK_PEGASUS").checked = false;
        document.all("CHK_ATLAS").checked = true;
        document.all("CHK_ONUR").checked = false;
        document.all("CHK_SUNEXPRESS").checked=false;

        if(from=="03401" || to=="03401")
        {
           document.all("CHK_ONUR").checked = true;
           //document.all("CHK_ATLAS").checked = true;
        }
        if(from=="03402" || to=="03402")
        {
           document.all("CHK_SUNEXPRESS").checked=true;
        }
        if(CheckPegasusLines(from,to))        
            document.all("CHK_PEGASUS").checked = true;

        showModalPopupViaClient();
        __doPostBack("BTN_SEARCHTICKET","");
    }
}

//function showModalPopupViaClient(ev) 
function showModalPopupViaClient() 
{
    //ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}
        
function hideModalPopupViaClient(ev) 
//function hideModalPopupViaClient() 
{
    //ev.preventDefault();        
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}

function CheckPegasusLines(from,to)
{
    // ^from~to~to....
    var flyes = "^00101~00701~03402~03501~03801~06101^03501~00101~00601~02101~02701~03401~03402~04401~04701~05501~06101^03801~00101~00601~03402" +
	            "^00701~00101~00601~03402~06101^04801~00601~03402^02101~00601~03402~03501^04802~03402" +
	            "^02501~00601~03402^00601~00701~04801~02101~02501~03402~03501~03801~06101~06501^02701~03402~03501^03401~03501" +
	            "^04401~03402~03501^04701~03501^03402~00101~00601~00701~04801~04802~02101~02501~02701~03501~03801~04401~06101~06501" +
	            "^05501~03501^06101~00101~00601~00701~03402~03501^06501~00601~03402";
	var indexOfFrom = flyes.indexOf("^" + from + "~");
	if(indexOfFrom>-1)
	{
	    // Take "~" symbol too	
	    var toflyes = flyes.substring( indexOfFrom + 6 , flyes.indexOf("^",indexOfFrom+7));
	    if(toflyes.indexOf("~" + to)>-1)	
		return true;	    
	}
	return false;
	            
}
