﻿

//RHS Accordion Functionality


$(document).ready(function() {
    $(".menu_body:eq(0)").show();
    $("#firstpane div.menu_head").click(function() {
        if ($(this).find("p").attr("class") == "expanded") {
            $(this).find("p").removeClass("expanded");
        }
        else {
            $(this).find("p").addClass("expanded");
        }
        $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");

        $(this).siblings("div.menu_head").find("p").removeClass("expanded");

        $(this).siblings();
    });
});


function clearInput(o, msg) {
    o.value = o.value == msg ? "" : o.value;
}

function setInput(o, msg) {
    o.value = o.value == "" ? msg : o.value;
}

function downloadbrochure(language) {   
    
    if (language == "English")
        window.location.href = "DownloadFile.aspx?filename=pdf/TajAir_Brochure.pdf";
    else
        window.location.href = "DownloadFile.aspx?filename=pdf/TajAir_Brochure_french.pdf";
}

function SendMail() {

if(!validateSendmail())
return false;


   
    var xmlHttp;

    try {

        // Firefox, Opera 8.0+, Safari

        xmlHttp = new XMLHttpRequest();

    }

    catch (e) {

        // Internet Explorer

        try {

            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

        }

        catch (e) {

            try {

                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            catch (e) {

                alert("Your browser does not support AJAX!");

                return false;

            }

        }

    }

    //get user entered city name

    //var Fname = document.getElementById('Text1').value;



    //first parameter is to specify Method either GET or POST

    //second parameter is URL of server, where you want to send request

    //Third parameter would define either communication pattern is synchornous(false) or asynchornous(true)

    xmlHttp.open("GET", "mailing.aspx?MyName=" + document.getElementById('txtMyName').value + "&Mymailid=" + document.getElementById('txtMymailid').value + "&FndName=" + document.getElementById('txtFndName').value + "&Fndmailid=" + document.getElementById('txtFndmailid').value + "&CurrUrl=" + window.location, true);

    //GetWeather.aspx is include in sample, which is intermediate between your request and web service.



    //send request to server according to parameters

    xmlHttp.send();



    //defining function to call whenever xmlhttp state changes

    xmlHttp.onreadystatechange = function() {

        //if request has been entertained and response is returned from server

        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {               
                alert("Your Email to " + document.getElementById('txtFndName').value + " has been successfully sent.");
                clearfields();
            }
            
        }

    }
    return false;

}


 function validateSendmail() {
     //alert('Bala');
     debugger;
        var isnoError = true;
        var Myname = document.getElementById('txtMyName');
        var Fndname = document.getElementById('txtFndName');
        var Myemail = document.getElementById('txtMymailid');
        var Fndemail = document.getElementById('txtFndmailid');

//        function LTrim(value) {

//            var re = /\s*((\S+\s*)*)/;
//            return value.replace(re, "$1");

//        }
//        function RTrim(value) {

//            var re = /((\s*\S+)*)\s*/;
//            return value.replace(re, "$1");

//        }

//        // Removes leading and ending whitespaces
//        function trim(value) {

//            return LTrim(RTrim(value));

//        }



        if (((trim(Myname.value)) == "YOUR NAME") || ((trim(Myname.value)) == "") || ((trim(Myname.value)).length == "")) {
            isnoError = Errorboxrhs('mynamedivtext', Myname, "text-error-boxrhs");
            
        }
        else {
            if (!fn_Character_Check(Myname.value, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .'))
                isnoError = Errorboxrhs('mynamedivtext', Myname, "text-error-boxrhs");
            else
                Clearerrorboxrhs('mynamedivtext', Myname,'text-boxrhs');
        }


        

if (((trim(Myemail.value)) == "YOUR EMAIL ID") || ((trim(Myemail.value)) == "") || ((trim(Myemail.value)).length == "")) {
       

            isnoError = Errorboxrhs('mymaildivtext', Myemail, "text-error-boxrhs");
            
            
        }
        else {
            if (!fn_Email_Check(Myemail.value))
                isnoError = Errorboxrhs('mymaildivtext', Myemail, "text-error-boxrhs");
            else
                Clearerrorboxrhs('mymaildivtext', Myemail, 'text-boxrhs');
        }
        
        if (((trim(Fndname.value)) == "FRIEND NAME") || ((trim(Fndname.value)) == "") || ((trim(Fndname.value)).length == "")) {

        
            isnoError = Errorboxrhs('divfndNametext', Fndname, "text-error-boxrhs");

        }
        else {
            if (!fn_Character_Check(Fndname.value, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .'))
                isnoError = Errorboxrhs('divfndNametext', Fndname, "text-error-boxrhs");
            else
                Clearerrorboxrhs('divfndNametext', Fndname, 'text-boxrhs');
        }
        
        if (((trim(Fndemail.value)) == "FRIEND EMAIL ID") || ((trim(Fndemail.value)) == "") || ((trim(Fndemail.value)).length == "")) {

        
            isnoError = Errorboxrhs('divfndEmailtext', Fndemail, "text-error-boxrhs");
           
        }
        else {
            if (!fn_Email_Check(Fndemail.value))
                isnoError = Errorboxrhs('divfndEmailtext', Fndemail, "text-error-boxrhs");
            else
                Clearerrorboxrhs('divfndEmailtext', Fndemail,'text-boxrhs');
        }

        if (!isnoError)
            return false;
        else
            return true;

    }
    
    
    
      function Errorboxrhs(divObj, ctrObj, cssname) {
        //alert(divObj);
        //alert(document.getElementById(divObj).innerHTML=errtext);
        document.getElementById(divObj).style.visibility = "visible";
       // document.getElementById(divObj).innerHTML = errtext;
        ctrObj.className = cssname;
        return false;
    }
    
    function Clearerrorboxrhs(divObj, ctrObj, cssname) {
        document.getElementById(divObj).style.visibility = "hidden";
        ctrObj.className = cssname;
    }
    function clearfields()
    {
        var Myname = document.getElementById('txtMyName');
        var Fndname = document.getElementById('txtFndName');
        var Myemail = document.getElementById('txtMymailid');
        var Fndemail = document.getElementById('txtFndmailid');
        Myname.value="YOUR NAME";
        Fndname.value="FRIEND NAME";
        Myemail.value="YOUR EMAIL ID";
        Fndemail.value="FRIEND EMAIL ID";
    }
	
	

