// JavaScript Document

// Function to  Open a popup window

var waitWin;

function setWaitWindow(theURL) 
{

	// open the new window, setting it to the global variable defined above
	waitWin =  window.open(theURL,'SearchPopupWindow',' width=600, height=200, top=140, left=105, scrollbars=yes, resizable=yes, status=yes ');
//	waitWin =  window.open(theURL,'SearchPopupWindow',' width=600 height=200 top=140 left=105 toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes ');
	//window.open(theURL, "contentWindow", "toolbar=no, statusbar=no, height=300, width=600");
	// set off the waiting function
	//,' width=570 height=370 top=140 left=105 resizable=yes, status=yes'
	checkWindow();
}

// Function to  to check wherther popup window is closed or not
function checkWindow() 
{
	if(waitWin.closed) 
	{
	        // the window has been closed; refresh this one
        	window.location.reload();
	}
	else
	{
		setTimeout("checkWindow()", 100);
	}
}

// Function to validate FromDate is greater then ToDate or not.
function CheckFromToDate( FromDate, ToDate )
{
	//alert("CheckFromToDate function called");	
	DateFrom = FromDate.value;
//	alert("DateFrom = " + DateFrom);
	if ( DateFrom.length > 10 )
	{
		FromTime = DateFrom.substr(11,5);
//		alert("FromTime = " + FromTime);
		FromHH = FromTime.substr(0,2);
//		alert("FromHH = " + FromHH);
		FromMM = FromTime.substr(3,2);
//		alert("FromMM = " + FromMM);
	}
	else
	{
		FromHH = "00";
		FromMM = "00";
	}
	DateFrom = DateFrom.substring(0,10);
	
	DateTo = ToDate.value;
	
	//alert("DateFrom = " + DateFrom);
	//alert("DateTo = " + DateTo);
	
	if ( DateTo.length > 10 )
	{
		ToTime = DateTo.substr(11,5);
//		alert("ToTime = " + ToTime);
		ToHH = ToTime.substr(0,2);
//		alert("ToHH = " + ToHH);
		ToMM = ToTime.substr(3,2);
//		alert("ToMM = " + ToMM);
	}
	else
	{
		ToHH = "00";
		ToMM = "00";
	}
	
	DateTo = DateTo.substring(0,10);
//	alert("DateFrom = "+DateFrom);
//	alert("DateTo = "+DateTo);
	if ( DateFrom == "" )
	{
		DateFrom = new Date();
	}
	if ( DateTo == "" )
	{
		DateTo = new Date();
	}	
	var date1, date2;
	var month1, month2;
	var year1, year2;
	
	month1 = DateFrom.substring (0, DateFrom.indexOf ("/"));
//	alert("month1 = "+month1);
	date1 = DateFrom.substring (DateFrom.indexOf ("/")+1, DateFrom.lastIndexOf ("/"));
//	alert("date1 = "+date1);
	year1 = DateFrom.substring (DateFrom.lastIndexOf ("/")+1, DateFrom.length);
//	alert("year1 = "+year1);
	
	month2 = DateTo.substring (0, DateTo.indexOf ("/"));
//	alert("month2 = "+month2);
	date2 = DateTo.substring (DateTo.indexOf ("/")+1, DateTo.lastIndexOf ("/"));
//	alert("date2 = "+date2);
	year2 = DateTo.substring (DateTo.lastIndexOf ("/")+1, DateTo.length);
//	alert("year2 = "+year2);

	month1--;
	month2--;

	FDate = new Date(year1, month1  , date1, FromHH, FromMM);
	//alert("FDate = "+FDate);
	TDate = new Date(year2, month2  , date2, ToHH, ToMM);
	//alert("TDate = "+TDate);

	if ( FDate >= TDate )
	{
		alert("From Date & Time can not be greater than or equal to To Date and Time.");	
		//alert("From Date  can not be greater than or equal to To Date.");	

		FromDate.value = "";
		ToDate.value = "";
		FromDate.focus();
		
		return false;
	}
	else
	{
		return true;
	}
}


function trim(strComp)
{
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}

function validateForm(formobj)
{
	var strmsg = "Following are the errors:\n \n";
	var focusobj = null;
	if(trim(formobj.TxtUserName.value) == "")
	{
		strmsg += "- User Name can not be blank\n";
		formobj.TxtUserName.value = "";
		focusobj = formobj.TxtUserName;
	}
	if(trim(formobj.TxtPassword.value) == "")
	{
		strmsg += "- Password can not be blank\n";
		formobj.TxtPassword.value = "";
		if(focusobj == null) focusobj = formobj.TxtPassword;
	}
	if(focusobj != null)
	{
		alert (strmsg);
		focusobj.focus();
		return false;
	}
	else
		return true;
}

function isNum(entry) 
{
	var str = entry.value;
	for (var i = 0; i < str.length; i++) 
	{
		var ch = str.substring(i, i + 1)
		if ((ch < "0" || "9" < ch) && ch != '.') 
		{
			alert("Value should be numeric.")
			entry.value="";
			entry.focus();
			entry.select();
			return true;
		}
	}
}

