﻿
function isBlank(strValue){       
    if(trim(strValue,"").length == 0)
    {        
        return true;  
    }
    else 
    {
        return false;  
    }    
}

function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}


function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}


function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


//<Parameter name="messageDiplayID">
//null to dispaly message as Alert. 
//Pass Div ID to display message as Text.
//</Parameter>
//<Parameter name="displayMessage">Message.</Parameter>

function IsContainsSpecialChars(str,msg){       
    var regExp = new RegExp("\\W","g");       
    if (regExp.test(str)==true)
    {
       ShowMessage (msg);
       return false; 
    }   
}

function ValidateJPNumber( JPNumber,EmptyJPNumberMsg,ValidJPNumberMsg){         
    if( isBlank( JPNumber ) == false ) 
    {          
        if ( JPNumber.length != 9)
        {            
            ShowMessage (ValidJPNumberMsg);
            return false;        
        }
    }
    else 
    {
        ShowMessage (EmptyJPNumberMsg);
        return false;        
    }    
    return true;
}

function ValidateEqualToLength(JPNumber, valLength) {

    if (JPNumber.length < valLength) {
        return false;
    }
    else {
        return true;
    }
}

function ValidatePassword( Password,EmptyPasswordMsg,ValidPasswordMsg ){    
  if ( isBlank( Password )== false)
  {
     if ( Password.length < 5 || Password.length > 8)
        {
            ShowMessage (ValidPasswordMsg);
            return false;        
        }
  }   
  else 
  {
        ShowMessage (EmptyPasswordMsg);
        return false;        
  }    
} 

function IsDigit(e,Message)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;     
    if (keycode < 47 || keycode > 57)
    {
        if (keycode!=13)
        {  
            ShowMessage (Message);
            return false;    
        }
    }
}

function validatePasswordHint(oSrc, args)
{
    args.IsValid = (args.Value.length <= 50);
}

function validatePasswordLength(oSrc, args)
{
    args.IsValid = (args.Value.length >= 5 && args.Value.length <= 8);
}

function validatePNRLength(oSrc, args) {
    args.IsValid = (args.Value.length >= 6);
}

function CheckPNRLength(str) {
   return (str.length == 6);
}     

function CheckAlphabets(str)
{
    var exp = "^[a-zA-Z\\s]+$";
    var regex = new RegExp(exp);    
    return regex.test(str)
}

function CheckNumeric(str) {
    var exp = "^[0-9]*$";
    var regex = new RegExp(exp);
    return regex.test(str)
}

function openWindow(url,windowname,windowfeatures)
{
    try {
        var windowname = windowname.replace(/ /g, '');
        window.open(url, windowname, windowfeatures);     
    }
    catch(err)
    {
        ShowMessage(err.message); 
    }
}


//Select the downTime checkbox to delete.
function SetDeleteJob(obj, chkHeader) {
    
    var objHeader = document.getElementById(chkHeader);
    var index;
    var checkedAll = true;
    if (obj.checked == false) {
        objHeader.checked = false;
    }
    for (index = 0; index < document.forms[0].length; index++) {
        if (document.forms[0].elements[index].type == "checkbox" && document.forms[0].elements[index].id.indexOf(chkHeader) == -1) {

            if (document.forms[0].elements[index].checked == false) {
                checkedAll = false;
            }

        }
    }
    //alert(checkedAll);
    if (checkedAll == true) {
        objHeader.checked = true;
    }

}

//Check all checked to delete
function SetAllDeleteJob(obj) {
   
    var index;
    if (obj.checked) {
        for (index = 0; index < document.forms[0].length; index++) {

            if (document.forms[0].elements[index].type == "checkbox") {
                document.forms[0].elements[index].checked = true;
            }
        }
    }
    else {
        for (index = 0; index < document.forms[0].length; index++) {
            if (document.forms[0].elements[index].type == "checkbox") {
                document.forms[0].elements[index].checked = false;
            }
        }
    }
}

function DeleteSubmit(unSelected, confirmMsg)
{
    var flag = false;
    for (index=0; index<document.forms[0].length; index++)
	{
		if((document.forms[0].elements[index].type == "checkbox") && (document.forms[0].elements[index].checked == true))
		{
			flag = true;
		}
	}
	if(!flag)
	{
	    ShowMessage(unSelected);
	    return flag;
	}
	else {
	    if (confirmMsg != null || confirmMsg == "undefined") {
	        flag = confirm(confirmMsg);

	    }
	    return flag;
	}
}

