﻿// JScript File
var Email;
function JF_LogUsrDtls() {}
// Example:

// writeCookie("myCookie", "my name", 24);

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}


function JF_NavigateCurr(url)
{
        wfcurr = 'toolbar=no,location=no,directories=no,top,left,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=688,height=353';
        currwin = window.open(url,'Currwindow',wfcurr)
        bname = navigator.appName;
		bver = parseInt(navigator.appVersion);
		//if (!(bname=="Microsoft Internet Explorer" && bver<"4"))
           //currwin.focus();
        if (currwin.opener == null) 
			currwin.opener = self;
			currwin.focus();
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//function MM_preloadImages() { //v3.0
//  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
//    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
//    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
//    var js_err="<%=vs_logerr%>";
//    if (js_err==""){
//<% If vb_custcd_passed="Y" Then %>
//			if (document.form_hbs.sle_Email.value!='')  
//				document.form_hbs.sle_pwd.focus();
//			else 
//				document.form_hbs.sle_Email.focus();
//<% Else %>
//			if (document.form_hbs.sle_CorpID.value!='' && document.form_hbs.sle_Email.value!='')  
//				document.form_hbs.sle_pwd.focus();
//			else if (document.form_hbs.sle_CorpID.value!='')
//				document.form_hbs.sle_Email.focus();
//			else
//				document.form_hbs.sle_CorpID.focus();
//<% End If %>
//		}
//		else 
//		{
//			if (js_err=="Invalid Corporate ID")
//				document.form_hbs.sle_CorpID.focus();
//			else if (js_err=="Invalid Password")
//				document.form_hbs.sle_pwd.focus();
//			else
//				document.form_hbs.sle_Email.focus();
//		}
//}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function JF_Submit(f)
{	
    var CorpId="";
    if(document.getElementById("hid_crpid").value!="")
    {
       CorpId=document.getElementById("hid_crpid").value;
    }
    else
    {
        CorpId=document.getElementById("txt_CrpId").value;
    }
    Email=document.getElementById("txt_Email").value;
    var Pwd=document.getElementById("txt_Pwd").value;
    var brwname=document.getElementById("hid_browser_name").value;
    var cookie=document.getElementById("hid_cookie_status").value;
	if (CorpId){
		if (!(JF_ChkNotNull(CorpId,"Corporate ID")))
			//return;
			return false;
		if (!(JF_ChkValidAlphaNumerStr(CorpId,"Corporate ID")))
			//return;
			return false;
	}
	if(JF_ChkNotNull(Email,"Email Address"))
	{
	}
	else
	return false
	if(JF_ChkValidEmail(Email,"Email Address"))	
	{
	}
	else
	return false
	if(JF_ChkNotNull(Pwd,"Password"))	
	{
	}
	else
	return false
	if(JF_ChkValidPwd(Pwd,"Password"))
	{	
//		document.form_hbs.hid_flag_login.value="Y";
//		document.form_hbs.action="Login.asp";
//		f.target="_self";
//		f.submit();	
        document.getElementById("hid_flag_login").value="Y";
//        fnsubmit();
      // return true;
	}
	else
	{
	    return false;
	}	
	/* For Loading*/
	JS_Loading()
	
	var objxml=new LSCreateXML();
	objxml.StartTag();
	objxml.AddParam("CrpId",CorpId);
	objxml.AddParam("Email",Email);
	objxml.AddParam("Pwd",Pwd);
	objxml.AddParam("brwsnam",brwname);
	objxml.AddParam("brwscookie",cookie);
	objxml.EndTag();
	var objget=new LSGetData();
	objget.SetParam(objxml.GetXml());
	objget.SetAsycMethod("resoponseLogin");
	objget.SetErrMethod("responseError");
	objget.SetOptionFlag("xx");
	if (window.location.protocol == "https:")
		objget.ReqSecuredServer("YES");
	objget.SetClassName("TCTSMEv2.TCTSMEv2_AjLogin,TCTSMEBO");
	objget.GetData();
	
}
function resoponseLogin(output,opt)
{
//alert(output);
var regex="[||]";
var arroutput
var jrvwstat;
if(output.match(regex)!=null)
{
  arroutput=output.split('||');
  document.getElementById("hid_user_id").value=arroutput[0];//Userid
  document.getElementById("hid_guid").value=arroutput[1];//Guid
  document.getElementById("hid_cust_cd").value=arroutput[2];//Cust_Cd
  document.getElementById("hid_user_typ").value=arroutput[3];//Test Booking Allowed or Not
  document.getElementById("hid_test_bkng").value=arroutput[4];//Test Booking Allowed or Not
  document.getElementById("hid_browser_name").value=arroutput[5];//BrowserName
  document.getElementById("hid_cookie_status").value=arroutput[6];//Cookie Status
  jrvwstat=arroutput[7];//Hotel Review
  /*For Images and style sheet*/
  document.getElementById("hid_img1").value=arroutput[10];//HidImage1
  document.getElementById("hid_img2").value=arroutput[11];//HidImage2
  document.getElementById("hid_img3").value=arroutput[12];//HidImage3
  document.getElementById("hid_ftrimg").value=arroutput[13];//HidImage3
  document.getElementById("hid_fill").value=arroutput[14];//HidImage3
  
  document.getElementById("hid_css").value=arroutput[9];//CSS
  
  document.getElementById("hid_imgpth").value=arroutput[8];//ImgPath
  
  /*End*/
  document.getElementById("hid_send_email").value=Email;
  nextpage(jrvwstat);
  
}
else   /*No '||' exist in the output string*/
{
    //alert(output);
    JS_Unloading();
    document.getElementById("lbl_error").innerHTML=output;
    document.getElementById("txt_Pwd").value="";
    
    /* If output is InvalidPassword then Forgot password has to be shown on the Login Page*/
//    if(output=="Invalid Password")
//    {
//        document.getElementById("tr_password").style.display="block";
//    }
//    else
//    {
//        document.getElementById("tr_password").style.display="none";
//    }
    /*End*/
   return false; 
}

}
function responseError(output,opt)
{
    
}

function JF_ChkNotNull(as_name, as_label){	
	js_val = Trim(as_name);
	js_err = 'N';
	if (js_val == "" || js_val== null ) 
	{	
		
			js_err= ' You seem to have forgotten to enter '+as_label+'! Please enter ' +as_label ;
	}
	else {
		for(var i=0;i<js_val.length;i++) 
			if (js_val.substring(i,i+1) != ' ') break;
			if (i>=js_val.length) {
				js_err= as_label + ' cannot be spaces.';
			}
		}
		if (js_err != 'N') {
			JF_ErrHandle(as_name, as_label, js_err) ;
			return false;
		}
		return true;
}

function JF_ChkValidAlphaNumerStr(as_name,as_label)
{
js_val = Trim(as_name);
 js_err = 'N';
 if (!(js_val == "" || js_val== null ))
  {
   for (var i =0; i < js_val.length; i++) 
    {
      if (js_val.substring(i,i+1) == ' ') 
       {
          js_err = as_label + ' cannot contain spaces.';
          break;
       }
      if (!(js_val.substring(i,i+1) >= 'a'  && js_val.substring(i,i+1) <= 'z'))
  	if (!(js_val.substring(i,i+1) >= 'A'  && js_val.substring(i,i+1) <= 'Z'))
  	if (!(js_val.substring(i,i+1) >= '0'  && js_val.substring(i,i+1) <= '9')) 
        {
           js_err = as_label + ' contains invalid characters.';
           break;
        }
      }
    if (js_err != 'N')
     {
       JF_ErrHandle(as_name, as_label, js_err) ;return false;
     }
   }
 return true;
}

function JF_ChkValidEmail(as_name,as_label){ // To Validate Email Id
//alert(as_name);
	////js_val=Trim(as_name);	 
	js_val=as_name;
	vs_error='N';
	if ((js_val != '') && (js_val != null)){
		for (var i =0; i < js_val.length; i++) 
			if (!(js_val.substring(i,i+1) >= "a"  && js_val.substring(i,i+1) <= "z"))	
			if (!(js_val.substring(i,i+1) >= "A"  && js_val.substring(i,i+1) <= "Z"))	
			if (!(js_val.substring(i,i+1) >= "0"  && js_val.substring(i,i+1) <= "9"))	
			if (!(js_val.substring(i,i+1) == "'" || js_val.substring(i,i+1) == "."  || js_val.substring(i,i+1) == "@" || js_val.substring(i,i+1) == "-" || js_val.substring(i,i+1) == "_" || js_val.substring(i,i+1) == "%" ))
			{
				js_err= as_label + ' contains invalid characters.'; 
				JF_ErrHandle(as_name, as_label, js_err) ;
				return false;
			}
			if (js_val.length <5 )vs_error='Y';
			if (js_val.indexOf('@') == -1) vs_error='Y';
			if (js_val.indexOf('.') == -1) vs_error='Y';
			js_first=js_val.substring(0,1);
			js_last=js_val.substring(js_val.length-1);
				if (js_first=='@' || js_last=='@' || js_first=='.' || js_last=='.') {
					vs_error='Y';}jl_pos = js_val.indexOf('@');
					js_next = js_val.substring(jl_pos+1,jl_pos+2);
					js_prev = js_val.substring(jl_pos-1,jl_pos);
					if ((js_next == '.') || (js_prev == '.')){
					vs_error='Y';
				}
			if (vs_error == 'Y') {
				js_err= 'Please specify a valid E-mail address'; 
				JF_ErrHandle(as_name, as_label, js_err) ;
				return false;
			}
		}
	return true;
}

function JF_ChkValidPwd(as_name,as_label) {
	js_val = Trim(as_name);
	js_err = 'N';
	if (!(js_val == "" || js_val== null )){
		if (js_val.length < 6) {
			js_err= as_label + ' cannot be less than 6 characters.';
		} 
		for (var i =0; i < js_val.length; i++) {
			if (js_val.substring(i,i+1) == ' ') {
				js_err = as_label + ' cannot contain spaces.';
				break; 
			}	
			if (!(js_val.substring(i,i+1) >= 'a'  && js_val.substring(i,i+1) <= 'z')) 	
			if (!(js_val.substring(i,i+1) >= 'A'  && js_val.substring(i,i+1) <= 'Z')) 	
			if (!(js_val.substring(i,i+1) >= '0'  && js_val.substring(i,i+1) <= '9')) {
				js_err = as_label + ' contains invalid characters.';
				break; 
			}
		}
		if (js_err != 'N'){
			JF_ErrHandle(as_name, as_label, js_err) ;
			return false;
		}
	}
	return true;
}

function JF_ErrHandle(as_name, as_label, as_err) { 
	alert(as_err);
	//as_name.focus();
return false;
 }
 function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
			
            trim_str = RTrim(LTrim(str));            
            return trim_str;
        }
        
        
        
 function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
        }
 function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // We don't want to trip JUST spaces, but also tabs,
                // line feeds, etc.  Add anything else you want to
                // "trim" here in Whitespace
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    // We have a string with trailing blank(s)...

                    var i = s.length - 1;       // Get length of string

                    // Iterate from the far right of string until we
                    // don't have any more whitespace...
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;


                    // Get the substring from the front of the string to
                    // where the last non-whitespace character is...
                    s = s.substring(0, i+1);
                }

                return s;
}
/* For Wrong password*/
function JF_SendPwd(asemail,ascustid,stylesheet)
{
		var curr = 'toolbar=no,location=no,directories=no,top,left,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=550,height=300';
		var jsstylesheet=document.getElementById(stylesheet);
		if(document.getElementById(asemail)!=null)
		{
		    var email=document.getElementById(asemail).value;
		}
		if(document.getElementById(ascustid)!=null)
		{
		    var custid=document.getElementById(ascustid).value;
		}
		else
		{
		    var custid=document.getElementById("hid_crpid").value;
		}
		if(custid=="")
		{
		    alert('Please Enter Your Corporate Id');
		    document.getElementById(ascustid).focus();
		}
		else if(email=="")
		{
		    //alert('Please Enter Your Email Address you have registered for this service');
		    alert('please enter the email id you have registered for this service');
		    document.getElementById(asemail).focus();
		}
		else
		{
            var currwin = window.open('TCTSMEv2_FrgtPwd.aspx?email='+email+'&custid='+custid+'&jstylesheet='+jsstylesheet.href,'Currwindow',curr)
            bname = navigator.appName;
		    bver = parseInt(navigator.appVersion);
		    //if (!(bname=="Microsoft Internet Explorer" && bver<"4"))
               //currwin.focus();
            if (currwin.opener == null) 
			    currwin.opener = self;
			    currwin.focus();
	    }
}

