//====================================================================================================
//	File Name		:	user.js
//	Author			: 	Himanshu Ahuja
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.
//====================================================================================================

//====================================================================================================
//	Function Name	:	Form_Submit()
//	Purpose			:	This function will check inputted field by user are valid or not.
//	Return			:	none
//----------------------------------------------------------------------------------------------------
function ValidateForm(frm)
{

	with(frm)
    {
    	//alert('HII');
		if(!IsEmpty(c_title, 'Please, enter Classified Title.'))
		{
			return false;
		}
		if(!IsEmpty(f_date, 'Please, enter From Date.'))
		{
			return false;
		}
		if(!IsEmpty(t_date, 'Please, enter To Date.'))
		{
			return false;
		}
	
		if(!IsEmpty(c_date, 'Please, Select Classified Date.'))
		{
			return false;
		}
	
		return true;
    }
}
/*function calendarCallback(date, month, year)
{

	var dates = new Date();
	var date1 = dates.getDate() ;
	month1=dates.getMonth()+1;
	if(month1 <= 9)
	{ month1 = '0'+ month1 }
	var year1 = dates.getFullYear() ;
	//current date
	final1 = year1  + "-" + month1 + "-"  + date1;

	if(month <= 9)
	{ month = '0'+ month }
	if(date <= 9)
	{ date = '0'+date }
	setdate =  year + '-' + month + '-' + date ;
	
	if( setdate < final1)
	{
		alert('Please Select Valid Date');
		document.frmClassified.c_date.value = final1;
		document.frmClassified.c_date.focus();
	}
	else
	{
		document.frmClassified.c_date.value = setdate;
		document.frmClassified.c_date.focus();	
	}
	 	
}*/







//====================================================================================================
//	Function Name	:	Show_Click()
//----------------------------------------------------------------------------------------------------
function Show_Click(cId)
{
	with(document.frmClassified)
	{
		c_id.value = cId;
		Action.value = "Show";
		submit();
	}
}
//====================================================================================================
//	Function Name	:	Add_Click()
//----------------------------------------------------------------------------------------------------
function Add_Click()
{
	with(document.frmClassified)
	{
		Action.value = "Add";
		submit();
	}
}
//====================================================================================================
//	Function Name	:	Edit_Click()
//----------------------------------------------------------------------------------------------------
function Edit_Click(cId)
{
	
	with(document.frmClassified)
	{
		
		Action.value = "Update";
		c_id.value = cId;
		flag.value=false;
		submit();
	}
}



function Update_Click(cId,ApprovalStatus)
{
	with(document.frmClassified)
	{
		c_id.value = cId;
		c_status.value = ApprovalStatus;
		Action.value = "Modify";
		submit();
	}
}
//====================================================================================================
//	Function Name	:	Delete_Click()
//----------------------------------------------------------------------------------------------------
function Delete_Click(cId)
{
	with(document.frmClassified)
	{
		if(confirm('Are you sure you want to delete this Classified?'))
		{	
			c_id.value = cId;
			Action.value = "Delete";
			submit();
		}
	}
}

//====================================================================================================
//	Function Name	:	Print_Click()
//----------------------------------------------------------------------------------------------------

function Print_Click(cId)
{
	
	with(document.frmClassified)
	{
		popupWindowURL("classified.php?Action=Print&c_id="+cId, 'PageContent', 650, 500, false, false, true);
	}
	
}


//====================================================================================================
//	Function Name	:	DeleteChecked_Click()
//----------------------------------------------------------------------------------------------------
function DeleteChecked_Click()
{
	with(document.frmClassified)
	{
		var flg=false;

		if(document.all['classified_list[]'].length)
		{
			for(i=0; i < document.all['classified_list[]'].length; i++)
			{
				if(document.all['classified_list[]'][i].checked)
					flg = true;
			}
		}
		else
		{
			if(document.all['classified_list[]'].checked)
				flg = true;
		}
		if(!flg)
		{
			alert('Please, select the Classified you want to delete.');
			return false;
		}
			
		if(confirm('Are you sure you want to delete selected Classified?'))
		{
			Action.value = 'DeleteSelected';
			submit();
		}
	}
}

function calendarCallback(date, month, year)
{
	//date = date + '/' + month + '/' + year;
	if(month <= 9)
	{ month = '0'+month }
	if(date <= 9)
	{ date = '0'+date }
	
	date =  year +'-' + month + '-' + date ;
	document.all.f_date.value = date;	// name of the form itself is forms[0]
	document.all.f_date.focus();
}

function calendarCallback1(date, month, year)
{
	//date = date + '/' + month + '/' + year;
	if(month <= 9)
	{ month = '0'+month }
	if(date <= 9)
	{ date = '0'+date }
	
	date =  year +'-' + month + '-' + date ;
	document.all.t_date.value = date;	// name of the form itself is forms[0]
	document.all.t_date.focus();
}






/*function Category_Change(CatId,ACTION)
{
	with(document.frmProject)
	{
		Action.value = ACTION;		
		category_id.value = CatId;		
		flag.value=true;
		submit();
	}
}*/

function Click_Search()
{	
	with(document.frmClassified)
	{
		if(from_day.value!=0 || from_month.value!=0 || from_year.value!=0)
		{
			if(from_day.value!=0 && from_month.value==0 && from_year.value==0)
			{
				alert('Please select From Month and From Year');
				return false;
			}
			else
			if(from_day.value==0 && from_month.value==0 && from_year.value!=0)
			{
				alert('Please select From Day and From Month');
				return false;
			}
			else
			if(from_day.value==0 && from_month.value!=0 && from_year.value==0)
			{
				alert('Please select From Day and From Year');
				return false;
			}
			else
			if(from_day.value!=0 && from_month.value!=0 && from_year.value==0)
			{
				alert('Please select From Year');
				return false;
			}
			else
			if(from_day.value==0 && from_month.value!=0 && from_year.value!=0)
			{
				alert('Please select From Day');
				return false;
			}
			else
			if(from_day.value!=0 && from_month.value==0 && from_year.value!=0)
			{
				alert('Please select From Month');
				return false;
			}
		}
		
		if(to_day.value!=0 || to_month.value!=0 || to_year.value!=0)
		{
			if(to_day.value!=0 && to_month.value==0 && to_year.value==0)
			{
				alert('Please select To Month and To Year');
				return false;
			}
			else
			if(to_day.value==0 && to_month.value==0 && to_year.value!=0)
			{
				alert('Please select To Day and To Month');
				return false;
			}
			else
			if(to_day.value==0 && to_month.value!=0 && to_year.value==0)
			{
				alert('Please select To Day and To Year');
				return false;
			}
			else
			if(to_day.value!=0 && to_month.value!=0 && to_year.value==0)
			{
				alert('Please select To Year');
				return false;
			}
			else
			if(to_day.value==0 && to_month.value!=0 && to_year.value!=0)
			{
				alert('Please select To Day');
				return false;
			}
			else
			if(to_day.value!=0 && to_month.value==0 && to_year.value!=0)
			{
				alert('Please select To Month');
				return false;
			}
		}
		
		if(to_year.value!=0 && from_year.value!=0)
		{
			if(to_year.value<from_year.value)
			{
				alert('Please select Proper To Year');
				return false;
			}
		}	
		
		searchclassified.value=true;
		submit();
		return true;
	}
}

function searchresult(fromdate,todate)
{
	
}