function CheckValidFolderName(category)
{
	var boolResult = true;
	if(category=="con" || category=="CON")
	{
		boolResult = false;
	}
	return boolResult;
}

function validateAutoSuggestBox(autosuggestBoxAirport, lblMessage, strBlankOrigin) {

    var varOrigin = autosuggestBoxAirport.value;
    var varMessage = lblMessage;
    document.getElementById(varMessage).innerHTML = '';
    if (varOrigin == "--Select--") {
        document.getElementById(varMessage).innerHTML = strBlankOrigin;
    }
    if (document.getElementById(varMessage).innerHTML != strBlankOrigin && Page_ClientValidate() == true) return true;
    if (document.getElementById(varMessage).innerHTML == strBlankOrigin || Page_ClientValidate() == false) return false;

}

function setDefault(controlID,text)
{
    var sval=document.getElementById(controlID);
    if(trim(sval.value," ")=="")
    {
        sval.value = text;        
    }
}

function setBlank(objControl)
{
    if (objControl)
    objControl.value = "";  
}

//Check all checked to select functions
// Only for InfoMessages.aspx
function SetAllDeleteMessage(obj,objStopFlow) {
    var objStopFlow = document.getElementById(objStopFlow);
    var index;
    if (obj.checked) {
        for (index = 0; index < document.forms[0].length; index++) {

            if (document.forms[0].elements[index].type == "checkbox" &&
                    document.forms[0].elements[index].id!=objStopFlow.id) {
                document.forms[0].elements[index].checked = true;
            }
        }
    }
    else {
        for (index = 0; index < document.forms[0].length; index++) {
            if (document.forms[0].elements[index].type == "checkbox" &&
                    document.forms[0].elements[index].id!=objStopFlow.id) {
                document.forms[0].elements[index].checked = false;
            }
        }
    }
}

//Check-Uncheck All functions
// Only for InfoMessages.aspx
function SetDelete(obj, chkHeader,objStopFlow) {
    var objHeader = document.getElementById(chkHeader);
    var objStopFlow = document.getElementById(objStopFlow);
    var index;
    var checkedAll = true;
    if (obj.checked == false) {
        objHeader.checked = false;
    }
    for (index = 0; index < document.forms[0].length; index++) {
        if (document.forms[0].elements[index].type == "checkbox" && document.forms[0].elements[index].id.indexOf(chkHeader) == -1 && document.forms[0].elements[index].id!=objStopFlow.id) {

            if (document.forms[0].elements[index].checked == false) {
                checkedAll = false;
            }
        }
    }
    
    if (checkedAll == true) {
        objHeader.checked = true;
    }

}

function ShowMessage(strMessage)
{
    alert (strMessage); 
}

function getMonth(strMonth)
{
    strMonth = strMonth.toLowerCase();    
    switch (strMonth )
    {
        case "jan" || "january":
            return 1;
        case "feb" || "february":
            return 2;
        case "march" || "mar":
            return 3;
        case "april" || "apr":
            return 4;
        case "may" || "may":
            return 5;
        case "jun" || "june":
            return 6;
         case "jul" || "july":
            return 7;
         case "aug" || "august":
            return 8;
         case "sep" || "september":
            return 9; 
         case "oct" || "october":
            return 10; 
         case "nov" || "november":
            return 11; 
         case "dec" || "december":
            return 12;                
         default :
            return 0;      
    } 
}

function ValidateWithCurrentDate(source,args)
{
    var fulldate = args.Value.split('-');
   var date = new Date();           
   
   var dt1   = parseInt(fulldate[0],10); 
   var mon1  = parseInt(getMonth(fulldate[1]),10);
   var yr1   = parseInt(fulldate[2],10); 
   var dt2   = parseInt(date.getDate(),10); 
   var mon2  = parseInt(date.getMonth(),10); 
   var yr2   = parseInt(date.getYear(),10); 
   var date1 = new Date(yr1, mon1, dt1); 
   var date2 = new Date(yr2, mon2, dt2); 

   if(date1 > date2)
   {
        args.IsValid = false;  
   } 
   else 
   { 
      args.IsValid = true;  
   }    
}






