/* to check the users email, alphabets, name, password, remove spaces form the Name through trim() etc..*/
function trim (strVar) { 
	if(strVar.length >0)
	{
		while(strVar.charAt(0)==" ")						//remove left spaces
			strVar=strVar.substring(1,strVar.length);
		while(strVar.charAt(strVar.length-1)==" ")			//remove right spaces
			strVar=strVar.substring(0,strVar.length-1);
	}
	return strVar;
}

function notValidPath( str )
{
	mailRE = new RegExp( );
	mailRE.compile('^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+', 'gi');
	return !(mailRE.test(str));
}

function checkEmail(email) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
		return (true);
	}
	return false;
}

function notValidsite( str )
{
	mailRE = new RegExp( );
	mailRE.compile('^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+', 'gi');
	return !(mailRE.test(str));
}

/*To check the Login ID of the User*/
function isNotID(str)
{
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if((ch < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) 
		{
			if(ch == "_" || ch == "-") continue;
			return true;
		}
	}
	return false;
}

function checkLogin(chk)
{
	if(chk.userName.value.length==0)
	{
		alert("User Name can not be left blank");
		chk.userName.focus();
		return false;
	}
	if(chk.password.value.length==0)
	{
		alert("Password can not be left blank");
		chk.password.focus();
		return false;
	}
	return true;
}

/*Used in All Cp Modules*/
function checkAll(checked)
{
	for(var i=0;i<document.removeForm.elements.length;i++)
	{
		var e = document.removeForm.elements[i];
		if(e.type == "checkbox") e.checked = checked;
	}
}

function checkAllperm(checked)
{
	for(var i=0;i<document.showPermFrm.elements.length;i++)
	{
		var e = document.showPermFrm.elements[i];
		if(e.type == "checkbox") e.checked = checked;
	}
}

function checkAllperm1(checked)
{
	for(var i=0;i<document.permFrm.elements.length;i++)
	{
		var e = document.permFrm.elements[i];
		if(e.type == "checkbox") e.checked = checked;
	}
}

function checkfrmedit(chk)
{
	if(chk.keyword.value == "")
	{
		alert("Please enter keyword to search");
		chk.keyword.focus();
		return false;
	}
	if(chk.keyword.value.length<3)
	{
		alert("Please enter atleast [3] charaters to search");
		chk.keyword.focus();
		return false;
	} 
	return true;
}

var pop = '';
function openwin(nm,width,height) {
	var name = nm;
	if (pop && !pop.closed) {
		pop.close();
	}
	pop = eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
	if (!pop.opener) popUpWin.opener = self;
}

function closewin()
{
	window.close();
}

function checkCreateUser(membersForm)
{
	//Members Id validation
	var member = trim(document.membersForm.loginId.value);
	if(member.length == 0)
	{
		alert("Please enter Login ID");
		document.membersForm.loginId.focus();
		return false;
	}
	var member = document.membersForm.loginId.value;
	if(member.length < 5)
	{
		alert("Login ID should be atleast Five(5) Characters!");
		document.membersForm.loginId.focus();
		return false;
	}
	if(isNotID(member))
	{
		alert("Invalid Characters in Login ID");
		document.membersForm.loginId.focus();
		return false;
	}
	//Password Validation
	var password = trim(document.membersForm.password.value);
	if(password.length == 0)
	{
		alert("Please enter Password");
		document.membersForm.password.focus();
		return false;
	}
	var password = document.membersForm.password.value;
	if(password.length < 6)
	{
		alert("Password should be atleast Six(6) Characters!");
		document.membersForm.password.focus();
		return false;
	}
	if(isNotID(password))
	{
		alert("Invalid Characters in Password");
		document.membersForm.password.focus();
		return false;
	}
	//Confirm Password
	var confirm_password = document.membersForm.confirm_password.value;
	if(password != confirm_password)
	{
		alert("Password & Confirm Password mismatch!");
		document.membersForm.confirm_password.focus();
		return false;
	}
	//First Name
	var fname = trim(document.membersForm.name.value);
	if(fname.length == 0)
	{
		alert("Please enter Name");
		document.membersForm.name.focus();
		return false;
	}
	//Address
	var address_1 = trim(document.membersForm.address_1.value);
	if(address_1.length == 0)
	{
		alert("Please enter Address Line - 1");
		document.membersForm.address_1.focus();
		return false;
	}
	//Country
	var country = document.membersForm.country.value;
	if(country.length == 0)
	{
		alert("Please Select Users Country");
		document.membersForm.country.focus();
		return false;
	}
	//Email
	var email_1 = trim(document.membersForm.email_1.value);
	if(email_1.length == 0)
	{
		alert("Please enter Email - 1");
		document.membersForm.email_1.focus();
		return false;
	}
	if(checkEmail(email_1) == false)
	{
		alert("Invalid email! Please re-enter.");
		document.membersForm.email_1.select();
		return false;
	}
	return true;
}

function deleteAlert1()
{
	var records = document.removeForm.records.value;
	var total = 0;
	var msg = "";

	if(records>0)
	{
		for(i=0; i<document.removeForm.length; i++)
		{
			e = document.removeForm.elements[i];
			if (e.type=='checkbox')
			{
				if(eval('e.checked') == true)
				{
					total= total+1;
				}
			}
		}
		if(total >0)
		{
			msg = msg + 'Do You Like to remove ' + total +' records ?';
		}
		else
		{
			alert("Please check the items to remove !");
			return false;
		}
		if(msg.length >0)
		{
			var flag;
			flag = confirm(msg + " If Yes Press \"OK\" else Press \"Cancel\".");
			if(flag == true)
				return true;
		}
	}
	return false;
}