/* For Reseting Credit Card Details*/
function JF_SubmitPwd()
{
    JS_ResetPwdLoading();
    document.frm_TCTSMEv2_FrgtPwd.action='TCTSMEv2_ResetCrdtCrd.aspx';
	document.frm_TCTSMEv2_FrgtPwd.method='POST';
    document.frm_TCTSMEv2_FrgtPwd.submit();
}

//function JF_SendPwd(email,cust,custom)
//{
//		f=document.form_hbs;
//		f.hid_send_email.value=email;
//		f.hid_send_cust.value=cust;		
//		f.hid_send_custom.value=cust;
//		f.action="<%=Application("NonSecureServer")%>HBS_ForgotPwd.asp?Cust_CD="+cust;//"HBS_SendPwd.asp";
//		f.method="post";
//		f.target="_self";
//		f.submit();
//		return;
//}

//function JF_Click()
//    {		
//		//document.form_hbs.action="http://devserver05/SMERegnV42_work/yourinfo1.asp";//?hid_cust_cd=<%=cust_cd_custom%>
//		document.form_hbs.action="<%=Application("RegnSite_URL")%>";//?hid_cust_cd=<%=cust_cd_custom%>
//		document.form_hbs.submit();    
//    } 


//function fnsubmit()
//	{
//		document.form1.action="TCTSMEV2_SearchHotels.aspx";
//		document.form1.method="POST";
//		document.form1.submit();
//		
//	}
	
	function nextpage(args)
	{
	    if(args=="N")
	    {
	     document.frm_TCTSMEv2_Login.action='TCTSMEV2_SearchHotels.aspx';
	    }
	    else
	    {
	     document.frm_TCTSMEv2_Login.action='TCTSMEv2_CustReview.aspx';
	    }
	    
        document.frm_TCTSMEv2_Login.method='POST';
        document.frm_TCTSMEv2_Login.submit();
	}
	
	/* For AJAX*/
    var js_loading="<table cellpadding='0' cellspacing='0' width='100%' height='100%' >";
    js_loading+="<tr>";
    js_loading+="<td align='center' valign='middle' width='100%' height='100%'>"; 
    js_loading+="<div style='background-color:#FFFFFF;margin-left:25px;width:110px;height:120px' class='nrm_txt'><p align='center'><img src='images/AjaxLoading.gif' /></p><B>Please Wait...</B></BR>";
    //js_loading+="<p align='center'><img src='images/AjaxLoading.gif' /></p></div>";
    js_loading+="</div>";