function dropdownselection(ddlID,txtID) {
    
    var ddlCitiesID = document.getElementById(ddlID);
    var textboxID = document.getElementById(txtID);

    if(ddlCitiesID.options[ddlCitiesID.selectedIndex].text=="Other")
        textboxID.style.visibility = "visible";
        
    
    else    
        textboxID.style.visibility = "hidden";
}

function ddlselection(ddlID, txtID, valID) {
    //debugger;  
    var ddlCitiesID = document.getElementById(ddlID);
    var textboxID = document.getElementById(txtID);
    var val1 = document.getElementById(valID);
        
    if (ddlCitiesID.options[ddlCitiesID.selectedIndex].text == "Other") {
        textboxID.style.display = "";
        ValidatorEnable(val1, true)

    }
    else {
        textboxID.style.display = "none";
        ValidatorEnable(val1, false)
    }
}




function ValidateManagePolicy(dvPolicyID,dvPNRID,rbtPolicyNumberID,rbtPNRNumberID,valPolicyID,valRegPolicyNumberID,valPNRNumberID,valRegPNRID)
{
      var dvPolicy = document.getElementById(dvPolicyID);
      var dvPNR = document.getElementById(dvPNRID);   
      var rbtPolicyNumber = document.getElementById(rbtPolicyNumberID);  
      var rbtPNRNumber = document.getElementById(rbtPNRNumberID);  
      var valPolicy = document.getElementById(valPolicyID);  
      var valRegPolicyNumber = document.getElementById(valRegPolicyNumberID);  
      var valPNRNumber = document.getElementById(valPNRNumberID);  
      var valRegPNR = document.getElementById(valRegPNRID);
      
      if (rbtPolicyNumber.checked)
      {
        dvPolicy.style.display = "block"; 
        dvPNR.style.display = "none"; 
                
        ValidatorEnable(valPolicy,true);
        ValidatorEnable(valRegPolicyNumber,true);        
        
        ValidatorEnable(valPNRNumber,false);
        ValidatorEnable(valRegPNR,false);                
        
      }  
       
      if (rbtPNRNumber.checked) 
      {
        dvPolicy.style.display = "none"; 
        dvPNR.style.display = "block"; 
        
        ValidatorEnable(valPolicy,false);
        ValidatorEnable(valRegPolicyNumber,false); 
        
        ValidatorEnable(valPNRNumber,true);
        ValidatorEnable(valRegPNR,true);   
        
      } 
      Page_ClientValidate("ManageInsurancePolicy");     
}

function DisplayManagePolicyDiv(dvPolicyID,dvPNRID,rbtPolicyNumberID,rbtPNRNumberID)
{
      var dvPolicy = document.getElementById(dvPolicyID);
      var dvPNR = document.getElementById(dvPNRID);   
      var rbtPolicyNumber = document.getElementById(rbtPolicyNumberID);  
      var rbtPNRNumber = document.getElementById(rbtPNRNumberID);  
     
      if (rbtPolicyNumber.checked)
      {
        dvPolicy.style.display = "block"; 
        dvPNR.style.display = "none";                 
        
      }  
       
      if (rbtPNRNumber.checked) 
      {
        dvPolicy.style.display = "none"; 
        dvPNR.style.display = "block";                 
      }
  }

  function CheckAlphaWithSpecial(e  ) {
      if (navigator.appName == "Microsoft Internet Explorer") {
          var unicode = e.charCode ? e.charCode : e.keyCode
      }
      else {
          var unicode = e.charCode ? e.charCode : e.KeyAscii
      }
      if (unicode != 8 && unicode != 32 && unicode != 46 && unicode != 40 && unicode != 41 && unicode != 45 && unicode != 34 && unicode != 39) { //if the key isn't the backspace key (which we should allow)
          //alert(unicode);
          if (unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122) //if not a number
              return false //disable key press
      }
      
//      var isUpper = false;
//      var isLower = false;
//      var isSpl = false;
//      var isSpace = false;
//      var charCode;
//      charCode = (evt.which) ? evt.which : evt.keyCode;
//      if (charCode < 65 || charCode > 90) isUpper=true;
//      if (charCode < 97 || charCode > 122) isLower=true;
//      if (charCode < 44 || charCode > 46) isSpl=true;
//      if (charCode != 32) isSpace = true;
//      if (!isUpper || !isLower || !isSpl || !isSpace) return true;
//      else return false;
  }


  function isNumberKey(e) {
      if (navigator.appName == "Microsoft Internet Explorer") {
          var unicode = e.charCode ? e.charCode : e.keyCode
      }
      else {
          var unicode = e.charCode ? e.charCode : e.KeyAscii
      }
      if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
     if(unicode != 9)
     {
          if (unicode < 48 || unicode > 57) //if not a number
              return false //disable key press
      }
      }
