
 // this function is used in contract file.
function showMe(id) 
{
	
	var obj = document.getElementById(id);
	if (obj.style.display=="block") {
	obj.style.display = "none";
	} else {
	obj.style.display = "block";
	}
}




//these four arrays will hold the values of a slab for a service provider.
//That we ill use in XML genetration for tht service.
var arrEndUser		=	new Array();
var arrTaBooking	=	new Array();
var arrCBooking		=	new Array();
var arrToBooking	=	new Array();
var arrPnr			=	new Array();


 function IsNumeric(sText)
	{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
	Char = sText.charAt(i);
	if (ValidChars.indexOf(Char) == -1)
	{
	IsNumber = false;
	}
	}
	return IsNumber;

}

//This function is used to add new row in existing slab
function addSlab()
{
			
		
			if(document.getElementById('endUser').value == '')
			{	
				alert("Please enter End User Booking");
				return false;
			}
			if(document.getElementById('taBooking').value == '')
			{	
				alert("Please enter TA Booking Booking");
				return false;
			}
			if(document.getElementById('toBooking').value == '')
			{	
				alert("Please enter TO Booking");
				return false;
			}
			if(document.getElementById('cBooking').value == '')
			{	
				alert("Please enter Corporate Booking");
				return false;
			}
			if(document.getElementById('pnr').value == '')
			{	
				alert("Please enter PNR Start Value");
				return false;
			}
			
			if(!IsNumeric(document.getElementById('pnr').value)){
				alert("Please enter only integer in PNR Start Value.");
				return false;
			}
			
            var endUser		= document.getElementById('endUser').value;

            var taBooking	= document.getElementById('taBooking').value;

            var toBooking	= document.getElementById('toBooking').value;

			var cBooking	= document.getElementById('cBooking').value;

			var pnr			= document.getElementById('pnr').value;


            if(endUser!="")
                        arrEndUser.splice(arrEndUser.length+1,0,endUser);
            if(taBooking!="")
                        arrTaBooking.splice(arrTaBooking.length+1,0,taBooking);
			if(toBooking!="")
                        arrToBooking.splice(arrToBooking.length+1,0,toBooking);
            if(cBooking!="")
                        arrCBooking.splice(arrCBooking.length+1,0,cBooking);
			 if(pnr!="")
                        arrPnr.splice(arrPnr.length+1,0,pnr);


            var hid1="";

            var strOutput = "<table width='99%' border='0' cellpadding='1' cellspacing='1' bgcolor='#A7A7A7'>";

            strOutput+="<tr> <td width='69' height='22' class='tableheader'>End User</td>";

            strOutput+="<td width='83' height='22' class='tableheader'>TA Booking</td>"; 

			strOutput+="<td width='86' class='tableheader'>Corporate Booking</td>"; 

			strOutput+="<td width='96' class='tableheader'>TO Booking</td>"; 

			strOutput+="<td width='120' class='tableheader'>Start Value (Greater than)</td>"; 

            strOutput+="<td width='133' align='center' valign='middle' class='tableheader'>&nbsp;</td></tr>";
			
           for(var i=0;i<arrEndUser.length;i++)
            {  

                        if(i%2==0)    // If remainder is even, output tr with class="altrow"

                        {           strOutput += "<tr class='altrow'>";           }

                        else  // Else, output tr with class altrow_white

                        {  strOutput += "<tr class='altrow_white'>";           }

             

                        strOutput += "<td height='22' align='center' valign='middle'>" + arrEndUser[i] + "</td>";

                        strOutput += "<td height='22' align='center' valign='middle'>" + arrTaBooking[i] + "</td>";

                        strOutput += "<td height='22' align='center' valign='middle'>" + arrCBooking[i] + "</td>";

						strOutput += "<td height='22' align='center' valign='middle'>" + arrToBooking[i] + "</td>";

						strOutput += "<td height='22' align='center' valign='middle'>" + arrPnr[i] + "</td>";

						strOutput += "<td  align='center' valign='middle'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                        strOutput +=   "<tr><td align='enter' valign='middle'><a href='#'><img src="+SITEURL+"images/icon_edit.gif alt='Click to edit' width='16' height='17' border='0' /></a></td>";
                        strOutput +=    "<td align='center' valign='middle'><img src="+SITEURL+"images/Icon_delete.gif alt='Click to delete' width='15' height='15' /></td>";
						strOutput +=    " </tr></table></td></tr>";
                                          

                        
							hid1 += "<input type='hidden' name='fromHid[]' value='" + endUser[i] +"'>";

							hid1 += "<input type='hidden' name='fromHid[]' value='" + arrTaBooking[i] +"'>";

							hid1 += "<input type='hidden' name='fromHid[]' value='" + arrCBooking[i] +"'>";

							hid1 += "<input type='hidden' name='toHid[]' value='" + arrToBooking[i] +"'>";

							hid1 += "<input type='hidden' name='fineHid[]' value='" + arrPnr[i] +"'>";   
            }

            // Close table

            strOutput += "</table>";

			document.getElementById('hid').innerHTML += hid1;

            document.getElementById('service_provider').innerHTML = strOutput;

            document.getElementById('endUser').value = '';

            document.getElementById('taBooking').value = '';

            document.getElementById('toBooking').value = '';

			document.getElementById('cBooking').value = '';

			document.getElementById('pnr').value = '';

			return true;
}


