/*
	+=======================================================================================================================+
	|										Blue Apple Technologies Private Limited								            |
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Project Name :  Explore Direct																						|
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Dated 		 :  4 August 2005																						|
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Author		 : Deepak Arora																							|
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Purpose		 : This script provides Javascript checks and functions used by all the listing in admin section		|
	|-----------------------------------------------------------------------------------------------------------------------|
	|Include Files   :  																									|
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Last updated  :																										|
	|-----------------------------------------------------------------------------------------------------------------------|
	|	Updation done :																										|
	+=======================================================================================================================+
*/

	// this function used the select the multiple checkboxes
	// listed in the list
	function SelectAll()
	{
		var MaxChks = parseInt(document.Form1.chk_id.length);
		if ( isNaN(MaxChks) )		// if there is only one record in a page
									// then chk_airline_id doesnt become a array
									// so returns NaN
		{
			MaxChks = 0;			// then put zero in it
		}

		if ( document.Form1.chk_top.checked )
		{
			for ( i = 0; i < MaxChks; i++)				// make all the check boxes checked
			{
				document.Form1.chk_id[i].checked = true;
			}
			if ( MaxChks == 0 )			// if MaxChks is 0 then chk_airline_id is not an array
				document.Form1.chk_id.checked = true;
		}
		else
		{
			for ( i = 0; i < MaxChks; i++)			// make all the check boxes unchecked
			{
				document.Form1.chk_id[i].checked = false;
			}
			if ( MaxChks == 0 )
				document.Form1.chk_id.checked = false;
		}
	}
	function MakeString(mTitle, mForm)
	{
		
		if ( !mForm )
		{
			mForm = document.Form1;
		}
		
		var MaxChks = parseInt(mForm.chk_id.length);
		var ret = "" ;
		if ( isNaN(MaxChks) )
		{
			MaxChks = 0;
		}
		var count_chks = 0;		
		if ( MaxChks == 0 )			// if MaxChks is 0 then ImgSr is not an array
		{
			if (mForm.chk_id.checked )
			{
				ret = mForm.chk_id.value + ",";
				count_chks++;
			}
		}
		else
		{
			for ( i = 0; i < MaxChks; i++)
			{
				if (mForm.chk_id[i].checked )
				{
					ret = ret + mForm.chk_id[i].value + ",";
					count_chks++;
				}
			}
		}
		if ( count_chks == 0 )
		{
			alert("Please select a " + mTitle + " From " + mTitle + " List and proceed");
			return false;
		}
		return ret;
	}

	function SubmitForm(str, mTitle, mAction, mForm, extraDetails )
	{
		var get = MakeString(mTitle, mForm );
		if ( ! get )
		{
			return false;
		}
		
		if(str=="Delete")
		{

		if(!confirm("Are you sure to delete this record?"))
		{ return false;
		}
		}
		
		if ( mForm )			//   mForm may not be present
		{
							// submits the form with some query string data
			mForm.action = mAction +  "?cmd=" + str + "&chk_ids=" + get + "&" + extraDetails;
			mForm.submit();
		}
		else
		{
							// submits the form with some query string data
			document.Form1.action = mAction +  "?cmd=" + str + "&chk_ids=" + get + "&" + extraDetails ;
			document.Form1.submit();
		}
	}