//      var charCode = (evt.which) ? evt.which : evt.keyCode

//      if (charCode != 8) //allow backspace
//          return (charCode >= 48 && charCode <= 57) //allow only digits	
  }

  function isAlphabetKey(evt) {

      if (navigator.appName == "Microsoft Internet Explorer") {
          var unicode = evt.charCode ? evt.charCode : evt.keyCode
      }
      else {
          var unicode = evt.charCode ? evt.charCode : evt.KeyAscii
      }
      if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
     if(unicode != 9)
     {

          if (unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122) //if not a number
              return false //disable key press
      }
      }
      
//      var isUpper = false;
//      var isLower = false;
//      var charCode = (evt.which) ? evt.which : evt.keyCode

//      if (charCode < 65 || charCode > 90) isUpper = true;
//      if (charCode < 97 || charCode > 122) isLower = true;
//      if (!isUpper || !isLower) return true;
//      else return false;
  }
  function isAlphabetKeyWithWhiteSpace(evt) {
      var charCode = (evt.which) ? evt.which : evt.keyCode
      if (charCode == 32)
          return true;
      else if (charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode >= 35 && charCode <= 39 || charCode == 8 || charCode == 46) {
          if (evt.shiftKey == 1 && (charCode < 48 || charCode > 57))
              return false;
          else if (charCode >= 35 && charCode <= 39) {
              return true;
          }
      }
      else
          return false;
  }
  function isAlphabetKeyWithoutWhiteSpace(evt) {
      var charCode = (evt.which) ? evt.which : evt.keyCode
      if (charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode >= 35 && charCode <= 39 || charCode == 8 || charCode == 46) {
          if (evt.shiftKey == 1 && (charCode < 48 || charCode > 57))
              return false;
          else if (charCode >= 35 && charCode <= 39) {
              return true;
          }
      }
      else
          return false;
  }

  function isAlphaNumericKey(evt) {
      var isUpper = false;
      var isLower = false;
      var isSpl = false;
      var isSpace = false;
      var isDigit = false;
      var charCode;
      charCode = (evt.which) ? evt.which : evt.keyCode;
      if (charCode < 65 || charCode > 90) isUpper = true;
      if (charCode < 97 || charCode > 122) isLower = true;
      if (charCode < 44 || charCode > 46) isSpl = true;
      if (charCode < 48 || charCode > 57) isDigit = true;
      if (charCode != 32) isSpace = true;
      if (!isUpper || !isLower || !isSpl || !isDigit || !isSpace) return true;
      else return false;
  }

  function isAlphaNumericKeyWithWhiteSpace(evt) {
      var charCode = (evt.which) ? evt.which : evt.keyCode
      if (charCode > 31 && (charCode < 48 || charCode > 57)) {
          if (evt.shiftKey == 1 && (charCode < 48 || charCode > 57))
              return false;
          else if (charCode >= 35 && charCode <= 39)
              return true;
      }
  }

  function isAlphaNumericKeyWithOutWhiteSpace(evt) {
      var charCode = (evt.which) ? evt.which : evt.keyCode
      if (charCode > 31 && (charCode < 48 || charCode > 57)) {
          if (charCode == 32)
              return false;
          else if (evt.shiftKey == 1 && (charCode < 48 || charCode > 57))
              return false;
          else if (charCode >= 35 && charCode <= 39)
              return true;
      }
  }

  function formReset() {
     
     for (i = 0; i < Page_Validators.length; i++) 
       {

            Page_Validators[i].style.display = "none";

        }
        var coll = document.getElementsByTagName("Div");
        for(i = 0; i<coll.length;i++)
        {
            if (coll[i].className == "ErrorTxtMsg") {
                coll[i].style.display = "none";
            }
        }
        var coll = document.getElementsByTagName("span");
        for (i = 0; i < coll.length; i++) {
            if (coll[i].className == "ErrorTxtMsg") {
                coll[i].style.display = "none";
            }
        }
        
        var coll = document.getElementsByTagName("input");
        for (i = 0; i < coll.length; i++) {
            var indexOfBlank = coll[i].className.indexOf("Blank");            
            if (indexOfBlank != "-1") {                             
                var cssName = coll[i].className;                
                cssName = cssName.substring(0,indexOfBlank);
                coll[i].className = cssName;
                
            }
        }
        
       
        
 }
 function NumbersOnly(e) {
     if (navigator.appName == "Microsoft Internet Explorer") {
         var unicode = e.charCode ? e.charCode : e.keyCode
     }
     else {
         var unicode = e.charCode ? e.charCode : e.KeyAscii
     }
     if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
     if(unicode != 9)
     {
         if (unicode < 48 || unicode > 57) //if not a number
             return false //disable key press
      }
     }
 }

 function AlphabetsOnly(e) {
 
     if (navigator.appName == "Microsoft Internet Explorer") {
         var unicode = e.charCode ? e.charCode : e.keyCode
     }
     else {
         var unicode = e.charCode ? e.charCode : e.KeyAscii
     }
     if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
     if(unicode != 9)
     {
         if (unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122) //if not a number
             return false //disable key press
      }
     }
 }
 function AlphabetsOnlyWithWhiteSpace(e) {

     if (navigator.appName == "Microsoft Internet Explorer") {
         var unicode = e.charCode ? e.charCode : e.keyCode
     }
     else {
         var unicode = e.charCode ? e.charCode : e.KeyAscii
     }
     if (unicode != 8 && unicode != 32) { //if the key isn't the backspace key and space key (which we should allow)
       if(unicode != 9)
     {

         if (unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122) //if not a number
             return false //disable key press
     }
     }
 }
 function NameOnly(e) {
     if (navigator.appName == "Microsoft Internet Explorer") {
         var unicode = e.charCode ? e.charCode : e.keyCode
     }
     else {
         var unicode = e.charCode ? e.charCode : e.KeyAscii
     }
     if (unicode != 8 && unicode != 32 && unicode != 46 && unicode != 40 && unicode != 41 && unicode != 45 && unicode != 34 && unicode != 39) { //if the key isn't the backspace key (which we should allow)
     if(unicode != 9)
     {
         //alert(unicode);
         if (unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122) //if not a number
             return false //disable key press
     }
     }
 }
 
 
 
