var timeout ;
function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function paymate(orderid)
{
	var phonenumber = document.getElementById('phnum').value;
	var amount = document.getElementById('Totalamount').value;
	document.paymate.Orderid.value = orderid;
	document.paymate.Amount.value = amount;
	document.paymate.Mobileno.value = phonenumber;
	document.paymate.submit();
      return true;
}

function itzcash(orderid)
{
	var amount = document.getElementById('Totalamount').value;
	document.itzcash.orderid.value = orderid;
	document.itzcash.productcost.value = amount;
	document.itzcash.submit();
      return true;
}


function threedsecure()
 {
       //alert("3d");
	 	var card1 = document.getElementById('Cardno1').value;
		var card2 = document.getElementById('Cardno2').value;
		var card3 = document.getElementById('Cardno3').value;
		var card4 = document.getElementById('Cardno4').value;
      	var pan = card1+card2+card3+card4;
      	var expiryear = document.getElementById('Expyear').value;
			expiryear = expiryear.substr(2,4);
	  	var expirmonth = document.getElementById('Expmonth').value;
	  	var expirydate = expirmonth+expiryear;
		var cvvno = document.getElementById('Cvv').value;
	   	var PurchaseAmount = document.getElementById('Totalamount').value;
		 PurchaseAmount =  PurchaseAmount.replace(',','');
			PurchaseAmount = PurchaseAmount+"00";
		var displayamount = document.getElementById('Totalamount').value;
			displayamount = formatCurrency(displayamount);
		var currencyvalue = 356;
       
	   
	  document.ThreeDsecure.pan.value = pan;
       document.ThreeDsecure.expirydate.value = expirydate;
       document.ThreeDsecure.purchaseAmount.value = PurchaseAmount;
	   document.ThreeDsecure.displayAmount.value = displayamount;
       document.ThreeDsecure.currencyVal.value = currencyvalue;
       document.ThreeDsecure.orderdesc.value='Airticket';
	   //alert("pan"+pan+"expdt"+expirydate+"PA"+PurchaseAmount);
       document.ThreeDsecure.submit();
       return true;
 }
function getradiovalue()
{
	var rad_val;
	for (var i=0; i < document.paymentformnew.Cardtype.length; i++)
	{
		if (document.paymentformnew.Cardtype[i].checked)
		{
			rad_val = document.paymentformnew.Cardtype[i].value;
			return rad_val;
		}
    }
}