//create HTTPXML object
function createRequestObject()
{

				if(window.XMLHttpRequest){
				  // Firefox, Safari, Opera..
				  http = new XMLHttpRequest();
			
			   } else if(window.ActiveXObject) {
				  // Internet Explorer 5+
				  http = new ActiveXObject("Microsoft.XMLHTTP");
			   } else {
				  // There is an error creating the object,
				  // just as an old browser is being used.
				  alert('Problem creating the XMLHttpRequest object');
			   } 

	return http;
}
var http = createRequestObject();

//function to add the entries in xml file.
function addToXml()
{

	var chkValue;
	if(document.getElementById('allotatedBranches').value == '')
			{	
				alert("Please enter Alloted Branches");
				return false;
			}
	if(document.getElementById('cCharge').value == '')
			{	
				alert("Please enter Cancelation Charges");
				return false;
			}

//get all varibles to set in XML;
if(document.getElementById("cType").checked)
	{
		cType = 1;
	}else{
		cType = 2;
	}
allotatedBranches	=	document.getElementById("allotatedBranches").value;
cCharge				=	document.getElementById("cCharge").value;
companyId			=	document.getElementById("companyId").value;
companyName			=	document.getElementById("companyName").value;
subCountryId		=	document.getElementById("subCountryId").value;



if(document.getElementById("Service Provider").checked)
	$serviceProvider	=	1;

serviceType			=	document.getElementById("ServiceTab").value;




//http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var params	= 'arrEndUser='+arrEndUser+'&arrTaBooking='+arrTaBooking+'&arrCBooking='+arrCBooking+'&arrToBooking='+arrToBooking+'&arrPnr='+arrPnr;
params	   +='&allocatedBranches='+allotatedBranches+"&cCharge="+cCharge+'&cType='+cType+'&serviceType='+serviceType;
params	   +='&companyId='+companyId+'&companyName='+companyName+'&subCountryId='+subCountryId+'&serviceProvider='+$serviceProvider;
alert(params);
http.open('GET', 'create_contract.php?'+params, true);
http.onreadystatechange	=	handleResponse;
http.send(params);
}

function handleResponse() {
   if(http.readyState == 4 && http.status == 200){
      // Text returned FROM the PHP script
      var response = http.responseText;
      if(response) {
			alert(response);
         // UPDATE ajaxTest content
         //document.getElementById("XmlMessage").innerHTML = response;
      }
   }
} 