//    js_loading+="</div>";
    js_loading+="</td>";
    js_loading+="</tr>";
    js_loading+="</table>";
//DISPLAY: block; LEFT: 0px; VISIBILITY: visible; WIDTH: auto; POSITION: static; TOP: 0px; HEIGHT: auto
    //
    function JS_Loading()
    {
    document.getElementById("div_loading").style.display='block';
    var js_loadcontainer=document.getElementById("div_loading");
    js_loadcontainer.style.height="650px";
    js_loadcontainer.style.width="1024px";
    js_loadcontainer.innerHTML=js_loading;
    js_loadcontainer.style.visibility='visible';
    js_loadcontainer.style.position="absolute";
//    js_loadcontainer.style.top="150px";
//    js_loadcontainer.style.left="250px";
    //js_loadcontainer.style.background="transparent"; 
    }
    function JS_Unloading()
    {
    var js_loadcontainer=document.getElementById("div_loading");
//    js_loadcontainer.style.height="250";
//    js_loadcontainer.style.width="250";
    js_loadcontainer.innerHTML="";
     js_loadcontainer.style.visibility='hidden';
    }
    
    
    /* Loading Image for Reset password*/
    var js_reset_loading="<table cellpadding='0' cellspacing='0' width='100%' height='100%' >";
    js_reset_loading+="<tr>";
    js_reset_loading+="<td align='center' valign='middle' width='100%' height='100%'>"; 
    js_reset_loading+="<div style='background-color:#FFFFFF;margin-left:6px;width:110px;height:120px' class='nrm_txt'><p align='center'><img src='images/AjaxLoading.gif' /></p><B>Please Wait...</B></BR>";
    js_reset_loading+="</div>";
    js_reset_loading+="</td>";
    js_reset_loading+="</tr>";
    js_reset_loading+="</table>";
    function JS_ResetPwdLoading()
    {
    document.getElementById("div_loading").style.display='block';
    var js_loadcontainer=document.getElementById("div_loading");
    js_loadcontainer.style.height="325px";
    js_loadcontainer.style.width="550px";
    js_loadcontainer.innerHTML=js_reset_loading;
    js_loadcontainer.style.visibility='visible';
    js_loadcontainer.style.position="absolute";
//    js_loadcontainer.style.top="150px";
//    js_loadcontainer.style.left="250px";
    //js_loadcontainer.style.background="transparent"; 
    }
    function JS_ResetPwdUnloading()
    {
    var js_loadcontainer=document.getElementById("div_loading");
//    js_loadcontainer.style.height="250";
//    js_loadcontainer.style.width="250";
    js_loadcontainer.innerHTML="";
     js_loadcontainer.style.visibility='hidden';
    }


function jf_regstr()
{
   //document.frm_TCTSMEv2_Login.action='TCTSMEv2_home.aspx'
   document.frm_TCTSMEv2_Login.action=document.getElementById("hid_regpage").value;
   document.frm_TCTSMEv2_Login.method='POST';
   document.frm_TCTSMEv2_Login.submit();
}