function textLimitCheck(thisArea, maxLength, msg)
{
	if (thisArea.value.length > maxLength)
	{
		alert(maxLength + ' characters limit.\rExcessive data will be truncated.');
		thisArea.value = thisArea.value.substring(0, maxLength);
		thisArea.focus();
	}
	document.getElementById(msg).innerText = thisArea.value.length;
}

function setTitle(val, title, desc)
{
	title	= document.getElementById(title);
	desc	= document.getElementById(desc);
	title.value	= val;
	desc.value	= val;
}

//check Category form
function checkCityForm(theForm)
{
	var city_name = trim(theForm.city_name.value);
	var countryID = trim(theForm.countryID.value);
	var meta_title = trim(theForm.meta_title.value);
	
	if(city_name.length==0)
	{
		alert("City Name should not be empty!");
		theForm.city_name.focus();
		return false;
	}
	if(countryID.length==0)
	{
		alert("Country should not be empty!");
		theForm.countryID.focus();
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Meta Title should not be empty!");
		theForm.meta_title.focus();
		return false;
	}
	return true;
}

//DATE VALIDATION
function dateValid(dd, mm, yyyy)
{
	if(dd.length==0 || mm.length==0 || yyyy.length==0)
		return false;
	if(isNaN(dd)) 
		return false;
	if(isNaN(mm)) 
		return false;
	if(isNaN(yyyy)) 
		return false;
	if(yyyy.length<4)
	{
		alert("Please Enter Year in four digit!");
		return false;
	}
	if(mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)
	{
		if(dd>31)
			return false;
	}
	else
	{
		if(mm==4 || mm==6 || mm==9 || mm==11)
		{
			if(dd>30)
				return false;
		}
		else
		{
			var f_day=isLeap(yyyy);
			if(dd>f_day) return false;
		}
	}
	return true;
}