function payment()
{
	
   	var baddrone=document.paymentformnew.Baddress1.value;
   	var baddrtwo=document.paymentformnew.Baddress2.value;
   	//var baddrthree=document.paymentformnew.Baddress3.value;	  	
   	var bcity=document.paymentformnew.Bcity.value;
   	var bstate=document.paymentformnew.Bstate.value;
	var bcountry=document.paymentformnew.Bcountry.value;
    var bphone=document.paymentformnew.Bphoneno.value;
    var bpincode=document.paymentformnew.Bpincode.value;
	var bmobile=document.paymentformnew.Bmobileno.value;
   	//var bareacode=document.paymentformnew.Bareacode.value;
    var bemail=document.paymentformnew.Bemailid.value;
	var cardshow=document.paymentformnew.carddisp.value;
	
	
	baddrone=trim(baddrone);
	baddrtwo=trim(baddrtwo);
	//baddrthree=trim(baddrthree);
	bcity=trim(bcity);
	bemail=trim(bemail);
	cardtype = getradiovalue();
	var form = document.paymentformnew;
	
	var adult=(form.adult.value);
	//alert (adult);
	if(adult>1)
	{
		for(i=0;i<adult;i++)
		{
			var fname=trim(form["Firstname[]"][i].value);
			
			if(fname=='')
			{	
				alert("Please enter the first name of the passenger in row " + (i+1)+".");
				form["Firstname[]"][i].focus();
			    return false;
			}
           	else
	    	{	
				count=fname.length;
				if (count <= 1)
				{	
					alert("Sorry, first name should have more than one character.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				else if (count > 50)
				{	
					alert("Sorry, currently we do not accept more than 50 characters for the first name.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				
		     }
			var lname=trim(form["Lastname[]"][i].value);
			if(lname=='')
			{	alert("Please enter the last name of the passenger in row " +(i+1)+".");
				form["Lastname[]"][i].focus();
				return false;
			}
		}
	}
	if(adult==1)
	{
		fname=trim(form["Firstname[]"].value);
		
		if(fname=='')
		{
	 		alert("Please enter the first name of the passenger.");
			form["Firstname[]"].focus();
			return false;
		}
		else
		{
			count=fname.length;
			if (count <= 1)
			{
				alert("First name should have more than one character, try again.");
				form["Firstname[]"].focus();
                return (false);
			}
			else if (count > 50)
			{	
				alert("Sorry, currently we do not accept more than 50 characters for the first name.");
				form["Firstname[]"].focus();
				return (false);
			}
		}
		lname=trim(form["Lastname[]"].value);
		if(lname=='')
		{
  			alert("Please enter the last name of the passenger.");
			form["Lastname[]"].focus();
	 		return false; 
		}
	} 

	if(baddrone=='')
	{
 		alert("Please enter the address 1 field.");
		document.paymentformnew.Baddress1.focus();
 		return false;
 	}
	else if (baddrone.length > 50) 
	{	
 		alert("Sorry, currently we do not accept more than 50 characters for address 1 field.");
		document.paymentformnew.Baddress1.value='';
		document.paymentformnew.Baddress1.focus();
 		return false;	
	}
	
	if(baddrtwo=='')
	{
 		alert("Please enter the address 2 field.");
		document.paymentformnew.Baddress2.focus();
 		return false;
 	}
	else if (baddrtwo.length > 50)
	{
		alert("Address 2 field length should be less than 51 characters.");
		document.paymentformnew.Baddress2.value='';
		document.paymentformnew.Baddress2.focus();
		return false;				
	}
	
	if(bcity=='')
	{
		alert("Please enter the city of the billing address.");
		document.paymentformnew.Bcity.focus();
		return false;
	}
	else if(bcity.length >30 )
	{
		alert("Please enter a valid city name with fewer characters.");
		document.paymentformnew.Bcity.focus();
		document.paymentformnew.Bcity.value='';
		return false;
	}
	
	if(bstate=='')
	{
		alert("Please enter the state of the billing address.");
		document.paymentformnew.Bstate.focus();
	 	return false;
 	}
	else if(bstate.length >30 )
	{
			 alert("Please enter a valid state name with fewer characters.");
			   document.paymentformnew.Bstate.value='';
				document.paymentformnew.Bstate.focus();
			
			return false;
	}
	
	if(bcountry=='')
	{
		alert("Please enter the country of the billing address.");
		document.paymentformnew.Bcountry.focus();
 		return false;
	}
	else if(bcountry.length >30 )
	{
			alert("Please enter a valid country name with fewer characters.");
			document.paymentformnew.Bcountry.focus();
			document.paymentformnew.Bcountry.value='';
			return false;
	}
	
	if(bpincode=='')
	{
		alert("Please enter the pincode of the billing address.");
		document.paymentformnew.Bpincode.focus();
		return false;
	}
	else if(bpincode.length > 9)
	{
		alert("Please enter a valid pincode with fewer characters.");
		document.paymentformnew.Bpincode.focus();
		document.paymentformnew.Bpincode.value='';
		return false;
	}
	
	if(bmobile=='')
	{
		alert("Please enter the mobile number.");
		document.paymentformnew.Bmobileno.focus();
		return false;
	}
	else if(bmobile.length < 10 || bmobile.length >12)
	{
		alert("Please provide a valid mobile number with 10 numeric characters.");
		document.paymentformnew.Bmobileno.focus();
		document.paymentformnew.Bmobileno.value="";
		
		return false;
	}
	
	if(bphone=='')
	{
		alert("Please enter the land line phone number with the STD code.");
		document.paymentformnew.Bphoneno.focus();
		return false;
	}
	else if ( (bphone.length > 12) || (bphone.length < 6) )
	{
		alert("Please enter a valid land line phone number with the STD code.");
		document.paymentformnew.Bphoneno.focus();
		document.paymentformnew.Bphoneno.value="";
		return false;
	}
	
	if(bemail=='')
	{
 		alert("Please enter the e-mail address.");
		document.paymentformnew.Bemailid.focus();
 		return false;
	}
	else if(emailval(document.paymentformnew.Bemailid.value)==false)
	{
		document.paymentformnew.Bemailid.value=''
		document.paymentformnew.Bemailid.focus();
		return false;
	}
	if(cardshow == 'show' && cardtype != 'PM' && cardtype != 'IH')
	{
		
		if(document.getElementById('Cardno1').value == '')
		{
			alert("Please enter the first four digits of the credit card.");
			document.getElementById('Cardno1').focus();
			return false;
		}
		else if(document.getElementById('Cardno1').value.length < 4)
		{
			alert("Please enter the correct first four digits of the credit card.");
			document.getElementById('Cardno1').focus();
			return false;
		}
		
		if(document.getElementById('Cardno2').value == '')
		{
			alert("Please enter the second four digits of the credit card.");
			document.getElementById('Cardno2').focus();
			return false;
		}
		else if(document.getElementById('Cardno2').value.length < 4)
		{
			alert("Please enter the correct second four digits of the credit card.");
			document.getElementById('Cardno2').focus();
			return false;
		}
		
		if(document.getElementById('Cardno3').value == '')
		{
			alert("Please enter the third four digits of the credit card.");
			document.getElementById('Cardno3').focus();
			return false;
		}
		else if(document.getElementById('Cardno3').value.length < 4)
		{
			alert("Please enter the correct third four digits of the credit card.");
			document.getElementById('Cardno3').focus();
			return false;
		}
		
		
		rad_val = getradiovalue();
		if(rad_val == 'AMEX')
		{
			if(document.getElementById('Cardno4').value == '')
			{
				alert("Please enter the last three digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
			else if(document.getElementById('Cardno4').value.length < 3)
			{
				alert("Please enter the correct last three digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
		}
		else if(rad_val == 'VISA' || rad_val == 'MC')
		{
			if(document.getElementById('Cardno4').value == '')
			{
				alert("Please enter the last four digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
			else if(document.getElementById('Cardno4').value.length < 4)
			{
				alert("Please enter the correct last four digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
		}
		
		if(document.getElementById('Expmonth').value == '')
		{
			alert("Please select the expiry month of the card.");
			document.getElementById('Expmonth').focus();
			return false;
		}
		
		if(document.getElementById('Expyear').value == '')
		{
			alert("Please select the expiry year of the card.");
			document.getElementById('Expyear').focus();
			return false;
		}
		if(document.getElementById('Cvv').value == '')
        {
                alert("Please enter the CVV number of the card.");
                document.getElementById('Cvv').focus();
                return false;
        }		
	
		if(rad_val == 'VISA' || rad_val == 'MC')
		{
			if(document.getElementById('Cardholder').value == '')
			{
				alert("Please enter the name of the card holder.");
				document.getElementById('Cardholder').focus();
				return false;
			}
		}
		else if(rad_val == 'AMEX')
		{
			if(document.getElementById('Cvv').value == '')
				{
						alert("Please enter the CVV number of the card.");
						document.getElementById('Cvv').focus();
						return false;
				}
	
			if(document.getElementById('amexFirstname').value == '')
			{
				alert("Please enter the first name of the card holder.");
				document.getElementById('amexFirstname').focus();
				return false;
			}
			if(document.getElementById('amexMiddlename').value == '')
			{
				alert("Please enter the middle name of the card holder.");
				document.getElementById('amexMiddlename').focus();
				return false;
			}
	
			if(document.getElementById('amexLastname').value == '')
			{
				alert("Please enter the last name of the card holder.");
				document.getElementById('amexLastname').focus();
				return false;
			}
	
		}
	}
	
	xajax_paymentdetails(xajax.getFormValues("paymentformnew"));
}


function logout()
{
	var check = confirm('Do you want to logout?');
	if(check)
	{
			return true;
	}
	else
	{
			return false;
	}
}
function goindex()
{
	document.location.href = "../yourprice/sessiondestroy.php" 
}
function searchorder(orderid,emailid)
{
	xajax_searchuserorder(orderid,emailid);
}


function gotocard2(value)
{
	if(value.length>=4)
	{
		document.getElementById('Cardno2').focus();
	}
}
function gotocard3(value)
{
	if(value.length>=4)
	{
		document.getElementById('Cardno3').focus();
	}
}
function gotocard4(value)
{
	
	if(value.length>=4)
	{
		document.getElementById('Cardno4').focus();
	}
}
function gotoselect(value)
{
	rad_val = getradiovalue();
	if(rad_val == 'AMEX')
	{
		if(value.length>=3)
		{
			document.getElementById('Expmonth').focus();
		}
	}
	else if(rad_val == 'VISA' || rad_val == 'MC')
	{
		if(value.length>=4)
		{
			document.getElementById('Expmonth').focus();
		}
	}
}

function gotocardname(value)
{
	
	if(value.length>=4)
	{
		document.getElementById('Cardholder').focus();
	}
}

function emailval(emailid)
{
	
	//var emailid=document.getElementById("emailid").value;
	//alert(emailid);
	var at="@";
	var dot=".";
	var lat=emailid.indexOf(at);
	var lemailid=emailid.length;
	var ldot=emailid.indexOf(dot);
	

	if(emailid=="")
	{
		alert("Please enter your correct email address.");
	}

	if(emailid.length > 0) 
	{

		if (lat==-1 || lat==0 || lat==lemailid)
		{
		   	alert("Please enter your correct email address.");
		   	emailid = "";
		   	
		   	return false;
		}
		if (ldot==-1 || ldot==0 || ldot==lemailid)
		{
		    	alert("Please enter your correct email address.");
			 emailid = "";
		   	 
		    	return false;
		}
		if (emailid.indexOf(at,(lat+1))!=-1)
		{
		   	alert("Please enter your correct email address.");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.substring(lat-1,lat)==dot || emailid.substring(lat+1,lat+2)==dot)
		{
		    	alert("Please enter your correct email address.");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(dot,(lat+2))==-1)
		{
		    	alert("Please enter your correct email address.");
			 emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(" ")!=-1)
		{
		    	alert("Please enter your correct email address.");
	         	emailid = "";
		    	
			return false;
		}
		return true;
	}
}

function agentpayment()
{
	
	var form = document.paymentformnew;
	
		var adult=(form.adult.value);
	//alert (adult);
	if(adult>1)
	{
		for(i=0;i<adult;i++)
		{
			var fname=trim(form["Firstname[]"][i].value);
			
			if(fname=='')
			{	
				alert("Please enter the first name of the passenger in row " + (i+1)+".");
				form["Firstname[]"][i].focus();
			    return false;
			}
           	else
	    	{	
				count=fname.length;
				if (count <= 1)
				{	
					alert("Sorry, first name should have more than one character.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				else if (count > 50)
				{	
					alert("Sorry, currently we do not accept more than 50 characters for the first name.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				
		     }
			var lname=trim(form["Lastname[]"][i].value);
			if(lname=='')
			{	alert("Please enter the lastname of the passenger in row " +(i+1)+".");
				form["Lastname[]"][i].focus();
				return false;
			}
			var passmob=trim(form["passmobile[]"][i].value);
			if(passmob == '')
			{
				alert("Please enter the mobile number of the passenger in row " +(i+1)+".");
				form["passmobile[]"][i].focus();
				return false;
			}
			if(passmob.length < 10 || passmob.length >12)
			{
				alert("Please provide a valid mobile number with 10 numeric characters of passenger in row"+(i+1)+".");
				form["passmobile[]"][i].focus();
				return false; 
			}
			var passland=trim(form["passland[]"][i].value);
			if(passland == '')
			{
				alert("Please enter the land line number of the passenger in row " +(i+1)+".");
				form["passland[]"][i].focus();
				return false;
			}
			if(passland.length < 6 || passland.length >12)
			{
				alert("Please provide a valid land line number of the passenger in row " +(i+1)+".");
				form["passland[]"][i].focus();
	 			return false; 
			}
			var passmail=trim(form["passmail[]"][i].value);
			if(passmail == '')
			{
				alert("Please enter the Email ID of the passenger in row " +(i+1)+".");
				form["passmail[]"][i].focus();
				return false;
			}		
			else if(emailval(passmail)==false)
			{
				alert("Please enter the correct Email ID of the passenger in row " +(i+1)+".");
				form["passmail[]"][i].focus();
	 			return false; 
			}

		}
	}
	if(adult==1)
	{
		fname=trim(form["Firstname[]"].value);
		
		if(fname=='')
		{
	 		alert("Please enter the first name of the passenger.");
			form["Firstname[]"].focus();
			return false;
		}
		else
		{
			count=fname.length;
			if (count <= 1)
			{
				alert("First name should have more than one character, try again.");
				form["Firstname[]"].focus();
                return (false);
			}
			else if (count > 50)
			{	
				alert("Sorry, currently we do not accept more than 50 characters for the first name.");
				form["Firstname[]"].focus();
				return (false);
			}
		}
		lname=trim(form["Lastname[]"].value);
		if(lname=='')
		{
  			alert("Please enter the last name of the passenger.");
			form["Lastname[]"].focus();
	 		return false; 
		}
		passmob=trim(form["passmobile[]"].value);
		if(passmob=='')
		{
  			alert("Please enter the mobile number of the passenger.");
			form["passmobile[]"].focus();
	 		return false; 
		}
		 if(passmob.length < 10 || passmob.length >12)
		{
			alert("Please provide a valid mobile number with 10 numeric characters.");
			form["passmobile[]"].focus();
	 		return false; 
		}
		passland=trim(form["passland[]"].value);
		if(passland=='')
		{
  			alert("Please enter the land line number of the passenger.");
			form["passland[]"].focus();
	 		return false; 
		}
		if(passland.length < 6 || passland.length >12)
		{
			alert("Please provide a valid land line number.");
			form["passland[]"].focus();
	 		return false; 
		}
		passemail=trim(form["passmail[]"].value);
		if(passemail=='')
		{
  			alert("Please enter the Email ID of the passenger.");
			form["passmail[]"].focus();
	 		return false; 
		}
		else if(emailvalpass(passemail)==false)
		{
			alert("Please enter the valid Email ID of the passenger.");
			form["passmail[]"].focus();
	 		return false; 
		}
	} 


	
	if(strim(document.getElementById("transactionpwd").value).length == 0)
	{
		alert("Please enter your transaction password.");
		exit();
	}
	xajax_agentbooking(xajax.getFormValues("paymentformnew"));
}

function submitsmsmessage()
{
		//alert('submitsmsmessage')
		var smsmobile=document.getElementById("SMSmobileno").value;
		var smsemail=document.getElementById("SMSemailid").value;
		var smsname=document.getElementById("SMSfrndname").value;
		
		if(trim(smsmobile).length <=0 && trim(smsemail).length <=0)
		{
			alertmessage("Please enter either your mobile number or email address","news2");
			//alert("Please enter either mobile number or email id");
			return false;
		}
		
		if(trim(smsmobile).length>0)
		{
			if(trim(smsmobile).length < 10 || trim(smsmobile).length >12)
			{
				alertmessage("Sorry, you have not provided the mobile number.","news2");
				//alert("Sorry, you have provided incorrect mobile number");
				document.SMSformvalue.SMSmobileno.focus();
				document.SMSformvalue.SMSmobileno.value="";
				return false;
			}
		}
		if(trim(smsemail).length>0)
		{
			if(checksms(smsemail)==false)
			{
				document.SMSformvalue.SMSemailid.value=''
				document.SMSformvalue.SMSemailid.focus();
				return false;
			}
		}
		if(trim(smsname).length<=0)
		{
			alertmessage("Please enter the name of your friend.","news2");
			//alert("Please enter your friends name");
			document.SMSformvalue.SMSfrndname.focus();
			return false;
		}
		xajax_SMSforfriends(xajax.getFormValues("SMSformvalue"));
}


function checksms(emailid)
{
	
	//var emailid=document.getElementById("emailid").value;
	//alert(emailid);
	var at="@";
	var dot=".";
	var lat=emailid.indexOf(at);
	var lemailid=emailid.length;
	var ldot=emailid.indexOf(dot);

		if (lat==-1 || lat==0 || lat==lemailid)
		{
		   	alertmessage("Invalid email address.","news2");
			//alert("Invalid E-mail ID");
		   	emailid = "";
		   	
		   	return false;
		}
		if (ldot==-1 || ldot==0 || ldot==lemailid)
		{
		    alertmessage("Invalid email address.","news2");
			//alert("Invalid E-mail ID")
			 emailid = "";
		   	 
		    	return false;
		}
		if (emailid.indexOf(at,(lat+1))!=-1)
		{
		   	alertmessage("Invalid email address.","news2");
			//alert("Invalid E-mail ID")
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.substring(lat-1,lat)==dot || emailid.substring(lat+1,lat+2)==dot)
		{
		    	alertmessage("Invalid email address.","news2");
				//alert("Invalid E-mail ID")
				emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(dot,(lat+2))==-1)
		{
		    	alertmessage("Invalid email address.","news2");
				//alert("Invalid E-mail ID")
			 emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(" ")!=-1)
		{
		    	alertmessage("Invalid email address.","news2");
				//alert("Invalid E-mail ID")
	         	emailid = "";
		    	
			return false;
		}
		return true;
}

function alertsuccess(content,div)
{
	//alert(div);
	dwAText ='';
	contentmsg='';
	document.getElementById('SMSalerts').className = "show";
	document.getElementById('SMSsuccessfull').className = "show";
	document.getElementById('divpayment').className = "hide";
	document.getElementById('divpass').className = "hide";
	document.getElementById('SMSmobileno').value='';
	document.getElementById('SMSemailid').value='';
	document.getElementById('SMSfrndname').value='';
	//document.getElementById('contentval').value = content;
	//alert(content);
	clearTimeout(timeout);
	doNews(content,div);
}
function alertmessage(content,div)
{
	//alert(div);
	dwAText ='';
	contentmsg='';
	document.getElementById('SMSalerts').className = "show";
	document.getElementById('SMSalertsub').className = "show";
	document.getElementById('divpayment').className = "hide";
	document.getElementById('divpass').className = "hide";
	//document.getElementById('contentval').value = content;
	//alert(content);
	clearTimeout(timeout);
	doNews(content,div);
	
}
//Typing Text (DHTML) v1 (Sunday, April 15th, 2001)
//Programmed by: Haitham M. Al-Beik
//Email: albeik99@netzero.net
var timeadd;
var ttloop = 1;    // Repeat forever? (1 = True; 0 = False)
var tspeed;   // Typing speed in milliseconds (larger number = slower)
var tdelay; // Time delay between newsTexts in milliseconds<br>// ------------- NO EDITING AFTER THIS LINE ------------- \\
var dwAText, cnews=0, eline=0, cchar=0, mxText;
var newsText = '';
var contentmsg;
var divname ;
function doNews(contentinfo,div) 
{
	//alert(contentinfo);
	cchar = 0;
	tdelay = 1000;
	tspeed = 100;
	ttloop = 1;
	contentmsg = contentinfo;
	newsText = contentinfo;
	mxText = newsText.length - 1;
  	dwAText = newsText;
	divname = div;
  	timeout=setTimeout("addChar()",500)
}
function addNews() 
{
  	cnews += 1;
  	if (cnews <= mxText) {
    	dwAText = newsText[cnews];
    if (dwAText.length != 0) 
	{
      //document.news.news2.value = "";
	  document.getElementById(divname).innerHTML = "";
      eline = 0;
      timeout=setTimeout("addChar()",1000)
    }
  }
}
function addChar() 
{
  dwAText = contentmsg;
  //alert(dwAText);
  if (eline!=1) 
  {
    if (cchar != dwAText.length) 
	{
      	nmttxt = ""; 
	  	for (var k=0; k<=cchar;k++) 
	  		nmttxt += dwAText.charAt(k);
      	//document.news.news2.value = nmttxt;
		document.getElementById(divname).innerHTML = nmttxt;
      	cchar += 1;
      	if (cchar != dwAText.length) 
			document.getElementById(divname).innerHTML += "|";
			//document.news.news2.value += "_";
    } 
	
    if (mxText==cnews && eline!=0 && ttloop!=0) 
	{
      cnews = 0; 
	  document.getElementById(divname).innerHTML = "";
	  //document.news.news2.value = "";
	  timeout=setTimeout("addChar()",tspeed);
	  //setTimeout("addNews()",tdelay);
    }
	else
	{
		timeout=setTimeout("addChar()",tspeed);
	}
  } 
  else 
  {
	 // document.news.news2.value = "";
	 document.getElementById(divname).innerHTML = "";
	 timeout= setTimeout("addChar()",tspeed);
   // setTimeout("addNews()",tdelay)
  }
}
function removedata()
{
	//document.getElementById("news2").value='';
	document.getElementById(divname).innerHTML = "";
}

function changecvv(divcvv)
{
	if(divcvv == 'amex')
	{
		document.getElementById("cvvno").innerHTML = "<strong>4DBC</strong><font color='#FF0000'>*</font>";
		document.getElementById("payimage").innerHTML = "<img src='images/amex77.jpg'>";
		document.getElementById("div4dbc").innerHTML = "<img src='images/4DBC.gif'>";
		document.getElementById("amexFirstname").value = "";
		document.getElementById("amexMiddlename").value = "";
		document.getElementById("amexLastname").value = "";
		document.getElementById("creditcardvalue").className ="show";
		document.getElementById("cvvinput").className = "show";
		document.getElementById("cardholdername").className = "show";
		document.getElementById("visacardholderHdr").className = "hide";
		document.getElementById("visacardholderVal").className = "hide";
		document.getElementById("phonenum").className = "hide";
	}
	else if(divcvv == 'visa' || divcvv == 'mstr')
	{
		document.getElementById("phonenum").className = "hide";
		document.getElementById("cvvno").innerHTML = "<strong>CVV No</strong><font color='#FF0000'>*</font>";
		document.getElementById("cvvinput").className = "show";
		document.getElementById("payimage").innerHTML = "<img src='images/payseal.gif'>";
		document.getElementById("div4dbc").innerHTML = "";
		document.getElementById("Cardholder").value = "";
		document.getElementById("creditcardvalue").className ="show";
		document.getElementById("cardholdername").className = "hide";
		document.getElementById("visacardholderHdr").className = "show";
		document.getElementById("visacardholderVal").className = "show";
		document.getElementById("phonenum").className = "hide";
	}
	else if(divcvv == 'PM')
	{
			document.getElementById("creditcardvalue").className ="hide";
			document.getElementById("payimage").innerHTML = "<img src='images/paymate.gif'>";
			document.getElementById("div4dbc").innerHTML = "";
			document.getElementById("cardholdername").className = "hide";
			document.getElementById("phonenum").className = "show";
	}
	else if(divcvv == 'IH')
	{
			document.getElementById("creditcardvalue").className ="hide";
			document.getElementById("payimage").innerHTML = "<img src='images/itzcash.gif'>";
			document.getElementById("div4dbc").innerHTML = "";
			document.getElementById("cardholdername").className = "hide";
			document.getElementById("phonenum").className = "hide";
	}
}

function selecttimeonward(selectdate,proid,onwstime,onwetime,value)
{
	document.getElementById('onwardproductid').value = proid;
	if(value == 0)
	{
		document.selectflight.selecttime.checked = true;
	}
	else
	{
		if(document.selectflight.selecttime[value].checked != true)
		{
			document.selectflight.selecttime[value].checked = true;
		}
	}
}

function selecttimereturn(onwdate,retdate,onwproid,retproid,onwstime,onwetime,retstime,retetime,value)
{
	document.getElementById('returnproductid').value = retproid;
	document.getElementById('onwardproductid').value = onwproid;
	if(value == 0)
	{
		document.selectflight.retselecttime.checked = true;
	}
	else
	{
		if(document.selectflight.retselecttime[value].checked != true)
		{
			document.selectflight.retselecttime[value].checked = true;
		}
	}
}

function bookingflight(type)
{
	radval = document.getElementById("radiobuttonvalue").value;
	request  = document.getElementById('selectrequest').value;
	onwpro = document.getElementById('onwardproductid').value;
	retpro = document.getElementById('returnproductid').value;
	onwardselect=0;
	returnselect=0;
	//alert('bookingflight '+radval+"  type  "+type+"  request id "+request+" onward  "+onwpro+ " return "+retpro);
	if(type == "oneway")
	{
		if(radval == 1)
		{
			if(document.selectflight.selecttime.checked == true)
				{
					//prod = document.selectflight.selecttime[i].value;
					onwardselect=1;
				}
		}
		else
		{
			for(i=0;i<radval;i++)
			{
				if(document.selectflight.selecttime[i].checked == true)
				{
					//prod = document.selectflight.selecttime[i].value;
					onwardselect=1;
				}
			}
		}
		if(onwardselect>0)
		{
			xajax_bookingairline(request,onwpro);
		}
		else
		{
			alert('Please select onward flight.');
			return false;
		}
	}
	else
	{
		retpro = document.getElementById('returnproductid').value;
		if(radval == 1)
		{
			if(document.selectflight.retselecttime.checked == true)
			{
				returnselect=1;
			}
		}
		else
		{
			for(i=0;i<radval;i++)
			{
				if(document.selectflight.retselecttime[i].checked == true)
				{
					returnselect=1;
					//prod = document.selectflight.selecttime[i].value;
					//alert(prod);
					//return true;
				}
			}
		}
		if(returnselect>0)
		{
			xajax_bookingairline(request,onwpro,retpro);
		}
		else
		{
			alert('Please select return flight.');
			return false;
		}
	}
}

function airlinesearchxajax()
{
	alert('payment airlinesearchxajax')
	document.getElementById('iframediv').className = "show";
	document.getElementById('xajaxsearchairlinediv').className = "show";
	
	Sorigin=document.getElementById("Origin").value;
	Sdest=document.getElementById("Dest").value;
	Sonwarddate=document.getElementById("StartDate").value;
	Oadult = document.getElementById("Adult").value;
	for (var i=0; i < document.Mainform.trip.length; i++)
	{
		if (document.Mainform.trip[i].checked)
		{
			trip_val = document.Mainform.trip[i].value;
		}
    }
	xajaxairlinecall(Sorigin,Sdest,Sonwarddate,Oadult,"home");
	if(trip_val == 2)
	{
		Sretdate=document.getElementById("returnsdate").value;
		returnxajaxairlinecall(Sdest,Sorigin,Sretdate,Oadult,"home");
	}
}

function xajaxairlinecall(Sorigin,Sdest,Sonwarddate,adult,type)	
{
	
	xajax_xajaxindigo(Sorigin,Sdest,Sonwarddate,adult,type);
	xajax_xajaxspice(Sorigin,Sdest,Sonwarddate,adult);
	xajax_xajaxdeccan(Sorigin,Sdest,Sonwarddate,adult);
	xajax_xajaxjet(Sorigin,Sdest,Sonwarddate,adult);
	xajax_xajaxgoair(Sorigin,Sdest,Sonwarddate,adult);
	xajax_xajaxparamount(Sorigin,Sdest,Sonwarddate,adult);
	//xajax_xajaxkingfisher(Sorigin,Sdest,Sonwarddate,adult);
	xajax_xajaxjetlite(Sorigin,Sdest,Sonwarddate,adult);
}

function returnxajaxairlinecall(Srorigin,Srdest,Sretdate,radult,type)	
{
	xajax_returnxajaxindigo(Srorigin,Srdest,Sretdate,radult,type);
	//xajax_returnxajaxspice(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxdeccan(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxjet(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxgoair(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxparamount(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxkingfisher(Srorigin,Srdest,Sretdate,radult);
	//xajax_returnxajaxjetlite(Srorigin,Srdest,Sretdate,radult);
}


function travelpayment()
{
	
   	var baddrone=document.paymentformnew.Baddress1.value;
   	var baddrtwo=document.paymentformnew.Baddress2.value;
   	//var baddrthree=document.paymentformnew.Baddress3.value;	  	
   	var bcity=document.paymentformnew.Bcity.value;
   	var bstate=document.paymentformnew.Bstate.value;
	var bcountry=document.paymentformnew.Bcountry.value;
    var bphone=document.paymentformnew.Bphoneno.value;
    var bpincode=document.paymentformnew.Bpincode.value;
	var bmobile=document.paymentformnew.Bmobileno.value;
   	//var bareacode=document.paymentformnew.Bareacode.value;
    var bemail=document.paymentformnew.Bemailid.value;
	var cardshow=document.paymentformnew.carddisp.value;
	
	
	baddrone=trim(baddrone);
	baddrtwo=trim(baddrtwo);
	//baddrthree=trim(baddrthree);
	bcity=trim(bcity);
	bemail=trim(bemail);
	cardtype = getradiovalue();
	var form = document.paymentformnew;
	
	var adult=(form.adult.value);
	//alert (adult);
	if(adult>1)
	{
		for(i=0;i<adult;i++)
		{
			var fname=trim(form["Firstname[]"][i].value);
			
			if(fname=='')
			{	
				alert("Please enter the first name of the passenger in row " + (i+1)+".");
				form["Firstname[]"][i].focus();
			    return false;
			}
           	else
	    	{	
				count=fname.length;
				if (count <= 1)
				{	
					alert("Sorry, first name should have more than one character.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				else if (count > 50)
				{	
					alert("Sorry, currently we do not accept more than 50 characters for the first name.");
					form["Firstname[]"][i].focus();
                      return (false);
				}
				
		     }
			var lname=trim(form["Lastname[]"][i].value);
			if(lname=='')
			{	
				alert("Please enter the last name of the passenger in row " +(i+1)+".");
				form["Lastname[]"][i].focus();
				return false;
			}
			var passmob=trim(form["passmobile[]"][i].value);
			if(passmob == '')
			{
				alert("Please enter the mobile number of the passenger in row " +(i+1)+".");
				form["passmobile[]"][i].focus();
				return false;
			}
			if(passmob.length < 10 || passmob.length >12)
			{
				alert("Please provide a valid mobile number with 10 numeric characters of passenger in row"+(i+1)+".");
				form["passmobile[]"][i].focus();
				return false; 
			}
			var passland=trim(form["passland[]"][i].value);
			if(passland == '')
			{
				alert("Please enter the land line number of the passenger in row " +(i+1)+".");
				form["passland[]"][i].focus();
				return false;
			}
			if(passland.length < 6 || passland.length >12)
			{
				alert("Please provide a valid land line number of the passenger in row " +(i+1)+".");
				form["passland[]"][i].focus();
	 			return false; 
			}
			var passmail=trim(form["passmail[]"][i].value);
			if(passmail == '')
			{
				alert("Please enter the Email ID of the passenger in row " +(i+1)+".");
				form["passmail[]"][i].focus();
				return false;
			}		
			else if(emailval(passemail)==false)
			{
				alert("Please enter the correct Email ID of the passenger in row " +(i+1)+".");
				form["passmail[]"][i].focus();
	 			return false; 
			}
		}
	}
	if(adult==1)
	{
		fname=trim(form["Firstname[]"].value);
		
		if(fname=='')
		{
	 		alert("Please enter the first name of the passenger.");
			form["Firstname[]"].focus();
			return false;
		}
		else
		{
			count=fname.length;
			if (count <= 1)
			{
				alert("First name should have more than one character, try again.");
				form["Firstname[]"].focus();
                return (false);
			}
			else if (count > 50)
			{	
				alert("Sorry, currently we do not accept more than 50 characters for the first name.");
				form["Firstname[]"].focus();
				return (false);
			}
		}
		lname=trim(form["Lastname[]"].value);
		if(lname=='')
		{
  			alert("Please enter the last name of the passenger.");
			form["Lastname[]"].focus();
	 		return false; 
		}
		
		passmob=trim(form["passmobile[]"].value);
		if(passmob=='')
		{
  			alert("Please enter the mobile number of the passenger.");
			form["passmobile[]"].focus();
	 		return false; 
		}
		 if(passmob.length < 10 || passmob.length >12)
		{
			alert("Please provide a valid mobile number with 10 numeric characters.");
			form["passmobile[]"].focus();
	 		return false; 
		}
		passland=trim(form["passland[]"].value);
		if(passland=='')
		{
  			alert("Please enter the land line number of the passenger.");
			form["passland[]"].focus();
	 		return false; 
		}
		if(passland.length < 6 || passland.length >12)
		{
			alert("Please provide a valid land line number.");
			form["passland[]"].focus();
	 		return false; 
		}
		passemail=trim(form["passmail[]"].value);
		if(passemail=='')
		{
  			alert("Please enter the Email ID of the passenger.");
			form["passmail[]"].focus();
	 		return false; 
		}
		else if(emailvalpass(passemail)==false)
		{
			alert("Please enter the valid Email ID of the passenger.");
			form["passmail[]"].focus();
	 		return false; 
		}
	} 

	if(baddrone=='')
	{
 		alert("Please enter the address 1 field.");
		document.paymentformnew.Baddress1.focus();
 		return false;
 	}
	else if (baddrone.length > 50) 
	{	
 		alert("Sorry, currently we do not accept more than 50 characters for address 1 field.");
		document.paymentformnew.Baddress1.value='';
		document.paymentformnew.Baddress1.focus();
 		return false;	
	}
	
	if(baddrtwo=='')
	{
 		alert("Please enter the address 2 field.");
		document.paymentformnew.Baddress2.focus();
 		return false;
 	}
	else if (baddrtwo.length > 50)
	{
		alert("Address 2 field length should be less than 51 characters.");
		document.paymentformnew.Baddress2.value='';
		document.paymentformnew.Baddress2.focus();
		return false;				
	}
	
	if(bcity=='')
	{
		alert("Please enter the city of the billing address.");
		document.paymentformnew.Bcity.focus();
		return false;
	}
	else if(bcity.length >30 )
	{
		alert("Please enter a valid city name with fewer characters.");
		document.paymentformnew.Bcity.focus();
		document.paymentformnew.Bcity.value='';
		return false;
	}
	
	if(bstate=='')
	{
		alert("Please enter the state of the billing address.");
		document.paymentformnew.Bstate.focus();
	 	return false;
 	}
	else if(bstate.length >30 )
	{
			 alert("Please enter a valid state name with fewer characters.");
			   document.paymentformnew.Bstate.value='';
				document.paymentformnew.Bstate.focus();
			
			return false;
	}
	
	if(bcountry=='')
	{
		alert("Please enter the country of the billing address.");
		document.paymentformnew.Bcountry.focus();
 		return false;
	}
	else if(bcountry.length >30 )
	{
			alert("Please enter a valid country name with fewer characters.");
			document.paymentformnew.Bcountry.focus();
			document.paymentformnew.Bcountry.value='';
			return false;
	}
	
	if(bpincode=='')
	{
		alert("Please enter the pincode of the billing address.");
		document.paymentformnew.Bpincode.focus();
		return false;
	}
	else if(bpincode.length > 9)
	{
		alert("Please enter a valid pincode with fewer characters.");
		document.paymentformnew.Bpincode.focus();
		document.paymentformnew.Bpincode.value='';
		return false;
	}
	
	if(bmobile=='')
	{
		alert("Please enter the mobile number.");
		document.paymentformnew.Bmobileno.focus();
		return false;
	}
	else if(bmobile.length < 10 || bmobile.length >12)
	{
		alert("Please provide a valid mobile number with 10 numeric characters.");
		document.paymentformnew.Bmobileno.focus();
		document.paymentformnew.Bmobileno.value="";
		
		return false;
	}
	
	if(bphone=='')
	{
		alert("Please enter the land line phone number with the STD code.");
		document.paymentformnew.Bphoneno.focus();
		return false;
	}
	else if ( (bphone.length > 12) || (bphone.length < 6) )
	{
		alert("Please enter a valid land line phone number with the STD code.");
		document.paymentformnew.Bphoneno.focus();
		document.paymentformnew.Bphoneno.value="";
		return false;
	}
	
	if(bemail=='')
	{
 		alert("Please enter the e-mail address.");
		document.paymentformnew.Bemailid.focus();
 		return false;
	}
	else if(emailval(document.paymentformnew.Bemailid.value)==false)
	{
		document.paymentformnew.Bemailid.value=''
		document.paymentformnew.Bemailid.focus();
		return false;
	}
	if(cardshow == 'show' && cardtype != 'PM' && cardtype != 'IH')
	{
		
		if(document.getElementById('Cardno1').value == '')
		{
			alert("Please enter the first four digits of the credit card.");
			document.getElementById('Cardno1').focus();
			return false;
		}
		else if(document.getElementById('Cardno1').value.length < 4)
		{
			alert("Please enter the correct first four digits of the credit card.");
			document.getElementById('Cardno1').focus();
			return false;
		}
		
		if(document.getElementById('Cardno2').value == '')
		{
			alert("Please enter the second four digits of the credit card.");
			document.getElementById('Cardno2').focus();
			return false;
		}
		else if(document.getElementById('Cardno2').value.length < 4)
		{
			alert("Please enter the correct second four digits of the credit card.");
			document.getElementById('Cardno2').focus();
			return false;
		}
		
		if(document.getElementById('Cardno3').value == '')
		{
			alert("Please enter the third four digits of the credit card.");
			document.getElementById('Cardno3').focus();
			return false;
		}
		else if(document.getElementById('Cardno3').value.length < 4)
		{
			alert("Please enter the correct third four digits of the credit card.");
			document.getElementById('Cardno3').focus();
			return false;
		}
		
		
		rad_val = getradiovalue();
		if(rad_val == 'AMEX')
		{
			if(document.getElementById('Cardno4').value == '')
			{
				alert("Please enter the last three digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
			else if(document.getElementById('Cardno4').value.length < 3)
			{
				alert("Please enter the correct last three digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
		}
		else if(rad_val == 'VISA' || rad_val == 'MC')
		{
			if(document.getElementById('Cardno4').value == '')
			{
				alert("Please enter the last four digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
			else if(document.getElementById('Cardno4').value.length < 4)
			{
				alert("Please enter the correct last four digits of the credit card.");
				document.getElementById('Cardno4').focus();
				return false;
			}
		}
		
		if(document.getElementById('Expmonth').value == '')
		{
			alert("Please select the expiry month of the card.");
			document.getElementById('Expmonth').focus();
			return false;
		}
		
		if(document.getElementById('Expyear').value == '')
		{
			alert("Please select the expiry year of the card.");
			document.getElementById('Expyear').focus();
			return false;
		}
		if(document.getElementById('Cvv').value == '')
        {
                alert("Please enter the CVV number of the card.");
                document.getElementById('Cvv').focus();
                return false;
        }		
	
		if(rad_val == 'VISA' || rad_val == 'MC')
		{
			if(document.getElementById('Cardholder').value == '')
			{
				alert("Please enter the name of the card holder.");
				document.getElementById('Cardholder').focus();
				return false;
			}
		}
		else if(rad_val == 'AMEX')
		{
			if(document.getElementById('Cvv').value == '')
				{
						alert("Please enter the CVV number of the card.");
						document.getElementById('Cvv').focus();
						return false;
				}
	
			if(document.getElementById('amexFirstname').value == '')
			{
				alert("Please enter the first name of the card holder.");
				document.getElementById('amexFirstname').focus();
				return false;
			}
			if(document.getElementById('amexMiddlename').value == '')
			{
				alert("Please enter the middle name of the card holder.");
				document.getElementById('amexMiddlename').focus();
				return false;
			}
	
			if(document.getElementById('amexLastname').value == '')
			{
				alert("Please enter the last name of the card holder.");
				document.getElementById('amexLastname').focus();
				return false;
			}
	
		}
	}
	xajax_travelpaymentdetails(xajax.getFormValues("paymentformnew"));
}
function emailvalpass(emailid)
{
	
	//var emailid=document.getElementById("emailid").value;
	//alert(emailid);
	var at="@";
	var dot=".";
	var lat=emailid.indexOf(at);
	var lemailid=emailid.length;
	var ldot=emailid.indexOf(dot);
	
	if(emailid.length > 0) 
	{

		if (lat==-1 || lat==0 || lat==lemailid)
		{
		   	emailid = "";
		   	
		   	return false;
		}
		if (ldot==-1 || ldot==0 || ldot==lemailid)
		{
				emailid = "";
		    	return false;
		}
		if (emailid.indexOf(at,(lat+1))!=-1)
		{
				emailid = "";
		    	return false;
		}

		if (emailid.substring(lat-1,lat)==dot || emailid.substring(lat+1,lat+2)==dot)
		{
				emailid = "";
		    	return false;
		}

		if (emailid.indexOf(dot,(lat+2))==-1)
		{
				emailid = "";
		    	return false;
		}

		if (emailid.indexOf(" ")!=-1)
		{
	         emailid = "";
			return false;
		}
		return true;
	}
}