function AcceptOnlyChar(e) 
{
	var k;
	document.all ? k = e.keyCode : k = e.which;
	return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32);
}

function ValidateNum(TxtObj)
{
	Num = TxtObj.value;
	if(trim(Num) == "")
	{
		alert("Value can not be blank");
		TxtObj.value = "";
		TxtObj.focus();
		return false;
	}
	else
	{
		if (isNum(TxtObj))
		{
			return false;
		}
	}
	return true;
}


function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length ; i>=1 ; i--)	// Use selectbox.options.length-1 for leaving 1 option
	{
		selectbox.remove(i);
	}
}

function PreviewImage(ImgFile, ImgId, TdId)
{
	imgpath = ImgFile.value;
	myimgid = window.document.getElementById(ImgId);
	myimgid.src=imgpath;
	myrowid = window.document.getElementById(TdId);
	myrowid.style.display = '';
	// To get the name and extension of image
	/*
	imgpathstr= new String(imgpath);
	splitString = imgpathstr.split("\\");
	imgpathstr1= new String(splitString[splitString.length-1]);
	dotindex = imgpathstr1.lastIndexOf(".");
	imagename= new String(imgpathstr1.substring(0,dotindex));
	imageext= new String(imgpathstr1.substring(dotindex+1,imgpathstr1.length));
	*/
}


// Function to open Popup window for large image and details
function PopupWindow(theURL) 
{
	waitWin =  window.open(theURL,'SearchPopupWindow',' width=600 height=400 top=140 left=105 scrollbars=yes resizable=yes, status=yes ');
}

function ShowFaqAnswer(TheID)
{
	TargetId = window.document.getElementById(TheID);
	TargetId.style.display = '';
}

function HideFaqAnswer(TheID)
{
	TargetId = window.document.getElementById(TheID);
	TargetId.style.display = 'none';
}


// Function to validate FromDate is greater then ToDate or not.
function CheckDateGreaterThenCurrentDate( DateObj )
{
	//alert("CheckDateGreaterThenCurrentDate called");
	TargetDate = DateObj.value;
	TargetDate = TargetDate.substring(0,10);
	
	CurrentDate = new Date();
	
	//alert("TargetDate = " + TargetDate);
	//alert("CurrentDate = " + CurrentDate);
	
	CD = CurrentDate.getDate() ;
	CM = CurrentDate.getMonth() + 1 ;
	CY = CurrentDate.getYear() ;
	
	//alert("CD = " + CD);
	//alert("CM = " + CM);
	//alert("CY = " + CY);
	
	CDate = CM+"/"+CD+"/"+CY	;
	//alert("CDate = " + CDate);
	
	var date1, date2;
	var month1, month2;
	var year1, year2;
	
	month1 = TargetDate.substring (0, TargetDate.indexOf ("/"));
	//alert("month1 = "+month1);
	date1 = TargetDate.substring (TargetDate.indexOf ("/")+1, TargetDate.lastIndexOf ("/"));
	//alert("date1 = "+date1);
	year1 = TargetDate.substring (TargetDate.lastIndexOf ("/")+1, TargetDate.length);
	//alert("year1 = "+year1);
	
	month2 = CDate.substring (0, CDate.indexOf ("/"));
	//alert("month2 = "+month2);
	date2 = CDate.substring (CDate.indexOf ("/")+1, CDate.lastIndexOf ("/"));
	//alert("date2 = "+date2);
	year2 = CDate.substring (CDate.lastIndexOf ("/")+1, CDate.length);
	//alert("year2 = "+year2);

	FDate = new Date(year1, month1 -1 , date1);
	//alert("FDate = "+FDate);
	TDate = new Date(year2, month2 -1 , date2);
	//alert("TDate = "+TDate);

	if ( FDate < TDate )
	{
		//alert("Pickup or Dropoff Dates can not be less than current date.");	
		alert("Dates can not be less than current date.");	
		return false;
	}
	else
	{
		return true;
	}
}








