function promastercreation()
{
	xajax_procouponmastercreation();
}
function insertpromaster(check)
{
	if(document.getElementById("txtprocouponmaster").value=="")
	{
		alert("Enter the Coupon Master Name");
		document.getElementById("txtprocouponmaster").focus();
		
	}
	else
	{
		if(document.frmprocouponmaster.cmdoffertype.value=="Submit")
		{
			xajax_procouponmastercreation(xajax.getFormValues('frmprocouponmaster'),check);
		}
		else
		{
			xajax_procouponmastercreation(xajax.getFormValues('frmprocouponmaster'),'');
		}
	}
	
	
}
function editoffer(couponmasterid,mastercouponname)
{

	document.getElementById("couponmasterid").value=couponmasterid;
	document.getElementById("txtprocouponmaster").value=mastercouponname;
	document.getElementById("updatedata").className="show";
	document.getElementById("deletedata").className="show";
	document.frmprocouponmaster.cmdoffertype.value="Add New";
}
function updatepromaster(check)
{
	xajax_procouponmastercreation(xajax.getFormValues('frmprocouponmaster'),check);
}
function deletepromaster(check)
{
	xajax_procouponmastercreation(xajax.getFormValues('frmprocouponmaster'),check);
}
function procouponcreation()
{
	xajax_procouponcreation();
}
function show()
{
	if(document.getElementById("chksector").checked)
	{
	 	document.getElementById("sectordetails").className="show";
		document.getElementById("chksectoravail").value='Y';
	}
	else
	{
		document.getElementById("sectordetails").className="hide";
		document.getElementById("chksectoravail").value='N';
	}
}
function insertprocoupon(check)
{
	mastercoupon=document.getElementById("cmbcouponname").value;
	procoupon=document.getElementById("txtprocouponname").value;
	numberofcoupons=document.getElementById("txtnumberofcoupons").value;
	couponamount=document.getElementById("txtcouponamount").value;
	airlinename=document.getElementById("airlinename").value;
	
	if(mastercoupon==0)
	{
		alert('Please select the master coupon');
	}
	else if(procoupon=="")
	{
		alert('please Enter the promo coupon name');
		document.getElementById("txtprocouponname").focus();
	}
	else if(numberofcoupons=="")
	{
		alert('please Enter the total number of coupons');
		document.getElementById("txtnumberofcoupons").focus();
	}
	else if(airlinename=="")
	{
		alert('please select any airline');
		document.getElementById("txtnumberofcoupons").focus();
	}
	else if(couponamount=="")
	{
		alert('please Enter the coupon Amount');
		document.getElementById("txtcouponamount").focus();
	}
	else
	{
		xajax_procouponcreation(xajax.getFormValues('frmprocoupon'),check);
	}
}
function tax()
{
	if(document.getElementById("chktax").checked)
	{	
		document.getElementById("taxstatus").value='Y';
	}
	else
	{
		document.getElementById("taxstatus").value='N';

	}
}
function procouponissue()
{
	xajax_procouponissuedetails();
}
function procouponuserdetails()
{
	xajax_procouponuserdetails();
}
function procouponuserinsert(check)
{
	if(document.getElementById("cmdaddnew").value=="Save")
	{
		
		if(document.getElementById("txtorganaizationname").value=="")
		{
			
			alert("please Enter the  Organaization Name");
			document.getElementById("txtorganaizationname").focus();
			return false;
		}
		else if(document.getElementById("txtusername").value=="")
		{
			
			alert("please Enter the  user Name");
			document.getElementById("txtusername").focus();
			return false;
		}
		else if(document.getElementById("txtaddress1").value=="")
		{
			alert("please Enter the  Address-1");
			document.getElementById("txtaddress1").focus();
			return false;
		}
		else if(document.getElementById("txtaddress2").value=="")
		{
			alert("please Enter the  Address-2");
			document.getElementById("txtaddress2").focus();
			return false;
		}
		else if(document.getElementById("txtcity").value=="")
		{
			alert("please Enter the  City");
			document.getElementById("txtcity").focus();
			return false;
		}
		else if(document.getElementById("txtstate").value=="")
		{
			alert("please Enter the State");
			document.getElementById("txtstate").focus();
			return false;
		}		
		else if(document.getElementById("txtcountry").value=="")
		{
			alert("please Enter the  Country");
			document.getElementById("txtcountry").focus();
			return false;
		}
		else if(document.getElementById("txtpincode").value=="")
		{
			alert("please Enter the  pincode");
			document.getElementById("txtpincode").focus();
			return false;
		
		}
		else if(document.getElementById("txtmobileno").value=="")
		{
			alert("please Enter the  Mobile Number");
			document.getElementById("txtmobileno").focus();
			return false;
		}
		else if(document.getElementById("txtphoneno").value=="")
		{
			alert("please Enter the  Pohne");
			document.getElementById("txtphoneno").focus();
			return false;
		}
		else if(document.getElementById("txtemailid").value=="")
		{
			alert("please Enter the  email ");
			document.getElementById("txtemailid").focus();
			return false;
		}
		else
		{
			xajax_procouponuserdetails(xajax.getFormValues('frmcouponuser'),check);
		}
	}
	else
	{
		xajax_procouponuserdetails(xajax.getFormValues('frmcouponuser'),'');
	}
}
function procouponuserupdate(check)
{
	xajax_procouponuserdetails(xajax.getFormValues('frmcouponuser'),check);
}
function procouponuserdelete(check)
{
	xajax_procouponuserdetails(xajax.getFormValues('frmcouponuser'),check);
}
function editcouponuser(procouponuserid,procouponusername,organizationname,address1,address2,city,state,country,pincode,mobileno,phone,email)
{
	
	document.getElementById("procouponuserid").value=procouponuserid;
	document.getElementById("txtusername").value=procouponusername;
	document.getElementById("txtorganaizationname").value=organizationname;
	document.getElementById("txtaddress1").value=address1;
	document.getElementById("txtaddress2").value=address2;
	document.getElementById("txtcity").value=city;
	document.getElementById("txtstate").value=state;
	document.getElementById("txtcountry").value=country;
	document.getElementById("txtpincode").value=pincode;
	document.getElementById("txtmobileno").value=mobileno;
	document.getElementById("txtphoneno").value=phone;
	document.getElementById("txtemailid").value=email;
	document.getElementById("btnupdate").className="show";
	document.getElementById("btndelete").className="show";
	document.getElementById("cmdaddnew").value = "AddNew"
	
}
function loadcoupons(masterid)
{
	xajax_getallprocoupons(masterid);
}
function loadcouponsdetails(couponnames)
{
	 		var arraylen=couponnames.length;
			var cmbcoupons=document.getElementById('cmbprocouponname');
			var len=cmbcoupons.length;
			
			for(var j=0;j<len;j++)
			{
				cmbcoupons.remove(0);
			}
			
			if(arraylen > 0)
			{
				for(i=0;i<arraylen;i++)
				{
					cmbcoupons.options[0] = new Option("Select Coupons","Select Coupons");
					cmbcoupons.options[i+1] = new Option(couponnames[i],couponnames[i]);					 
					
				}
			}
}
function availcoups(couponname)
{
			var cmbcoupons=document.getElementById('cmbprocouponname');
			var len=cmbcoupons.length;
			xajax_getallremainscoupons(couponname);
		
		
}
function loadavailablecoupons(totalcoupons,startcouponid,endcouponid)
{
		
		document.getElementById("txttotalcoupon").value=totalcoupons;
		document.getElementById("txtsnofrom").value=startcouponid;
		document.getElementById("txtsnoto").value=endcouponid;	
		
}
function couponissue(check)
{
		procouponmaster=document.getElementById("cmbcouponmaster").value;
		procoupons=document.getElementById("cmbprocouponname").value;			
		procouponusername=document.getElementById("cmbcouponuser").value;	
		totalcoupon=document.getElementById("txtissueno").value;	
		totalavailcoupon=document.getElementById("txttotalcoupon").value;	
		
		if(procouponmaster==0)
		{
			alert('Please Select Master Coupon Name');
			document.getElementById("cmbcouponmaster").focus();
		}
		else if(procoupons=="Select Coupons")
		{
			alert('Please Select Coupon Name');
			document.getElementById("cmbprocouponname").focus();
		}
		else if(procouponusername==0)
		{
			alert('Please Enter User Name');
			document.getElementById("cmbcouponuser").focus();
		}
		else if(totalcoupon==0)
		{
			alert('Please Enter No.Of coupons');
			document.getElementById("txtissueno").focus();
		}
		else if( Number(totalcoupon) > Number(totalavailcoupon) )
		{
		    //alert( parseInt(totalcoupon));
			alert('No.of Coupon not available please renter your another number');
			document.getElementById("txtissueno").value="";
			document.getElementById("txtissueno").focus();			
		}
		else
		{
			alert('coupon issue');
			xajax_procouponissuedetails(xajax.getFormValues('frmprocouponissue'),check);
		}
		
}
function procouponmonitor(check)
{
	xajax_procouponmonitor(xajax.getFormValues('frmprocouponmonitor'),'');
}
function couponmonitor(check)
{
	procouponmaster=document.getElementById("cmbcouponmaster").value;
	procoupons=document.getElementById("cmbprocouponname").value;			
	procouponusername=document.getElementById("cmbcouponuser").value;	
		
		if(procouponmaster==0)
		{
			alert('Please Select Master Coupon Name');
			document.getElementById("cmbcouponmaster").focus();
		}
		else if(procoupons=="Select Coupons")
		{
			alert('Please Select Coupon Name');
			document.getElementById("cmbprocouponname").focus();
		}
		else if(procouponusername==0)
		{
			alert('Please Select User Name');
			document.getElementById("cmbcouponuser").focus();
		}
		else
		{
			alert('show details' + check );
			xajax_procouponmonitor(xajax.getFormValues('frmprocouponmonitor'),check);
		}
}