//CHECK DAY IN FEBRUARY MONTH
function isLeap(year)
{
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

//CHECK DATE DIFFERENCE BETWEEN TO DATES
function dateDiff(dd1, mm1, yy1, dd2, mm2, yy2)
{
	var date1 = yy1 + mm1 + dd1;
	var date2 = yy2 + mm2 + dd2;
	if(date1>date2) return false;
	return true;
}

function getCurrentDate()
{
	currentTime = new Date();

	dd = currentTime.getDate();
	mm = currentTime.getMonth();
	yy = currentTime.getFullYear();
	mm = mm + 1;
	if(dd<10) dd = "0" + dd;
	if(mm<10) mm = "0" + mm;
	currDate = yy + "-" + mm + "-" + dd;

	return currDate;
}

function checkAlert(theForm)
{
	var name = trim(theForm.name.value);
	var email = trim(theForm.email.value);
	if(name.length==0)
	{
		alert("Please enter your name!");
		theForm.name.focus();
		return false;
	}
	if(email.length==0)
	{
		alert("Please enter your e-mail!");
		theForm.email.focus();
		return false;
	}
	if(checkEmail(email) == false)
	{
		alert("Invalid email! Please re-enter.");
		theForm.email.select();
		return false;
	}
	return true;
}

function checkHotelForm(theForm)
{
	var hotelName = trim(theForm.hotelName.value);
	var add_line1 = trim(theForm.add_line1.value);
	var countryID = trim(theForm.countryID.value);
	var city_id = trim(theForm.city_id.value);
	var area_id = trim(theForm.area_id.value);
	var hotelURL = trim(theForm.hotelURL.value);
	var fixFileName = trim(theForm.fixFileName.value);
	var rating_id = theForm['rating_id[]'];

	if(hotelName.length==0)
	{
		alert("Please enter Hotel Name !");
		theForm.hotelName.focus();
		return false;
	}
	if(fixFileName.length>0)
	{
		var pos = fixFileName.lastIndexOf(".");
		var lastPos = fixFileName.length-1;
		if(pos>=0 && ((pos+4)==lastPos || (pos+4)==lastPos))
		{
			fixFileName = fixFileName.substr(0,pos);
			if(isNotID(fixFileName))
			{
				alert("Invalid File Name!");
				theForm.fixFileName.select();
				return false;
			}
		}
		else
		{
			alert("Invalid File Name!");
			theForm.fixFileName.select();
			return false;
		}
	}
	if(rating_id.value.length==0)
	{
		alert("Please select hotel rating !");
		return false;
	}
	if(add_line1.length==0)
	{
		alert("Please enter address line-1 !");
		theForm.add_line1.focus();
		return false;
	}
	if(countryID.length==0)
	{
		alert("Please select country !");
		theForm.countryID.focus();
		return false;
	}
	if(city_id.length==0)
	{
		alert("Please select city !");
		theForm.city_id.focus();
		return false;
	}
/*	if(area_id.length==0)
	{
		alert("Please select area !");
		theForm.area_id.focus();
		return false;
	}
*/
	if(hotelURL.length>0)
	{
		if(notValidsite(hotelURL))
		{
			alert("Invalid URL! Please re-enter.");
			theForm.hotelURL.focus();
			return false;
		}
	}
	return true;
}

function createHotelForm(theForm)
{
	var hotel_id = trim(theForm.hotel_id.value);
	var hotelName = trim(theForm.hotelName.value);
	var add_line1 = trim(theForm.add_line1.value);
	var countryID = trim(theForm.countryID.value);
	var city_id = trim(theForm.city_id.value);
	var accommodation = trim(theForm.accommodation.value);
	var meta_title = trim(theForm.meta_title.value);
	var hotel_services = trim(theForm.hotel_services.value);

	var rating_id = theForm['rating_id[]'];

	if(hotel_id.length==0)
	{
		alert("Please select Hotel Name!");
		theForm.hotel_id.focus();
		return false;
	}
	if(hotelName.length==0)
	{
		alert("Please enter Hotel Name !");
		theForm.hotelName.focus();
		return false;
	}
	if(rating_id.value.length==0)
	{
		alert("Please select hotel rating !");
		return false;
	}
	if(add_line1.length==0)
	{
		alert("Please enter address line-1 !");
		theForm.add_line1.focus();
		return false;
	}
	if(accommodation.length==0)
	{
		alert("Please enter Hotel Accommodation !");
		theForm.accommodation.focus();
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Please enter Meta Title !");
		theForm.meta_title.focus();
		return false;
	}
	if(hotel_services.length==0)
	{
		alert("Please enter Hotel Services !");
		theForm.hotel_services.focus();
		return false;
	}
	return true;
}

/*FUNCTION FOR PAGE GENERATE FORM*/
function checkPageSetting(theForm)
{
	var extension = theForm.extension.value;
	var basePath = theForm.basePath.value;
	var hotelFolder = theForm.hotelFolder.value;
	var cityFolder = theForm.cityFolder.value;
	var ratingFolder = theForm.ratingFolder.value;
	var areaFolder = theForm.areaFolder.value;
	var onlineDir = theForm.onlineDir.value;

	if(extension.length==0)
	{
		alert("Extension Field can't be blank.");
		theForm.extension.focus();
		return false;
	}
	if(basePath.length==0)
	{
		alert("Base Path Field can't be blank.");
		theForm.basePath.focus();
		return false;
	}
	if(extension==".php")
	{
		if(onlineDir.length==0)
		{
			alert("Online Base Dir Field can't be blank.");
			theForm.onlineDir.focus();
			return false;
		}
	}
	if(hotelFolder.length==0)
	{
		alert("Folder Field can't be blank.");
		theForm.hotelFolder.focus();
		return false;
	}
	if(hotelFolder!="/")
	{
		if(checkFolderName(hotelFolder))
		{
			alert("Please Enter correct Folder Name.");
			theForm.hotelFolder.select();
			return false;
		}
	}
	if(cityFolder.length==0)
	{
		alert("Folder Field can't be blank.");
		theForm.cityFolder.focus();
		return false;
	}
	if(cityFolder!='/')
	{
		if(checkFolderName(cityFolder))
		{
			alert("Please Enter correct Folder Name.");
			theForm.cityFolder.select();
			return false;
		}
	}
	if(ratingFolder.length==0)
	{
		alert("Folder Field can't be blank.");
		theForm.ratingFolder.focus();
		return false;
	}
	if(ratingFolder!='/')
	{
		if(checkFolderName(ratingFolder))
		{
			alert("Please Enter correct Folder Name.");
			theForm.ratingFolder.select();
			return false;
		}
	}
	if(areaFolder.length==0)
	{
		alert("Folder Field can't be blank.");
		theForm.areaFolder.focus();
		return false;
	}
	if(areaFolder!='/')
	{
		if(checkFolderName(areaFolder))
		{
			alert("Please Enter correct Folder Name.");
			theForm.areaFolder.select();
			return false;
		}
	}
	return true;
}

function checkFolderName(str)
{
	for (var i = 0; i < str.length; i++)
	{
		if(parseInt(str.charAt(0))==str.charAt(0))
			return true;
		var ch = str.substring(i, i + 1);
		if((ch < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) 
		{
			if(ch == "_" || ch=="-") continue;
			return true;
		}
	}
	return false;
}

//created by nipan for Package Category
function checkCategory(theForm)
{
	var catName = theForm.catName.value;
	var metaTitle = theForm.metaTitle.value;

	if(catName.length==0)
	{
		alert("Category Name can't be blank.");
		theForm.catName.focus();
		return false;
	}
	if(metaTitle.length==0)
	{
		alert("Meta Title can't be blank.");
		theForm.metaTitle.focus();
		return false;
	}
}

// for Package Master
function checkPackage(theForm)
{
	var packageName = theForm.packageName.value;
	var countryID = theForm.countryID.value;
	var cityID = theForm.cityID.value;
	var hotel_id = theForm.hotel_id.value;
	var startDate_dd = theForm.startDate_dd.value;
	var startDate_mm = theForm.startDate_mm.value;
	var startDate_yyyy = theForm.startDate_yyyy.value;
	var endDate_dd = theForm.endDate_dd.value;
	var endDate_mm = theForm.endDate_mm.value;
	var endDate_yyyy = theForm.endDate_yyyy.value;

	var exDateFrom_dd = theForm.exDateFrom_dd.value;
	var exDateFrom_mm = theForm.exDateFrom_mm.value;
	var exDateFrom_yyyy = theForm.exDateFrom_yyyy.value;
	var exDateTo_dd = theForm.exDateTo_dd.value;
	var exDateTo_mm = theForm.exDateTo_mm.value;
	var exDateTo_yyyy = theForm.exDateTo_yyyy.value;

	var nights = theForm.nights.value;
	var packageTypeIND = theForm.packageTypeIND;
	var packageTypeNONIND = theForm.packageTypeNONIND;
	var metaTitle = theForm.metaTitle.value;
	var currentDate = new Date();
	var toDay_yyyy = currentDate.getFullYear();
	var toDay_mm = currentDate.getMonth()+1;
	if(toDay_mm<=9)
		toDay_mm = "0"+toDay_mm;
	var toDay_dd = currentDate.getDate();
	if(toDay_dd<=9)
		toDay_dd = "0"+toDay_dd;

	if(packageName.length==0)
	{
		alert("Package Name can't be blank");
		theForm.packageName.focus();
		return false;
	}
	
	var category, category1, num,num1 = 0, i;
	category = "cat[]";
	category1 = document.getElementById(category);
	num = category1.length;
	for(i=0;i<num;i++)
	{
		if(category1[i].selected==true)
		{
			num1++;
		}
	}
	if(num1==0)
	{
		alert("Please select at least one category.");
		return false;
	}
	if(countryID.length==0)
	{
		alert("Please select a country name.");
		theForm.countryID.focus();
		return false;
	}
	if(cityID.length==0)
	{
		alert("Please select a city name.");
		theForm.cityID.focus();
		return false;
	}
	if(hotel_id.length==0)
	{
		alert("Please select a hotel name.");
		theForm.hotel_id.focus();
		return false;
	}
	if(startDate_dd.length>0 && startDate_mm.length>0 && startDate_yyyy.length>0)
	{
		if(!dateValid(startDate_dd, startDate_mm, startDate_yyyy))
		{
			alert("Please select valid date!");
			theForm.startDate_dd.focus();
			return false;
		}
	}
	else
	{
		alert("Please select start date.");
		theForm.startDate_dd.focus();
		return false;
	}
	if(endDate_dd.length>0 && endDate_mm.length>0 && endDate_yyyy.length>0)
	{
		if(!dateValid(endDate_dd, endDate_mm, endDate_yyyy))
		{
			alert("Please select valid date!");
			theForm.endDate_dd.focus();
			return false;
		}
	}
	else
	{
		alert("Please select end date.");
		theForm.endDate_dd.focus();
		return false;
	}
	if(!dateDiff(toDay_dd, toDay_mm, toDay_yyyy,endDate_dd, endDate_mm, endDate_yyyy))
	{
		alert("End Date should be greated than or equal to Today!");
		theForm.endDate_dd.focus();
		return false;
	}
	if(!dateDiff(startDate_dd, startDate_mm, startDate_yyyy,endDate_dd, endDate_mm, endDate_yyyy))
	{
		alert("Start Date can't be greated than End Date!");
		theForm.startDate_dd.focus();
		return false;
	}
	if(exDateFrom_dd.length>0 && exDateFrom_mm.length>0 && exDateFrom_yyyy.length>0)
	{
		if(!dateDiff(startDate_dd, startDate_mm, startDate_yyyy,exDateFrom_dd, exDateFrom_mm, exDateFrom_yyyy))
		{
			alert("Except Date From should greater than Start Date!");
			theForm.exDateFrom_dd.focus();
			return false;
		}
		if(!dateDiff(exDateFrom_dd, exDateFrom_mm, exDateFrom_yyyy,endDate_dd, endDate_mm, endDate_yyyy))
		{
			alert("Except date From should less than End Date!");
			theForm.exDateFrom_dd.focus();
			return false;
		}
	}
	if(exDateTo_dd.length>0 && exDateTo_mm.length>0 && exDateTo_yyyy.length>0)
	{
		if(!dateDiff(startDate_dd, startDate_mm, startDate_yyyy,exDateFrom_dd, exDateFrom_mm, exDateFrom_yyyy))
		{
			alert("Except Date To should greater than Start Date!");
			theForm.exDateTo_dd.focus();
			return false;
		}
		if(!dateDiff(exDateTo_dd, exDateTo_mm, exDateTo_yyyy,endDate_dd, endDate_mm, endDate_yyyy))
		{
			alert("Except date To should less than End Date!");
			theForm.exDateTo_dd.focus();
			return false;
		}
	}
	if(exDateFrom_dd.length>0 && exDateFrom_mm.length>0 && exDateFrom_yyyy.length>0 && exDateTo_dd.length>0 && exDateTo_mm.length>0 && exDateTo_yyyy.length>0)
	{
		if(!dateDiff(exDateFrom_dd, exDateFrom_mm, exDateFrom_yyyy,exDateTo_dd, exDateTo_mm, exDateTo_yyyy))
		{
			alert("Except date From should less than Except date To.!");
			theForm.exDateTo_dd.focus();
			return false;
		}
	}
	if(packageTypeIND.checked==false && packageTypeNONIND.checked==false)
	{
		theForm.packageTypeIND.focus();
		alert("Please tick at least one Package Type.");
		return false;
	}
	if((nights.length!=0 && parseInt(nights)!=nights) || (nights.length!=0 && nights<=0))
	{
		alert("Please enter Nights in +Ve Integer value.");
		theForm.nights.focus();
		return false;
	}
	if(metaTitle.length==0)
	{
		alert("Please enter meta title.");
		theForm.metaTitle.focus();
		return false;
	}
}

function setTitlePackage(val, title, desc)
{
	title = document.getElementById(title);
	desc = document.getElementById(desc);
	title.value = val;
	desc.value = val;
	if(val.length==0)
		desc.value = "";
}

function checkSearchValidityPackage(theForm)
{
	var packageName = theForm.packageName.value;
	var state = theForm.state.value;
	var categoryID = theForm.categoryID.value;
	var cityID = theForm.cityID.value;
	var hotelName = theForm.hotelName.value;
	var groupID = theForm.groupID.value;
	var dateFrom_dd = theForm.dateFrom_dd.value;
	var dateFrom_mm = theForm.dateFrom_mm.value;
	var dateFrom_yyyy = theForm.dateFrom_yyyy.value;
	var dateTo_dd = theForm.dateTo_dd.value;
	var dateTo_mm = theForm.dateTo_mm.value;
	var dateTo_yyyy = theForm.dateTo_yyyy.value;
	var dateFrom = "", dateTo = "";

	if(dateFrom_dd.length>0 && dateFrom_mm.length>0 && dateFrom_yyyy.length>0)
	{
		dateFrom = dateFrom_yyyy+"-"+dateFrom_mm+"-"+dateFrom_dd;
	}
	if(dateTo_dd.length>0 && dateTo_mm.length>0 && dateTo_yyyy.length>0)
	{
		dateTo = dateTo_yyyy+"-"+dateTo_mm+"-"+dateTo_dd;
	}
	if(dateTo.length!=0 && dateFrom.length==0)
	{
		alert("Please enter From Date");
		theForm.dateFrom_dd.focus();
		return false;
	}
	if(packageName.length==0 && state.length==0 && categoryID.length==0 && cityID.length==0 && hotelName.length==0 && groupID.length==0 && dateFrom.length==0 && dateTo.length==0)
	{
		alert("Please choose at least one search criteria!");
		theForm.packageName.focus();
		return false;
	}
	if(dateFrom_dd.length>0 && dateFrom_mm.length>0 && dateFrom_yyyy.length>0 && dateTo_dd.length>0 && dateTo_mm.length>0 && dateTo_yyyy.length>0)
	{
		if(!dateDiff(dateFrom_dd, dateFrom_mm, dateFrom_yyyy, dateTo_dd, dateTo_mm, dateTo_yyyy))
		{
			alert("To Date should greater than From Date.!");
			theForm.dateTo_dd.focus();
			return false;
		}
	}
}

// for Package Charges
function checkChargeSearchForm(theForm)
{
	var countryID = theForm.countryID.value;	
	var cityID = theForm.cityID.value;
	var hotel_id = theForm.hotel_id.value;
	var packageID = theForm.packageID.value;

	if(countryID.length==0)
	{
		alert("Country Name can't be blank.");
		theForm.countryID.focus();
		return false;
	}
	if(cityID.length==0)
	{
		alert("City Name can't be blank.");
		theForm.cityID.focus();
		return false;
	}
	if(hotel_id.length==0)
	{
		alert("Hotel Name can't be blank.");
		theForm.hotel_id.focus();
		return false;
	}
	if(packageID.length==0)
	{
		alert("Package Name can't be blank.");
		theForm.packageID.focus();
		return false;
	}
	return true;
}

var winName;
var packageID;
function winOpen(winName, packageID)
{
	winName = window.open('getRoomImage.php?packageID='+packageID, winName,'menubar=no, width=540, height=420, SCROLLBARS=yes, toolbar=no, top=10, left=10');
	winName.focus();
}

function pasteImage(image)
{
	 var wherePaste = window.name;
	 opener.document.all[wherePaste].value = image;
	 self.close();
}

function checkPackageCost(theForm)
{
	var roomName = theForm.roomName.value;
	var packageTypeNONIND = theForm.packageTypeNONIND.value;
	var packageTypeIND = theForm.packageTypeIND.value;
	var weekEnd = theForm.weekEnd;
	if(packageTypeIND==1)
	{
		var packageCostEPINR = theForm.packageCostEPINR.value;
		var packageCostCPINR = theForm.packageCostCPINR.value;
		var packageCostMAPINR = theForm.packageCostMAPINR.value;
		var packageCostAPINR = theForm.packageCostAPINR.value;
		if(weekEnd.checked==true)
		{
			var weekendCostEPINR = theForm.weekendCostEPINR.value;
			var weekendCostCPINR = theForm.weekendCostCPINR.value;
			var weekendCostMAPINR = theForm.weekendCostMAPINR.value;
			var weekendCostAPINR = theForm.weekendCostAPINR.value;
		}
	}
	if(packageTypeNONIND==1)
	{
		var packageCostEPUSD = theForm.packageCostEPUSD.value;
		var packageCostCPUSD = theForm.packageCostCPUSD.value;
		var packageCostMAPUSD = theForm.packageCostMAPUSD.value;
		var packageCostAPUSD = theForm.packageCostAPUSD.value;
		if(weekEnd.checked==true)
		{
			var weekendCostEPUSD = theForm.weekendCostEPUSD.value;
			var weekendCostCPUSD = theForm.weekendCostCPUSD.value;
			var weekendCostMAPUSD = theForm.weekendCostMAPUSD.value;
			var weekendCostAPUSD = theForm.weekendCostAPUSD.value;
		}
	}
	if(roomName.length==0)
	{
		alert("Room Name can't be blank.");
		theForm.roomName.focus();
		return false;
	}
	if(packageTypeIND==1 && packageTypeNONIND==1)
	{
		if((packageCostEPINR.length==0 || packageCostEPINR==0) && (packageCostEPUSD.length==0 || packageCostEPUSD==0) && (packageCostCPINR.length==0 || packageCostCPINR==0) && (packageCostCPUSD.length==0 || packageCostCPUSD==0) && (packageCostMAPINR.length==0 || packageCostMAPINR==0) && (packageCostMAPUSD.length==0 || packageCostMAPUSD==0) && (packageCostAPINR.length==0 || packageCostAPINR==0) && (packageCostAPUSD.length==0 || packageCostAPUSD==0))
		{
			alert("Please enter at lest one package cost.");
			theForm.packageCostEPINR.focus();
			return false;
		}
		if(packageCostEPINR.length!=0 && isNaN(packageCostEPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostEPINR.focus();
			return false;
		}
		if(packageCostCPINR.length!=0 && isNaN(packageCostCPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostCPINR.focus();
			return false;
		}
		if(packageCostMAPINR.length!=0 && isNaN(packageCostMAPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostMAPINR.focus();
			return false;
		}
		if(packageCostAPINR.length!=0 && isNaN(packageCostAPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostAPINR.focus();
			return false;
		}
		if(packageCostEPUSD.length!=0 && isNaN(packageCostEPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostEPUSD.focus();
			return false;
		}
		if(packageCostCPUSD.length!=0 && isNaN(packageCostCPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostCPUSD.focus();
			return false;
		}
		if(packageCostMAPUSD.length!=0 && isNaN(packageCostMAPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostMAPUSD.focus();
			return false;
		}
		if(packageCostAPUSD.length!=0 && isNaN(packageCostAPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostAPUSD.focus();
			return false;
		}
		if(weekEnd.checked==true)
		{
			if((weekendCostEPINR.length==0 || weekendCostEPINR==0) && (weekendCostEPUSD.length==0 || weekendCostEPUSD==0) && (weekendCostCPINR.length==0 || weekendCostCPINR==0) && (weekendCostCPUSD.length==0 || weekendCostCPUSD==0) && (weekendCostMAPINR.length==0 || weekendCostMAPINR==0) && (weekendCostMAPUSD.length==0 || weekendCostMAPUSD==0) && (weekendCostAPINR.length==0 || weekendCostAPINR==0) && (weekendCostAPUSD.length==0 || weekendCostAPUSD==0))
			{
				alert("Please enter at lest one weekend package cost.");
				theForm.weekendCostEPINR.focus();
				return false;
			}
			if(weekendCostEPINR.length!=0 && isNaN(weekendCostEPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostEPINR.focus();
				return false;
			}
			if(weekendCostCPINR.length!=0 && isNaN(weekendCostCPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostCPINR.focus();
				return false;
			}
			if(weekendCostMAPINR.length!=0 && isNaN(weekendCostMAPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostMAPINR.focus();
				return false;
			}
			if(weekendCostAPINR.length!=0 && isNaN(weekendCostAPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostAPINR.focus();
				return false;
			}
			if(weekendCostEPUSD.length!=0 && isNaN(weekendCostEPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostEPUSD.focus();
				return false;
			}
			if(weekendCostCPUSD.length!=0 && isNaN(weekendCostCPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostCPUSD.focus();
				return false;
			}
			if(weekendCostMAPUSD.length!=0 && isNaN(weekendCostMAPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostMAPUSD.focus();
				return false;
			}
			if(weekendCostAPUSD.length!=0 && isNaN(weekendCostAPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostAPUSD.focus();
				return false;
			}
		}
	}
	else if(packageTypeIND==1)
	{
		if((packageCostEPINR.length==0 || packageCostEPINR==0) && (packageCostCPINR.length==0 || packageCostCPINR==0) && (packageCostMAPINR.length==0 || packageCostMAPINR==0) && (packageCostAPINR.length==0 || packageCostAPINR==0))
		{
			alert("Please enter at lest one package cost.");
			theForm.packageCostEPINR.focus();
			return false;
		}
		if(packageCostEPINR.length!=0 && isNaN(packageCostEPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostEPINR.focus();
			return false;
		}
		if(packageCostCPINR.length!=0 && isNaN(packageCostCPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostCPINR.focus();
			return false;
		}
		if(packageCostMAPINR.length!=0 && isNaN(packageCostMAPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostMAPINR.focus();
			return false;
		}
		if(packageCostAPINR.length!=0 && isNaN(packageCostAPINR))
		{
			alert("Please enter numeric value.");
			theForm.packageCostAPINR.focus();
			return false;
		}
		if(weekEnd.checked==true)
		{
			if((weekendCostEPINR.length==0 || weekendCostEPINR==0) && (weekendCostCPINR.length==0 || weekendCostCPINR==0) && (weekendCostMAPINR.length==0 || weekendCostMAPINR==0) && (weekendCostAPINR.length==0 || weekendCostAPINR==0))
			{
				alert("Please enter at lest one weekend package cost.");
				theForm.weekendCostEPINR.focus();
				return false;
			}
			if(weekendCostEPINR.length!=0 && isNaN(weekendCostEPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostEPINR.focus();
				return false;
			}
			if(weekendCostCPINR.length!=0 && isNaN(weekendCostCPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostCPINR.focus();
				return false;
			}
			if(weekendCostMAPINR.length!=0 && isNaN(weekendCostMAPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostMAPINR.focus();
				return false;
			}
			if(weekendCostAPINR.length!=0 && isNaN(weekendCostAPINR))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostAPINR.focus();
				return false;
			}
		}
	}
	else
	{
		if((packageCostEPUSD.length==0 || packageCostEPUSD==0)&& (packageCostCPUSD.length==0 || packageCostCPUSD==0) && (packageCostMAPUSD.length==0 || packageCostMAPUSD==0) && (packageCostAPUSD.length==0 || packageCostAPUSD==0))
		{
			alert("Please enter at lest one package cost.");
			theForm.packageCostEPUSD.focus();
			return false;
		}
		if(packageCostEPUSD.length!=0 && isNaN(packageCostEPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostEPUSD.focus();
			return false;
		}
		if(packageCostCPUSD.length!=0 && isNaN(packageCostCPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostCPUSD.focus();
			return false;
		}
		if(packageCostMAPUSD.length!=0 && isNaN(packageCostMAPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostMAPUSD.focus();
			return false;
		}
		if(packageCostAPUSD.length!=0 && isNaN(packageCostAPUSD))
		{
			alert("Please enter numeric value.");
			theForm.packageCostAPUSD.focus();
			return false;
		}
		if(weekEnd.checked==true)
		{
			if((weekendCostEPUSD.length==0 || weekendCostEPUSD==0) && (weekendCostCPUSD.length==0 || weekendCostCPUSD==0) && (weekendCostMAPUSD.length==0 || weekendCostMAPUSD==0) && (weekendCostAPUSD.length==0 || weekendCostAPUSD==0))
			{
				alert("Please enter at lest one weekend package cost.");
				theForm.weekendCostEPUSD.focus();
				return false;
			}
			if(weekendCostEPUSD.length!=0 && isNaN(weekendCostEPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostEPUSD.focus();
				return false;
			}
			if(weekendCostCPUSD.length!=0 && isNaN(weekendCostCPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostCPUSD.focus();
				return false;
			}
			if(weekendCostMAPUSD.length!=0 && isNaN(weekendCostMAPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostMAPUSD.focus();
				return false;
			}
			if(weekendCostAPUSD.length!=0 && isNaN(weekendCostAPUSD))
			{
				alert("Please enter numeric value.");
				theForm.weekendCostAPUSD.focus();
				return false;
			}
		}
	}
}

//DHTML Form Handling
function formUpdate(theForm)
{
	var weekEnd = theForm.weekEnd;
	if(weekEnd.checked==true)
		weekendPrice.style.display = "block";	
	else
		weekendPrice.style.display = "none";	
}

/*FUNCTION FOR TESTIMONIAL */

function checkTestimonial(theForm)
{
	var name = trim(theForm.name.value);
	var countryId = trim(theForm.countryId.value);
	var visitedLocation = trim(theForm.visitedLocation.value);
	var comments = trim(theForm.comments.value);
	var rating = trim(theForm.rating.value);

	var submit_date_dd = trim(theForm.submit_date_dd.value);
	var submit_date_mm = trim(theForm.submit_date_mm.value);
	var submit_date_yyyy = trim(theForm.submit_date_yyyy.value);
//	var subject = trim(theForm.subject.value);

	if(name.length==0)
	{
		alert("Please enter name!");
		theForm.name.focus();
		return false;
	}
	if(submit_date_dd.length==0 || submit_date_yyyy.length==0 || submit_date_yyyy.length==0)
	{
		alert("Please select date!");
		theForm.submit_date_dd.focus();
		return false;		
	}
	var today = getCurrentDate();
	var date = submit_date_yyyy+"-"+submit_date_mm+"-"+submit_date_dd;
	if(date>today)
	{
		alert("Send Date should not be future date!");
		theForm.submit_date_dd.focus();
		return false;
	}
	if(countryId.length==0)
	{
		alert("Please select country!");
		theForm.countryId.focus();
		return false;
	}
	if(visitedLocation.length==0)
	{
		alert("Please enter visit location!");
		theForm.visitedLocation.focus();
		return false;
	}
/*	if(subject.length==0)
	{
		alert("Please enter subject!");
		theForm.subject.focus();
		return false;
	}
	if(comments.length==0)
	{
		alert("Please enter Description!");
		theForm.comments.focus();
		return false;
	}
	if(rating.length==0)
	{
		alert("Please enter rating!");
		theForm.rating.focus();
		return false;
	}
*/
	if(rating.length>0)
	{
		if(isNaN(rating))
		{
			alert("Please enter valid rating!");
			theForm.rating.select();
			return false;
		}
	}
	return true;
}

/*NEW FUNCTION*/

/*FUNCTION FOR CATEGORY MASTER*/
function checkCatMaster(theForm)
{
	
	var categoryName = trim(theForm.categoryName.value);
	var metaTitle = trim(theForm.metaTitle.value);
	
	if(categoryName.length==0)
	{
		alert("Please enter category name!");
		theForm.categoryName.focus();
		return false;
	}
	if(metaTitle.length==0)
	{
		alert("Please enter meta Title!");
		theForm.metaTitle.focus();
		return false;
	}
	
	return true;
}
function checkIncludeMaster(theForm)
{
	var stateID = theForm.stateID.value;
	var includeName = trim(theForm.includeName.value);
	var includeLink = trim(theForm.includeLink.value);
		
	if(stateID.length==0)
	{
		alert("Please select state name!");
		theForm.stateID.focus();
		return false;
	}
	if(includeName.length==0)
	{
		alert("Please enter include name!");
		theForm.includeName.focus();
		return false;
	}
	if(includeLink.length==0)
	{
		alert("Please enter include link!");
		theForm.includeLink.focus();
		return false;
	}
	if(notValidPath(includeLink))
	{
		alert("Please enter valid link!");
		theForm.includeLink.focus();
		return false;
	}
	
	return true;
}
function checkLaunchManager(theForm)
{
	var includeName = trim(theForm.includeName.value);
	var includeLink = trim(theForm.includeLink.value);
	
	if(includeName.length==0)
	{
		alert("Please enter include name!");
		theForm.includeName.focus();
		return false;
	}
	if(includeLink.length==0)
	{
		alert("Please enter include link!");
		theForm.includeLink.focus();
		return false;
	}
	if(notValidPath(includeLink))
	{
		alert("Please enter valid link!");
		theForm.includeLink.select();
		return false;
	}
	return true;
}
/*FUNCTION FOR STATE MANAGER*/
function checkStateMaster(theForm)
{
	
	var stateName = trim(theForm.stateName.value);
	var metaTitle = trim(theForm.metaTitle.value);
	if(stateName.length==0)
	{
		alert("Please enter state name!");
		theForm.stateName.focus();
		return false;
	}
	if(metaTitle.length==0)
	{
		alert("Please enter  meta title!");
		theForm.metaTitle.focus();
		return false;
	}
	return true;
}

/*FUNCTION FOR ACTIVITY MANAGER*/
function checkActivityMaster(theForm)
{
	var activityName = trim(theForm.activityName.value);

	if(activityName.length==0)
	{
		alert("Please enter activity name!");
		theForm.activityName.focus();
		return false;
	}
		
	return true;
}
/*FUNCTION FOR NEWS MANAGER*/
function checkNewsManager(theForm)
{
	var newsTitle = trim(theForm.newsTitle.value);
	var catID = theForm['catID[]'];
	var newsSum = trim(theForm.newsSum.value);	
	var dd = trim(theForm.newsDate_dd.value);
	var mm = trim(theForm.newsDate_mm.value);
	var yy = trim(theForm.newsDate_yyyy.value);
	if(newsTitle.length==0)
	{
		alert("Please enter news title!");
		theForm.newsTitle.focus();
		return false;
	}	
	if(catID.value.length == 0)
	{
		alert("Please select category!");
		return false;
	}
	if(newsSum.length==0)
	{
		alert("Please enter news summary!");
		theForm.newsSum.focus();
		return false;
	}
	if(dd.length>0 && mm.length>0 && yy.length>0)
	{
		if(!dateValid(dd, mm, yy))
		{
			alert("Please select valid date!");
			theForm.newsDate_dd.focus();
			return false;
		}
	}
	return true;
}


function onlineHotelForm(theForm)
{
	var hotel_id = trim(theForm.hotel_id.value);
	var hotelName = trim(theForm.hotelName.value);
	var city_id = trim(theForm.city_id.value);
	var accommodation = trim(theForm.accommodation.value);
	var meta_title = trim(theForm.meta_title.value);
	var hotel_services = trim(theForm.hotel_services.value);

	if(hotel_id.length==0)
	{
		alert("Please select Hotel Name!");
		theForm.hotel_id.focus();
		return false;
	}
	if(hotelName.length==0)
	{
		alert("Please enter Hotel Name !");
		theForm.hotelName.focus();
		return false;
	}
	if(accommodation.length==0)
	{
		alert("Please enter Hotel Accommodation !");
		theForm.accommodation.focus();
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Please enter Meta Title !");
		theForm.meta_title.focus();
		return false;
	}
	if(hotel_services.length==0)
	{
		alert("Please enter Hotel Services !");
		theForm.hotel_services.focus();
		return false;
	}
	return true;
}


/* FOR PACKAGES*/

function addNewRow(rowId, costRowId)
{
	var rowId = document.getElementById(rowId);
	var costRowId = document.getElementById(costRowId);

	rowId.style.display = 'block';
	costRowId.style.display = 'block';
}

function removeRow(rowId, costRowId, i)
{
	var rowId = document.getElementById(rowId);
	var costRowId = document.getElementById(costRowId);
	rowId.style.display = 'none';
	costRowId.style.display = 'none';

	document.packageForm['pricelist['+i+']'].value = '';
}

function checkHotelPrice(theForm)
{
	var cityID 		= theForm.cityID.value;
	var hotelID 	= theForm.hotelId.value;
	var priceRange 	= theForm.priceRange.value;
	
	if(cityID.length == 0)
	{
		alert("Please Select city!");
		theForm.cityID.focus();
		return false;
	}
	
	if(hotelID.length == 0)
	{
		alert("Please Select Hotel!");
		theForm.hotelId.focus();
		return false;
	}
	
	if(priceRange.length == 0)
	{
		alert("Please Select Price!");
		theForm.priceRange.focus();
		return false;
	}
	return true;
}


/*
NEw Function for domestic package*/
function checkDomesticPackage(theForm)
{
	var cityId = theForm.cityId.value;
	var hotelId = theForm.hotelId.value;
	var catId = theForm.catId.value;
	var startDate = theForm.startDate.value;
	var endDate = theForm.endDate.value;

	var isIndian = theForm.isIndian;
	var isNonIndian = theForm.isNonIndian;
	var nights = theForm.nights.value;

	if(cityId.length==0)
	{
		alert("Please select a city name.");
		theForm.cityId.focus();
		return false;
	}
	if(hotelId.length==0)
	{
		alert("Please select a hotel name.");
		theForm.hotelId.focus();
		return false;
	}
	
	if(catId.length==0)
	{
		alert("Please select a Package Type.");
		theForm.catId.focus();
		return false;
	}
	if(startDate.length==0)
	{
		alert("Please select a from date.");
		theForm.startDate.focus();
		return false;
	}
	if(endDate.length==0)
	{
		alert("Please select a till date.");
		theForm.endDate.focus();
		return false;
	}

	if(isIndian.checked==false && isNonIndian.checked==false)
	{
		theForm.isIndian.focus();
		alert("Please tick at least one Package Type.");
		return false;
	}
	if((nights.length!=0 && parseInt(nights)!=nights) || (nights.length!=0 && nights<=0))
	{
		alert("Please enter Nights in Integer value.");
		theForm.nights.select();
		return false;
	}
}


/*FUNCITON FOR INTERNAITONAL PACKAGE*/
function checkIntPackage(thisForm)
{
	var packName		= trim(thisForm.packName.value);
	var no_of_nights	= trim(thisForm.no_of_nights.value);
	var ctArr			= thisForm['ctArr[]'];
	var startDate		= trim(thisForm.startDate.value);
	var endDate			= trim(thisForm.endDate.value);
	var packInclusion	= trim(thisForm.packInclusion.value);
	var packExclusion	= trim(thisForm.packExclusion.value);

	if(packName.length==0)
	{
		alert("Please enter package name");
		thisForm.packName.focus();
		return false;
	}
	if(no_of_nights.length==0)
	{
		alert("Please enter Total night");
		thisForm.no_of_nights.focus();
		return false;
	}
	if(isNaN(no_of_nights))
	{
		alert("Please enter valid Total night");
		thisForm.no_of_nights.select();
		return false;
	}
	if(ctArr.value.length==0)
	{
		alert("Please select country!");
		return false;
	}
	if(startDate.length==0)
	{
		alert("Please select start date");
		thisForm.startDate.focus();
		return false;
	}
	if(endDate.length==0)
	{
		alert("Please enter end date");
		thisForm.endDate.focus();
		return false;
	}
	if(startDate>endDate)
	{
		alert("Please enter valid end date");
		thisForm.endDate.focus();
		return false;	
	}
	if(packInclusion.length==0)
	{
		alert("Please enter package Inclusions");
		thisForm.packInclusion.focus();
		return false;
	}
	if(packExclusion.length==0)
	{
		alert("Please enter package Exclusions");
		thisForm.packExclusion.focus();
		return false;
	}
	return true;
}