// Function to validate FromDate is greater then ToDate or not.
function ValidateFromToDate( FromDate, ToDate )
{
	//alert("ValidateFromToDate function called");	
	DateFrom = FromDate.value;
//	alert("DateFrom = " + DateFrom);
	if ( DateFrom.length > 10 )
	{
		FromTime = DateFrom.substr(11,5);
//		alert("FromTime = " + FromTime);
		FromHH = FromTime.substr(0,2);
//		alert("FromHH = " + FromHH);
		FromMM = FromTime.substr(3,2);
//		alert("FromMM = " + FromMM);
	}
	else
	{
		FromHH = "00";
		FromMM = "00";
	}
	DateFrom = DateFrom.substring(0,10);
	
	DateTo = ToDate.value;
	
	//alert("DateFrom = " + DateFrom);
	//alert("DateTo = " + DateTo);
	
	if ( DateTo.length > 10 )
	{
		ToTime = DateTo.substr(11,5);
//		alert("ToTime = " + ToTime);
		ToHH = ToTime.substr(0,2);
//		alert("ToHH = " + ToHH);
		ToMM = ToTime.substr(3,2);
//		alert("ToMM = " + ToMM);
	}
	else
	{
		ToHH = "00";
		ToMM = "00";
	}

	DateTo = DateTo.substring(0,10);

	if ( DateFrom == "" )
	{
		DateFrom = new Date();
	}
	if ( DateTo == "" )
	{
		DateTo = new Date();
	}	
	var date1, date2;
	var month1, month2;
	var year1, year2;
	
	month1 = DateFrom.substring (0, DateFrom.indexOf ("/"));
//	alert("month1 = "+month1);
	date1 = DateFrom.substring (DateFrom.indexOf ("/")+1, DateFrom.lastIndexOf ("/"));
//	alert("date1 = "+date1);
	year1 = DateFrom.substring (DateFrom.lastIndexOf ("/")+1, DateFrom.length);
//	alert("year1 = "+year1);
	
	month2 = DateTo.substring (0, DateTo.indexOf ("/"));
//	alert("month2 = "+month2);
	date2 = DateTo.substring (DateTo.indexOf ("/")+1, DateTo.lastIndexOf ("/"));
//	alert("date2 = "+date2);
	year2 = DateTo.substring (DateTo.lastIndexOf ("/")+1, DateTo.length);
//	alert("year2 = "+year2);

	month1--;
	month2--;

	//FDate = new Date(year1, month1  , date1, FromHH, FromMM);
	FDate = new Date(year1, month1  , date1);

//	alert("FDate = "+FDate);
	//TDate = new Date(year2, month2  , date2, ToHH, ToMM);
	TDate = new Date(year2, month2  , date2);

//	alert("TDate = "+TDate);

	if ( FDate > TDate )
	{
		alert("From Date can not be greater than To Date.");	
		//alert("From Date  can not be greater than or equal to To Date.");	

		FromDate.value = "";
		ToDate.value = "";
		FromDate.focus();
		
		return false;
	}
	else
	{
		return true;
	}
}




// Function to validate FromDate is greater then ToDate or not.
function ValidatePropertyFromToDate( FromDate, ToDate,msg )
{
	//alert("ValidateFromToDate function called");	
//	DateFrom = FromDate.value;
	DateFrom = FromDate;
//	alert("DateFrom = " + DateFrom);
	if ( DateFrom.length > 10 )
	{
		FromTime = DateFrom.substr(11,5);
//		alert("FromTime = " + FromTime);
		FromHH = FromTime.substr(0,2);
//		alert("FromHH = " + FromHH);
		FromMM = FromTime.substr(3,2);
//		alert("FromMM = " + FromMM);
	}
	else
	{
		FromHH = "00";
		FromMM = "00";
	}
	DateFrom = DateFrom.substring(0,10);
	
//	DateTo = ToDate.value;
	DateTo = ToDate;
	
	//alert("DateFrom = " + DateFrom);
	//alert("DateTo = " + DateTo);
	
	if ( DateTo.length > 10 )
	{
		ToTime = DateTo.substr(11,5);
//		alert("ToTime = " + ToTime);
		ToHH = ToTime.substr(0,2);
//		alert("ToHH = " + ToHH);
		ToMM = ToTime.substr(3,2);
//		alert("ToMM = " + ToMM);
	}
	else
	{
		ToHH = "00";
		ToMM = "00";
	}

	DateTo = DateTo.substring(0,10);

	if ( DateFrom == "" )
	{
		DateFrom = new Date();
	}
	if ( DateTo == "" )
	{
		DateTo = new Date();
	}	
	var date1, date2;
	var month1, month2;
	var year1, year2;
	
	month1 = DateFrom.substring (0, DateFrom.indexOf ("/"));
//	alert("month1 = "+month1);
	date1 = DateFrom.substring (DateFrom.indexOf ("/")+1, DateFrom.lastIndexOf ("/"));
//	alert("date1 = "+date1);
	year1 = DateFrom.substring (DateFrom.lastIndexOf ("/")+1, DateFrom.length);
//	alert("year1 = "+year1);
	
	month2 = DateTo.substring (0, DateTo.indexOf ("/"));
//	alert("month2 = "+month2);
	date2 = DateTo.substring (DateTo.indexOf ("/")+1, DateTo.lastIndexOf ("/"));
//	alert("date2 = "+date2);
	year2 = DateTo.substring (DateTo.lastIndexOf ("/")+1, DateTo.length);
//	alert("year2 = "+year2);

	month1--;
	month2--;

	//FDate = new Date(year1, month1  , date1, FromHH, FromMM);
	FDate = new Date(year1, month1  , date1);

//	alert("FDate = "+FDate);
	//TDate = new Date(year2, month2  , date2, ToHH, ToMM);
	TDate = new Date(year2, month2  , date2);

//	alert("TDate = "+TDate);

	if ( FDate > TDate )
	{
		alert(msg);	
		//alert("From Date  can not be greater than or equal to To Date.");	
		
		return false;
	}
	else
	{
		return true;
	}
}


















//-->