function opencsv()
{
	var win=window.open('http://www.atyourprice.in/yourprice/openprocouponcsv.php','','left=0px, top=0px, width=570px, height=350px, scrollbars=yes, status =yes, resizable=no');
}
function printprocoupon()
{
		
		var PrintValue = document.getElementById('procoupdetails').innerHTML;
		var WinPrint = window.open('','','left=0px, top=0px, width=570px, height=350px, scrollbars=yes, status =yes, resizable=no');
		WinPrint.document.write(PrintValue);
		WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();		
}
function procsv(couponname)
{
	
	xajax_procouponcsvcreate(couponname);
	alert("csv file created for" + couponname + "coupons");
	var win=window.open('http://www.atyourprice.in/yourprice/openhardprocsv.php','','left=0px, top=0px, width=570px, height=350px, scrollbars=yes, status =yes, resizable=no');
}
function promocouponshow()
{	
	//alert('promocoupon show');
	document.getElementById("travel_request").className="show";
	document.getElementById("propaymentdiv").className="show";
	document.getElementById("promcode").className="show";
	document.getElementById("dualpromocode").className="show";
	document.getElementById("txtpromocode").value= "Enter Promo Code";
	document.getElementById("txtpromocode").focus();
	document.getElementById("txtpromocode").select();
	
}
//new added from requestindex js
function acceptcheckcoupon(check)
{
	if( check == "accept")
	{
		requestdate = document.getElementById('sessionrequestdate').value;
		xajax_coupondeliverystore(requestdate);
	}
	else
	{
		document.location.href = "../yourprice/index.php";
	}

	
}
//this code for promocoupon add by ramesh
function couponhide()
{
	document.getElementById("travel_request").className="show";
	document.getElementById("propaymentdiv").className="hide";
	document.getElementById("promcode").className = "hide";
	document.getElementById("dualpromocode").className="hide";	

}
 function couponsubmit()
 {
	 	prmocode = document.getElementById('txtpromocode').value;
		if(prmocode=="")
		{
			alert('Please Enter promo');
			document.getElementById('txtpromocode').focus();
		}
		else
		{
			document.getElementById("promcode").className="hide";
			document.getElementById("dualpromocode").className="hide";	
			document.getElementById("travel_request").className="show";
			//document.getElementById("promosubmit").className="show";
			document.getElementById("propaymentdiv").className="hide";
			//document.getElementById("promocoupondiv").className="hide";
			
			xajax_checkprocoupondetails(prmocode);
		}
 }
 function procouponverify()
 {
	alert('Invalid Coupon');
	/*document.getElementById("travel_request").className="show";
	document.getElementById("propaymentdiv").className="hide";
	document.getElementById("promcode").className = "hide";
	document.getElementById("dualpromocode").className="hide";
	document.getElementById("promocoupondiv").className="show";
	document.getElementById("promosubmit").className="hide";
	document.getElementById("choiceairline").className="hide";
	document.getElementById("premiumairlinediv").className="hide";*/
	
	return false
 }
 
 function couponattribute(triptype,procouponamount,promocode,procouponid,taxstatus)
 {
	// alert(procouponamount + "promocode"+ promocode + "id=" + procouponid +"taxstatus"+ taxstatus);
	 document.getElementById('txtrequestfare').value=procouponamount;
 	 document.getElementById('txtcurrentpromocode').value=promocode;
	 document.getElementById('txtcurrentpromocodeid').value=procouponid;
 	 document.getElementById('hdntaxvalue').value=taxstatus;
	 if(triptype=='O')
	 {
		 document.getElementById("rounddiv").className="hide";
	 }
 } 