function getCookieEnableDisable(c_name)
{
if (document.cookie.length>0)
  {
    var results = document.cookie.match ( '(^|;) ?' + c_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;

  }
return "";
}

function setCookieEnableDisable(c_name,value,expiredays,path,domain)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
var cookie_string = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

  cookie_string += "; path=/";

  if (domain)
	   cookie_string += "; domain=" + escape ( 'jetairways.com' );

  document.cookie = cookie_string;



//document.cookie=+
//((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ ";path=/;domain=:jetairways.com";
}


// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
setCookieEnableDisable( 'checkCookie', 'none');
// if Get_Cookie succeeds, cookies are enabled, since
//the cookie was successfully created.
if (!getCookieEnableDisable('checkCookie'))
{
	//document.write( 'cookies are not currently enabled.' );
	window.location.href="/EnableCookies.aspx";
	/*
	this is an example of a set cookie variable, if
	you want to use this on the page or on another script
	instead of writing to the page you would just check that value
	for true or false and then do what you need to do.
	*/
	cookie_set = false;
	// and these are the parameters for Delete_Cookie:
	// name, path, domain
	// make sure you use the same parameters in Set and Delete Cookie.
	//Delete_Cookie('test', '/', '');
}
// if the Get_Cookie test fails, cookies
//are not enabled for this session.
//else
//{
//	document.write( 'cookies are not currently enabled.' );
//	cookie_set = false;
//}


/*Add for Personalization */
//Activity Details
function ViewAllStmtWidget(url) {
    url += "?FromWidget=ViewAllStmt";
    window.location.href = url;
}
function ViewStmtWidget(url, fromdate, toDate) {
    url += "?FromWidget=ViewStmt&Fromdate="+fromdate+"&Todate="+toDate;
    window.location.href = url;
}