function setServiceTab_old(str,formName) { 
			
			if(str=="Flights")
			{	
				document.forms[formName].Flights.src=SITEURL+"images/flights_over.gif";
				document.forms[formName].service.value='1';
			}
				else
				{
				document.forms[formName].Flights.src=SITEURL+"images/flights.gif";
				}
			
			if(str=="Trains")
			{	
				document.forms[formName].Trains.src=SITEURL+"images/trains_over.gif";
				document.forms[formName].service.value='6';
			}
				else
				{
				document.forms[formName].Trains.src=SITEURL+"images/trains.gif";	
				}
			
			if(str=="Hotels")
			{	
				document.forms[formName].Hotels.src=SITEURL+"images/hotels_over.gif";
				document.forms[formName].service.value='10';
			}
				else
				{
					document.forms[formName].Hotels.src=SITEURL+"images/hotels.gif";
				}
			
			if(str=="Cars")
			{	
				document.forms[formName].Cars.src=SITEURL+"images/cars_over.gif";
				document.forms[formName].service.value='2';
			}
				else
				{
					document.forms[formName].Cars.src=SITEURL+"images/cars.gif";
				}
			
			if(str=="Events")
			{	
				document.forms[formName].Events.src=SITEURL+"images/events_over.gif";
				document.forms[formName].service.value='4';
			}
				else
				{
				document.forms[formName].Events.src=SITEURL+"images/events.gif";	
				}
				
			if(str=="Golf")
			{	
				document.forms[formName].Golf.src=SITEURL+"images/golf_over.gif";
				document.forms[formName].service.value='8';
			}
				else
				{
				document.forms[formName].Golf.src=SITEURL+"images/golf.gif";	
				}
				
			if(str=="Charted")
			{	
				document.forms[formName].Charted.src=SITEURL+"images/charted_over.gif";
				document.forms[formName].service.value='11';
			}
				else
				{
				document.forms[formName].Charted.src=SITEURL+"images/charted.gif";	
				}
				
			if(str=="ShowTickets")
			{	
				document.forms[formName].ShowTickets.src=SITEURL+"images/showtickets_over.gif";
				document.forms[formName].service.value='5';
			}
				else
				{
				document.forms[formName].ShowTickets.src=SITEURL+"images/showtickets.gif";	
				}
				
			if(str=="Tours")
			{	
				document.forms[formName].Tours.src=SITEURL+"images/tours_over.gif";
				document.forms[formName].service.value='9';
			}
				else
				{
				document.forms[formName].Tours.src=SITEURL+"images/tours.gif";	
				}
			if(str=="Coaches")
			{	
				document.forms[formName].Coaches.src=SITEURL+"images/coaches_over.gif";
				document.forms[formName].service.value='13';
			}
				else
				{
				document.forms[formName].Coaches.src=SITEURL+"images/coaches.gif";	
				}
			

			if(str=="Insurance")
			{	
				document.forms[formName].Insurance.src=SITEURL+"images/insurance_over.gif";
				document.forms[formName].service.value='12';
			}
				else
				{
				document.forms[formName].Insurance.src=SITEURL+"images/insurance.gif";	
				}
				
			if(str=="Game")
			{	
				document.forms[formName].Game.src=SITEURL+"images/game_over.gif";
				document.forms[formName].service.value='7';
			}
				else
				{
				document.forms[formName].Game.src=SITEURL+"images/game.gif";	
				}

			if(str=="Package")
			{	
				document.forms[formName].Package.src=SITEURL+"images/package_over.gif";
				document.forms[formName].service.value='Package';
			}
				else
				{
					if(document.forms[formName].Package)
					document.forms[formName].Package.src=SITEURL+"images/package.gif";
				}
			if(str=="Cruises")
			{	
				document.forms[formName].Cruises.src=SITEURL+"images/cruises_over.gif";
				document.forms[formName].service.value='3';
			}
				else
				{
				document.forms[formName].Cruises.src=SITEURL+"images/cruises.gif";
				}	
		/*str1	=	document.getElementById('ServiceTab').value
		

			if(str1=="Flights" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/flights.gif";
			}
			if(str1=="Trains" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/trains.gif";
			}
			if(str1=="Hotels" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/hotels.gif";
			}
			if(str1=="Cars" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/cars.gif";
			}
			if(str1=="Events" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/events.gif";
			}
			if(str1=="Golf" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/golf.gif";
			}
			if(str1=="Cruise" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/cruises.gif";
			}
			if(str1=="Charted" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/charted.gif";
			}
			if(str1=="Show Tickets" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/showtickets.gif";
			}
			if(str1=="Tours" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/tours.gif";
			}
			if(str1=="Coaches" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/coaches.gif";
			}
			if(str1=="Insurance" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/insurance.gif";
			}
			if(str1=="Game" && str1!=str)
			{	
				document.getElementById(str1).src=SITEURL+"images/game.gif";
			}

			document.getElementById('ServiceTab').value		=	str;	
			

			//show the sp_contract div
			document.getElementById('sp_contract').style.display		=	''; */
}