function prorequestvalidate()
{
	
	requestform = document.Mainform;
	datevalue = 'N';
	timevalue = 'N';
	choicevalue = getradiovaluesearch(document.Mainform.choice);
	tripvalue = getradiovaluesearch(document.Mainform.trip);
	origincity =document.Mainform.Origin.value;
	destcity =document.Mainform.Dest.value;
	adultsnum =document.Mainform.Adult.value;
	requestfare = document.Mainform.txtrequestfare.value;;
	onwardsdate =document.Mainform.StartDate.value;
	onwardedate =document.Mainform.enddate.value;
	promocodeid = document.getElementById('txtcurrentpromocodeid').value;
	
	
	
	if(tripvalue=="2")
	{
			returnsdate =document.Mainform.returnsdate.value;
			returnedate =document.Mainform.returnedate.value;
	}
	else
	{
			returnsdate =document.Mainform.StartDate.value;
			returnedate =document.Mainform.enddate.value;
	}
	onfirsttime = '00:00';
	onsecondtime = '23:59';
	retfirsttime = '00:00';
	retsecondtime = '23:59';
	//alert("origincity "+origincity+" destcity  "+destcity )
	if(origincity=='')
	{
		alert('Please select the city ');
		document.Mainform.Origin.focus();
		return false;
	}
	if(destcity=='')
	{
		alert('Please select the city ');
		document.Mainform.Dest.focus();
		return false;
	}
	if(destcity==origincity)
	{
		alert('Please select different cities for Origin and Destination.');
		document.Mainform.Origin.focus();
		return false;
	}
	if(datevalue=='N')
	{
		onwardsdate =document.Mainform.StartDate.value;
		onwardedate =document.Mainform.enddate.value;
		if((onwardsdate=="")||(onwardedate==""))
		{
			alert('Please select your departure date range');
			document.Mainform.StartDate.focus();
			return false;
		}
		if(tripvalue=="2")
		{
			returnsdate =document.Mainform.returnsdate.value;
			returnedate =document.Mainform.returnedate.value;
			if((returnsdate=="")||(returnedate==""))
			{
				alert('Please select your return departure date range ');
				document.Mainform.returnsdate.focus();
				return false;
			}
		}
	}
	if(timevalue=='N')
	{
		onfirsttime = document.getElementById("ontime1").value;
		onsecondtime = document.getElementById("ontime2").value;
		if(onfirsttime >= onsecondtime)
		{
			alert("Onward start time must be lesser than end time");
			document.getElementById("ontime2").focus();
			return false;
		}
		if(tripvalue=="2")
		{
			retfirsttime = document.getElementById("rettime1").value;
			retsecondtime = document.getElementById("rettime2").value;
			if(retfirsttime >= retsecondtime)
			{
				alert("Return  start time must be lesser than end time");
				document.getElementById("rettime2").focus();
				return false;
			}
		}
	}
	var totalnumofairlines = new Array();
	var cnt = 0;
	premiumairline = "notselected";
	lowcostairline = "notselected";
	precount = document.getElementById("proprecount").value;
	for(i=1;i<precount;i++)
	{
		if(document.getElementById("propremium").checked==true)
		{
			totalnumofairlines[cnt] = document.getElementById("propre"+i).value;
			cnt++;
			premiumairline = "selected";
		}
	}
	lowcount = document.getElementById("prolowcount").value;
	for(i=1;i<lowcount;i++)
	{
		if(document.getElementById("prolowcost").checked==true)
		{
			totalnumofairlines[cnt] = document.getElementById("prolow"+i).value;
			cnt++;
			lowcostairline = "selected";
		}
	}
	if(premiumairline == "notselected" && lowcostairline == "notselected")
	{
		alert('Please select atleast one airline');
		return false;
	}
	if(requestfare=="")
	{
		alert("Please enter your desired price");
		document.Mainform.Requestfare.focus();
		return false;
	}
	
		
	xajax_provalidaterequest(tripvalue, totalnumofairlines,origincity,destcity,onwardsdate,onwardedate,onfirsttime,onsecondtime, returnsdate,returnedate,retfirsttime,retsecondtime,requestfare,promocodeid,xajax.getFormValues("Mainform"));
	//return true;
}
function procheckminflight(response,sorrymsg)
{	
	if(response == 'false')
	{
		//document.getElementById("sorrydivshow").className = "show";
		//document.getElementById("sorrymsg").innerHTML = sorrymsg;
		document.getElementById('insidefarealert').innerHTML = sorrymsg;
		document.getElementById('insidefarealert').className = "show";
		document.getElementById('divcontinue').className = "hide";
		document.getElementById('divchange').className = "hide";
		document.getElementById('divinput').className = "hide";
		//document.getElementById('divflightchange').className = "show";
		document.getElementById('farealert').className = "show";
		
		return false;
	}
	else
	{
		document.Mainform.action="couponrequestpass.php";
		document.Mainform.submit();
		return true;
	}
	
}
function submitselectedairline()
{
	var returnairline ='';
	var returnflightnumber = 0;
	var returndatedep='';
	var returntimedep='';
	var returntimearr = '';
	var returnfare =0;
	var retunorigin='';
	var retundest='';
    var onwcouponselectcheck = 'notselected';
	var retcouponselectcheck = 'notselected';
	var requestdate = document.getElementById("couponrequestdate").value;
	//alert('selected airline submit');
	var airlinecount = document.getElementById("selectedaircount").value;
	var origin = document.getElementById("origin").value;
	var dest = document.getElementById("dest").value;
	//alert(airlinecount+origin+dest);
	
	for(i=1;i<airlinecount;i++)
		{	
			if(document.getElementById("rdcouponairline"+i).checked==true)
			{
				  airline = document.getElementById("airline"+i).value;
				  flightnumber =document.getElementById("flightnumber"+i).value;
				  datedep = document.getElementById("datedep"+i).value;
				  timedep = document.getElementById("timedep"+i).value;
				  timearr = document.getElementById("timearr"+i).value;
				  fare = document.getElementById("fare"+i).value;
				  onwcouponselectcheck = 'selected';
			}
		}	
		//var triptype="oneway";
	//alert(airline+flightnumber+datedep+timedep+timearr+fare);
	if(onwcouponselectcheck == 'notselected')
	{
		alert("Please select onward flight from the list.");
		return false;
	}
	var roundtrip = document.getElementById("rtntype").value;
	
	
	if(roundtrip == 'Round')
	{
	 
		//for return selected
	var triptype = 'Round';
	var returnairlinecount = document.getElementById("selectedreturnaircount").value;
	var retunorigin = document.getElementById("retunorigin").value;
	var retundest = document.getElementById("returndest").value;
	
	//alert("Retun Trip"+returnairlinecount+retunorigin+retundest);
	for(i=1;i<returnairlinecount;i++)
	{	
		if(document.getElementById("rdreturncouponairline"+i).checked==true)
		{
			  returnairline = document.getElementById("returnairline"+i).value;
			  returnflightnumber =document.getElementById("returnflightnumber"+i).value;
			  returndatedep = document.getElementById("returndatedep"+i).value;
			  returntimedep = document.getElementById("returntimedep"+i).value;
			  returntimearr = document.getElementById("returntimearr"+i).value;
			  returnfare = document.getElementById("returnfare"+i).value;
			  retcouponselectcheck = 'selected';
		}
	}		
		//alert("return"+returnairline+returnflightnumber+returndatedep+returntimedep+returntimearr+returnfare);
	if(retcouponselectcheck == 'notselected')
	{
		alert("Please select return flight from the list.");
		return false;
	}
		//alert(triptype);
	}
	
	
	xajax_airlinepass(airline,origin,dest,flightnumber,datedep,timedep,timearr,fare,requestdate,returnairline,returnflightnumber,returndatedep,returntimedep,returntimearr,returnfare,retunorigin,retundest,triptype);		
	//xajax_procoupontransaction();
}

function proclicktripcheck(tripcheck)
{
	if(tripcheck=="round")
	{
		
		document.getElementById("roundtripview1").className="show";
		document.getElementById("returntimedivname1").className="show";
	}
	else 
	{
		
		document.getElementById("roundtripview1").className="hide";
		document.getElementById("returntimedivname1").className="hide";
	}
	
}
function porocouponassigncall(id,show,target)
	{
		//alert("requestindex.js");
		Calendar.setup({
		inputField     :    show,     // id of the input field
        ifFormat       :    "%Y-%m-%d",      // format of the input field
        button         :    id,  // trigger for the calendar (button ID)
        align          :    "Tl",           // alignment (defaults to "Bl")
		singleClick    :    true
		
    });
	}
