﻿
//**********************************************************************************************************
//       TMJsUtility have common methods that are use in SearchAir,SearchHotel,SerachCar
//**********************************************************************************************************

function TMJsUtility()
{
    this._tempX=0;
    this._tempY=0;
    this._IE = document.all?true:false;
     //make query String of search result
    this.queryStringForSearchDetails="";
}
  
/*******************************************************************
     The following functions  are define in TMUtility.js: 
*******************************************************************/

// Get x,y position 
TMJsUtility.prototype.GetMouseXY = function(eventObj_)
{
    var body=document.body;
    this._tempX = this._IE ? event.clientX + body.scrollLeft : eventObj_.pageX;
    this._tempY = this._IE ? event.clientY + body.scrollTop : eventObj_.pageY;

    if (this._tempX < 0){this._tempX = 0}
    if (this._tempY < 0){this._tempY = 0}  
    return true;
}

//Show Details
TMJsUtility.prototype.ShowDetails = function(e,elementId_)
{
    if (!e) var e = window.event;
    this.GetMouseXY(e);
    jQuery('#'+elementId_)
    .css({top:this._tempY+20,left:this._tempX-200})
    .slideDown("slow")
    .end();
}

//Hide Details
TMJsUtility.prototype.HideDetails = function(elementId_)
{
    jQuery('#'+elementId_).slideUp();
}
  

//remove white space and special charcters
TMJsUtility.prototype.RemoveWhiteSpace = function(item_)
 {  
     try
     {
          if(item_ !=null)
          {
              item_ = item_.replace(/\r/g, " ");
              item_ = item_.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
              item_ = item_.replace(/'/g, "");
              item_ = item_.replace(/ +/g, " ");  
              item_ = item_.replace(/^\s/g, "");
              item_ = item_.replace(/\s$/g, "");	
                if (item_ == ' ')
                {
                    item_ = '';
                } 
            }     
      }
    catch(err){}
    return item_;
 }
 
//Get Airport code
TMJsUtility.prototype.GetAirportcode = function(txtSource_,airportCodeUrl_)
{
    var urlToOpen = airportCodeUrl_ + txtSource_;    
    var newWindow=window.open(urlToOpen,'airportcode','width=650,height=508,top =100,left=100,scrollbars=yes');
    newWindow.focus();    
}     
  
//Remove  special charcters ( like: \',),(,;,--,|)
TMJsUtility.prototype.ParseInput = function(stringToBeValidate_)
{    
    if(stringToBeValidate_==null || stringToBeValidate_.length==0)
    {
         return stringToBeValidate_;
    }
    else
    {
        var stringLength=stringToBeValidate_.length; 
        for(var i=0;i<stringLength;i++)
        {
            stringToBeValidate_ = stringToBeValidate_.replace('\'', '\"');
            stringToBeValidate_ = stringToBeValidate_.replace("\"","");
            stringToBeValidate_ = stringToBeValidate_.replace(")", "");
            stringToBeValidate_ = stringToBeValidate_.replace("(", "");
            stringToBeValidate_ = stringToBeValidate_.replace(";", "");
            stringToBeValidate_ = stringToBeValidate_.replace("--", "");
            stringToBeValidate_ = stringToBeValidate_.replace("|", "");
        }
       return stringToBeValidate_;
    }
}
 
 
 //Get Cookie data
TMJsUtility.prototype.GetCookieValue = function(cookieName_) 
{
    var exp = new RegExp (escape(cookieName_) + "=([^;]+)");
    if (exp.test (document.cookie + ";"))
    {
        exp.exec (document.cookie + ";");
        return unescape(RegExp.$1);
    }
    else
    {
      return false;
    }
}

//Compare current & cookies date   
TMJsUtility.prototype.CheckDate = function(date_)
{
    var today=new Date();
    var compareDate = new Date()      
    date_=date_.split("/");
    compareDate.setMonth(Number(date_[0])-1);
    compareDate.setDate(Number(date_[1]));        
    compareDate.setFullYear(Number("20"+date_[2])); 
    if(today<=compareDate)
    {                         
        return true;
    }
    else
    {
        return false;
    }     
}
//Trim string variable
String.prototype.trim = function() 
{
    return this.replace(/^\s+|\s+$/g,"");
}

    