// empty the fields of the form
 function emptyFields(ArryToBlank , formname)
 {
	for(var i = 0; i < ArryToBlank.length; i++)
	{	
		document.forms[formname].elements[ArryToBlank[i]].value = '';
	}
 }

// reset the fields of the form
 function resetFields(formname)
 {
	for(var i = 0; i < document.forms[formname].elements.length; i++)
	{	
		document.forms[formname].elements[i].value = '';
	}
 }



function confirm_delete(id, str)
{
	document.form1.oper.value='delete';
	document.form1.recId.value = id;
	var agree=confirm("Are you sure you want to delete this "+str+" from the system");
	if (agree)
		return true ;
	else
		return false ;
}


// To delete the Corporate User....Function Starts
// Created by Ajay Shukla 
function confirm_deleteCorporate(id,str,formname)
{
//	alert(id + formname);
//	document.form1.oper.value='delete';
	document.forms[formname].elements.oper.value = 'delete';
	document.forms[formname].elements.recId.value = id;

//	document.form1..value = ;
	var agree=confirm("Are you sure you want to delete this "+str+" from the system");
	
	if (agree)
		return true ;
	else
		return false ;
}

// .............Function Ends



function update(id)
{
	document.form1.oper.value='delete';
	document.form1.recId.value = id;
}

function reset_city()
{
	document.getElementById('city').value='';
	document.getElementById('stateDiv').selectedIndex='';
	document.getElementById('country').selectedIndex='';
}

function getState(countryId,stateId)
{
	//alert("SDF");
	url	=	'flights_airport.php?cId='+countryId;

	if(stateId != '')
		url += '&sId='+stateId;
    
	new Ajax.Updater('loadCat',url,{asynchronous:true, evalScripts:true});
}

function getCity(stateId,cityId)
{
	//alert(stateId);
	url	=	'flights_airport.php?stateId='+stateId;
	if(cityId != '')
		url += '&cityId='+cityId;
		
	 
//alert(url);
	//new Ajax.Updater('test',url,{asynchronous:true, evalScripts:true});
	new Ajax.Updater('citydiv',url,{asynchronous:true, evalScripts:true});
}
function City(stateId,cityId,url)
{
	//alert(stateId);
	url	=	url+'?stateId='+stateId;
	if(cityId != '')
		url += '&cityId='+cityId;
		
	 
//alert(url);
	//new Ajax.Updater('test',url,{asynchronous:true, evalScripts:true});
	new Ajax.Updater('citydiv',url,{asynchronous:true, evalScripts:true});
}


function getvailidation()
{ 
	if(document.getElementById('country').value=='')
	{ 
		alert("Select a country");
		return false;
	}
	
	/*	
	if(document.getElementById('stateDD').value=='')
	{
		alert("Select a state");
		return false;
	}
	*/
		
	if(document.getElementById('cityDD').value=='')
	{
		alert("Select a city");
		return false;
	}
	
	return true;
	
}

//    Set Tag inable


function select_all(totalList)//Function For Select check box
{
	var total_records_viewed = totalList;
	var strList = ''; 

	for(i=0;i<total_records_viewed;i++)
	{
		if(document.getElementById('chk_SD').checked==true)
		{
			document.getElementById('chk'+i).checked=true;
			strList = strList + document.getElementById('chk'+i).value + ",";
		}
		else
		{
			document.getElementById('chk'+i).checked=false;
		}
	}

	strLength = strList.length; 
	strList = Left(strList,strLength - 1)
	document.getElementById('clientList_hidd').value = strList;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function un_select(totalList)
{	 
	var total_records_viewed = totalList;
	var strList = ''; 
	for(i=0;i<total_records_viewed;i++)
	{
		flag="True";
		if(!(document.getElementById('chk'+i).checked)){
				flag="false";
		}else{
			strList = strList + document.getElementById('chk'+i).value + ",";
		}
			document.getElementById('chk_SD').checked=false;
	}
	strLength = strList.length; 
	strList = Left(strList,strLength - 1)
	document.getElementById('clientList_hidd').value = strList;
}
