/* 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 valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {
			cnt = i; 
			i = -1;
		}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

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 == "_") continue;
			return true;
		}
	}
	return false;
}
function isValidEmail(emailid){		
	var l=emailid.length;
	if(l==0)
		return false;	
	if(l!=0)
	{
		var a=emailid.indexOf('@');
		var d=emailid.lastIndexOf('.');
		var str1=emailid.substr(0, a);
		var str2=emailid.substr(a+1, d-a-1);
		var str3=emailid.substr(d+1, l);
		var len1=str1.length;
		var len2=str2.length;
		var len3=str3.length;
		if(a<0 || d<2)
		{
			alert ("Check for missing '@' or '.' ");
			return false;
		}
		else if (a>d)
		{
			alert ("Invalid email. Please enter correct email address");
			return false;
		}				
		if (len1<=1 || len2<=1 || len3 <=1)
		{
			alert ("Invalid email. Please enter correct email address");
			return false;
		}				
	}
	return true;
}

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(isValidEmail(email_1) == 0)
	{
		document.membersForm.email_1.focus();
		return false;		  
	}	  
	return true;
}
function checkUpdatePass(membersForm)
{
	var member = trim(membersForm.loginId.value);
	if(member.length == 0)
	{
		alert("Please enter login-ID!");
		membersForm.loginId.focus();
		return false;
	}
	var member = membersForm.loginId.value;
	if(member.length < 5)
	{
		alert("Login ID should be atleast 5 characters!");
		membersForm.loginId.focus();
		return false;
	}
	if(isNotID(member))
	{
		alert("Invalid characters in login-ID!");
		membersForm.loginId.focus();
		return false;
	}
	//Password Validation
	var password = trim(membersForm.password.value);
	if(password.length == 0)
	{
		alert("Please enter password!");
		membersForm.password.focus();
		return false;
	}
	var password = membersForm.password.value;
	if(password.length < 6)
	{
		alert("Password should be atleast Six(6) Characters!");
		membersForm.password.focus();
		return false;
	}
	if(isNotID(password))
	{
		alert("Invalid characters in password!");
		membersForm.password.focus();
		return false;
	}

	//Confirm Password
	var confirm_password = membersForm.confirm_password.value;
	if(password != confirm_password)
	{
		alert("Password & confirm password mismatch!");
		membersForm.confirm_password.focus();
		return false;
	}	
}
function checkUpdateUser(membersForm)
{
	//First Name
	var fname = trim(membersForm.name.value);
	if(fname.length == 0)
	{
		alert("Please enter name!");
		membersForm.name.focus();
		return false;
	}

	//Address
	var address_1 = trim(membersForm.address_1.value);
	if(address_1.length == 0)
	{
		alert("Please enter address line - 1!");
		membersForm.address_1.focus();
		return false;
	}
	//Country		  		  
	var country = membersForm.country.value;
	if(country.length == 0)
	{
		alert("Please select users country!");
		membersForm.country.focus();
		return false;
	}
	//Email		  
	var email_1 = trim(membersForm.email_1.value);
	if(email_1.length>0)
	{
		if(checkEmail(email_1) == false)
		{
			alert("Invalid e-mail address! Please re-enter.");
			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;
	//document.getElementById(msg).innerText = maxLength-thisArea.value.length;
}

//check Category form
function checkCategory(theForm)
{
	var cat_name = trim(theForm.cat_name.value);
	/*var meta_title = trim(theForm.meta_title.value);
	var meta_desc = trim(theForm.meta_desc.value);
	var description = trim(theForm.description.value);*/
	if(cat_name.length==0)
	{
		alert("Category Name should not be empty!");
		theForm.cat_name.focus();
		return false;
	}
	/*if(meta_title.length==0)
	{
		alert("Meta Title should not be empty!");
		theForm.meta_title.focus();
		return false;
	}
	if(meta_desc.length==0)
	{
		alert("Meta desc should not be empty!");
		theForm.meta_desc.focus();
		return false;
	}
	if(description.length==0)
	{
		alert("Description should not be empty!");
		theForm.description.focus();
		return false;
	}*/
	return true;
}
function checkMainCategory(theForm)
{
	var mainCatName = trim(theForm.mainCatName.value);
	
	if(mainCatName.length==0)
	{
		alert("Category Name should not be empty!");
		theForm.mainCatName.focus();
		return false;
	}
	return true;
}
function checkMainSubCategory(theForm)
{
	var subCatName 	= trim(theForm.subCatName.value);
	var mainCatID 	= theForm.mainCatID.value;
	
	if(subCatName.length==0)
	{
		alert("Sub Category Name should not be empty!");
		theForm.subCatName.focus();
		return false;
	}
	if(mainCatID.length==0)
	{
		alert("Please Select main Category");
		theForm.mainCatID.focus();
		return false;
	}
	return true;
}
function setTitle(val, title, desc)
{
	title=document.getElementById(title);
	desc=document.getElementById(desc);
	title.value=val;
	desc.value=val;
}

//check Venue form
function checkVenue(theForm)
{
	var venueName = trim(theForm.venueName.value);
	var countryID = trim(theForm.countryID.value);
	var city = trim(theForm.city.value);
	var email = trim(theForm.email.value);
	var website = trim(theForm.website.value);
	var meta_title = trim(theForm.meta_title.value);

	if(venueName.length==0)
	{
		alert("Venue Name should not be empty!");
		theForm.venueName.focus();
		return false;
	}
	
	if(countryID.length==0)
	{
		alert("Country should not be empty!");
		theForm.countryID.focus();
		return false;
	}
	
	if(city.length==0)
	{
		alert("City should not be empty!");
		theForm.city.focus();
		return false;
	}
	
	if(email.length>0)
	{
		if(checkEmail(email) == false)
		{
			alert("Invalid email! Please re-enter.");
			theForm.email.select();
			return false;
		}
	}
	if(website.length>0)
	{
		if(notValidsite(website))
		{
			alert("Invalid URL! Please re-enter.");
			theForm.website.select();
			return false;
		}
	}
	if(meta_title.length==0)
	{
		alert("Meta Title should not be empty!");
		theForm.meta_title.focus();
		return false;
	}
	return true;
}
//check Organizer form
function checkOrganizer(theForm)
{
	var organizerName = trim(theForm.organizerName.value);
	var email = trim(theForm.email.value);
	var website = trim(theForm.website.value);
	var meta_title = trim(theForm.meta_title.value);

	if(organizerName.length==0)
	{
		alert("Organizer Name should not be empty!");
		theForm.organizerName.focus();
		return false;
	}
	
	if(email.length>0)
	{
		if(checkEmail(email) == false)
		{
			alert("Invalid email! Please re-enter.");
			theForm.email.select();
			return false;
		}
	}
	if(website.length>0)
	{
		if(notValidsite(website))
		{
			alert("Invalid URL! Please re-enter.");
			theForm.website.select();
			return false;
		}
	}
	if(meta_title.length==0)
	{
		alert("Meta Title should not be empty!");
		theForm.meta_title.focus();
		return false;
	}
	return true;
}
//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;
}

//CHECK TRADE SHOWS FORM
function checkTradeShows(theForm)
{
	
	var showsTitle = trim(theForm.showsTitle.value);
	var venueID = trim(theForm.venueID.value);
	var period = trim(theForm.period.value);
	var countryID = theForm.countryID.value;
	var cityID = theForm.cityID.value;
	var new_venue = trim(theForm.new_venue.value);
	var category_id = theForm['category_id[]'];
	var meta_title = trim(theForm.tlt1.value);
	var meta_title1 = trim(theForm.tlt2.value);
	var meta_title2 = trim(theForm.tlt3.value);
	var meta_desc = trim(theForm.meta_desc.value);
	var source = theForm.source.value;

	if(showsTitle.length==0)
	{
		alert("Please enter shows title!");
		theForm.showsTitle.focus();
		return false;
	}
	dd1=theForm.startDate_dd.value;
	mm1=theForm.startDate_mm.value;
	yy1=theForm.startDate_yyyy.value;
	dd2=theForm.closeDate_dd.value;
	mm2=theForm.closeDate_mm.value;
	yy2=theForm.closeDate_yyyy.value;
	var dt=0;
	
	if(dd1.length>0 && mm1.length>0 && yy1.length>0)
	{
		dt=1;
		if(!dateValid(dd1, mm1, yy1))
		{
			alert("Please select valid start date!");
			theForm.startDate_dd.focus();
			return false;
		}
		var today=getCurrentDate();
		var date=yy1+"-"+mm1+"-"+dd1;
		if(date<today)
		{
			alert("Please enter prospective event only!")
			theForm.startDate_dd.focus();
			return false;
		}
	}
	if(mm1.length>0 && yy1.length>0)
	{
		dt=1;
	}

	if(dt==0 && period.length==0)
	{
		alert("Please enter start date 'OR' period!");
		theForm.startDate_dd.focus();
		return false;
	}
	if(dd2.length>0 && mm2.length>0 && yy2.length>0)
	{
		if(!dateValid(dd2, mm2, yy2))
		{
			alert("Please select valid close date!");
			theForm.closeDate_dd.focus();
			return false;
		}
		if(!dateDiff(dd1, mm1, yy1, dd2, mm2, yy2))
		{
			alert("Please enter valid date difference between Start Date and Close Date!");
			theForm.closeDate_dd.focus();
			return false;
		}
	}
	if(countryID.length==0)
	{
		alert("Please select country!");
		theForm.countryID.focus();
		return false;
	}
	if(cityID.length==0)
	{
		alert("Please select city!");
		theForm.cityID.focus();
		return false;
	}
	if(venueID.length==0 && new_venue.length==0)
	{
		alert("Please select venue!");
		theForm.venueID.focus();
		return false;
	}
	if(venueID=="other")
	{
		if(new_venue.length==0)
		{
			alert("Please enter new venue!");
			theForm.new_venue.focus();
			return false;
		}
	}
	if(category_id.value.length==0)
	{
		alert("Please select category!");
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Please enter meta title!");
		theForm.meta_title.focus();
		return false;
	}
	if(meta_desc.length==0)
	{
		theForm.meta_desc.value=meta_title;
		if(meta_title1.length>0)
			theForm.meta_desc.value=theForm.meta_desc.value+" - "+meta_title1;
		if(meta_title2.length>0)
			theForm.meta_desc.value=theForm.meta_desc.value+" - "+meta_title2;
	}
	if(source.length==0)
	{
		alert("Please enter source!");
		theForm.source.focus();
		return false;
	}

	return true;
}
//CHECK TRADE SHOWS FORM
function checkTradeShowsUpdate(theForm)
{
	var showsTitle = trim(theForm.showsTitle.value);
	var eventProfile = trim(theForm.eventProfile.value);
	var venueID = trim(theForm.venueID.value);
	var meta_title = trim(theForm.meta_title.value);
	var meta_desc = trim(theForm.meta_desc.value);
	var period = trim(theForm.period.value);
	var new_venue = trim(theForm.new_venue.value);
	var cityID = theForm.cityID.value;
	var countryID = theForm.countryID.value;
	var category_id = theForm['category_id[]'];

	if(showsTitle.length==0)
	{
		alert("Please enter shows title!");
		theForm.showsTitle.focus();
		return false;
	}
	dd1=theForm.startDate_dd.value;
	mm1=theForm.startDate_mm.value;
	yy1=theForm.startDate_yyyy.value;
	dd2=theForm.closeDate_dd.value;
	mm2=theForm.closeDate_mm.value;
	yy2=theForm.closeDate_yyyy.value;
	var dt=0;
	
	if(dd1.length>0 && mm1.length>0 && yy1.length>0)
	{
		dt=1;
		if(!dateValid(dd1, mm1, yy1))
		{
			alert("Please select valid start date!");
			theForm.startDate_dd.focus();
			return false;
		}
/*		var today=getCurrentDate();
		var date=yy1+"-"+mm1+"-"+dd1;
		if(date<today)
		{
			alert("Please enter prospective event only!")
			theForm.startDate_dd.focus();
			return false;
		}*/
	}
	if(mm1.length>0 && yy1.length>0)
	{
		dt=1;
	}

	if(dt==0 && period.length==0)
	{
		alert("Please enter start date 'OR' period!");
		theForm.startDate_dd.focus();
		return false;
	}
	if(dd2.length>0 && mm2.length>0 && yy2.length>0)
	{
		if(!dateValid(dd2, mm2, yy2))
		{
			alert("Please select valid close date!");
			theForm.closeDate_dd.focus();
			return false;
		}
		if(!dateDiff(dd1, mm1, yy1, dd2, mm2, yy2))
		{
			alert("Please enter valid date difference between Start Date and Close Date!");
			theForm.closeDate_dd.focus();
			return false;
		}
	}
	if(eventProfile.length==0)
	{
		alert("Please enter event profile!");
		theForm.eventProfile.focus();
		return false;
	}
	if(countryID.length==0)
	{
		alert("Please select country!");
		theForm.countryID.focus();
		return false;
	}
	if(cityID.length==0)
	{
		alert("Please select city!");
		theForm.cityID.focus();
		return false;
	}
	if(venueID.length==0 && new_venue.length==0)
	{
		alert("Please select venue!");
		theForm.venueID.focus();
		return false;
	}
	if(venueID=="other")
	{
		if(new_venue.length==0)
		{
			alert("Please enter new venue!");
			theForm.new_venue.focus();
			return false;
		}
	}
	
	if(category_id.value.length==0)
	{
		alert("Please select category!");
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Please enter meta title!");
		theForm.meta_title.focus();
		return false;
	}
	
	if(meta_desc.length==0)
	{
		theForm.meta_desc.value=meta_title;
	}
	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 validityHotel(theForm)
{
	var hotelName = trim(theForm.hotelName.value);
	var hotelURL = trim(theForm.hotelURL.value);
	var ratingID = trim(theForm.ratingID.value);
	var countryID = trim(theForm.countryID.value);
	
	if(hotelName.length == 0)
	{
		alert("Hotel Name field can't be blank.");
		theForm.hotelName.focus();
		return false;
	}
	if(hotelURL.length==0)
	{
		alert("Hotel URL field can't be blank.");
		theForm.hotelURL.focus();
		return false;
	}
	if(notValidsite(hotelURL))
	{
		alert("Invalid URL! Please re-enter.");
		theForm.hotelURL.select();
		return false;
	}
	if(ratingID.length==0)
	{
		alert("Please Select Category/Rating.");
		theForm.ratingID.focus();
		return false;
	}
	if(countryID.length==0)
	{
		alert("Please Select Country Name.");
		theForm.countryID.focus();
		return false;
	}
	return true;
}
function checkSearchValidity()
{
	var cityName=document.form_search.cityName.value;
	var countryID=document.form_search.countryID.value;
	var keyword=document.form_search.hotelname.value;
	var status=document.form_search.status.value;

	if((cityName.length==0) && (countryID.length==0) && (keyword.length==0) && (status.length==0))
	{
		alert("You must fill at least one Field for searching.");
		document.form_search.cityName.focus()
		return false;
	}
}
//check trade searcing form
function checkTradeSearch(theForm)
{
	var v1, v2, v3, v4, v5, v6, v7, v8, dd1, dd2, mm1, mm2, yy1, yy2,test=0;
	v1=theForm.search_title.value;
	v2=theForm.search_status.value;
	v3=theForm.search_city.value;
	v4=theForm.search_country.value;
	v5=theForm.search_venue.value;
	v6=theForm.search_category.value;
	v7=theForm.searchOrgID.value;
	v8=theForm.search_userID.value;
	v9=theForm.search_checked;
                  
	dd1=theForm.start_Date_dd.value;
	mm1=theForm.start_Date_mm.value;
	yy1=theForm.start_Date_yyyy.value;
	dd2=theForm.close_Date_dd.value;
	mm2=theForm.close_Date_mm.value;
	yy2=theForm.close_Date_yyyy.value;

	var btn = valButton(v9);
	
	if(dd1.length>0 && mm1.length>0 && yy1.length>0)
	{
		test=1;
		if(!dateValid(dd1, mm1, yy1))
		{
			alert("Please Enter Valid Start Date !");
			theForm.start_Date_dd.focus();
			return false;
		}
	}

	if(dd2.length>0 && mm2.length>0 && yy2.length>0)
	{
		test=1;
		if(!dateValid(dd2, mm2, yy2))
		{
			alert("Please Enter Valid To Date!");
			theForm.close_Date_dd.focus();
			return false;
		}
	}

                 
	if(test==0 && v1.length==0 && v2.length==0 && v3.length==0 && v4.length==0 && v5.length==0 && v6.length==0 && v7.length==0 && v8.length==0 && btn == null)
	{
		alert("You must fill at least one Field for searching.");
		theForm.search_title.focus();
		return false;
	}
}
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 checkAnnounce(theForm)
{
	var email_to= document.catForm['email_to[0]'];
	var email_from = trim(theForm.email_from.value);
	var name_from = trim(theForm.name_from.value);
	email_to=trim(email_to.value);
	var email1= document.catForm['email_to[1]'];
	var email2= document.catForm['email_to[2]'];
	var email3= document.catForm['email_to[3]'];
	var email4= document.catForm['email_to[4]'];
	var req_imageCode = trim(theForm.req_imageCode.value);
	email1= trim(email1.value);
	email2= trim(email2.value);
	email3= trim(email3.value);
	email4= trim(email4.value);
	
	if(email_to.length==0)
	{
		alert("Please enter your friend's e-mail!");
		document.catForm['email_to[0]'].focus();
		return false;
	}
	if(checkEmail(email_to) == false)
	{
		alert("Invalid e-mail address! Please re-enter.");
		document.catForm['email_to[0]'].select();
		return false;		  
	}
	if(email1.length>0)
	{
		if(checkEmail(email1) == false)
		{
			alert("Invalid e-mail address! Please re-enter.");
			document.catForm['email_to[1]'].select();
			return false;		  
		}
	}
	if(email2.length>0)
	{
		if(checkEmail(email2) == false)
		{
			alert("Invalid e-mail address! Please re-enter.");
			document.catForm['email_to[2]'].select();
			return false;		  
		}
	}
	if(email3.length>0)
	{
		if(checkEmail(email3) == false)
		{
			alert("Invalid e-mail address! Please re-enter.");
			document.catForm['email_to[3]'].select();
			return false;
		}
	}
	if(email4.length>0)
	{
		if(checkEmail(email4) == false)
		{
			alert("Invalid e-mail address! Please re-enter.");
			document.catForm['email_to[4]'].select();
			return false;		  
		}
	}

	if(email_from.length==0)
	{
		alert("Please enter your e-mail!");
		theForm.email_from.focus();
		return false;
	}
	if(checkEmail(email_from) == false)
	{
		alert("Invalid your e-mail! Please re-enter.");
		theForm.email_from.select();
		return false;		  
	}
	if(name_from.length==0)
	{
		alert("Please enter your name!");
		theForm.name_from.focus();
		return false;
	}
	if(req_imageCode.length==0)
	{
		alert("Please enter image code!");
		theForm.req_imageCode.focus();
		return false;
	}
	return true;
}

function getFieldvalue(val1, val2, val3, val4, val5, val6, val7)
{
removeForm.upd_fieldName.value=val1;
document.removeForm.upd_type.value=val2;
document.removeForm.upd_fileldSize.value=val3;
alert(removeForm.upd_fieldName.value);
alert(removeForm.upd_fieldSize.value);
document.removeForm.upd_fieldAttributes.value=val4;
document.removeForm.upd_fieldNull.value=val5;
document.removeForm.upd_auto.value=val6;
document.removeForm.upd_primaryKey.value=val7;
}
function checkContactForm(theForm)
{
	var message = trim(theForm.message.value);
	var name_from = trim(theForm.name_from.value);
	var email_from = trim(theForm.email_from.value);
	var country = trim(theForm.country.value);
	var req_imageCode = trim(theForm.req_imageCode.value);

	if(name_from.length==0)
	{
		alert("Please enter your name!");
		theForm.name_from.focus();
		return false;
	}
	if(email_from.length==0)
	{
		alert("Please enter your e-mail!");
		theForm.email_from.focus();
		return false;
	}
	if(checkEmail(email_from) == false)
	{
		alert("Invalid your e-mail! Please re-enter.");
		theForm.email_from.select();
		return false;		  
	}
	if(country.length==0)
	{
		alert("Please enter your country!");
		theForm.country.focus();
		return false;
	}
	if(message.length==0)
	{
		alert("Please enter message!");
		theForm.message.focus();
		return false;
	}
	
	if(req_imageCode.length<4)
	{
		alert("Please enter image code!");
		theForm.req_imageCode.focus();
		return false;
	}
	return true;
}
//CHECK TRADE SHOWS FORM
function checkEventsSubmit(theForm)
{
	
	var name_from    = trim(theForm.name_from.value);
	var email_from   = trim(theForm.email_from.value);
	var showsTitle   = trim(theForm.showsTitle.value);
	var startDate    = theForm.startDate.value;
	var closeDate  	 = theForm.closeDate.value;
	var period       = trim(theForm.period.value);
	var eventProfile = trim(theForm.eventProfile.value);
	var venueName    = trim(theForm.venueName.value);
	var countryName  = theForm.countryName.value;
	var cityName     = theForm.cityName.value;
	var req_imageCode= trim(theForm.req_imageCode.value);
	
	if(name_from.length==0)
	{
		alert("Please enter your name!");
		theForm.name_from.focus();
		return false;
	}
	if(email_from.length==0)
	{
		alert("Please enter your e-mail!");
		theForm.email_from.focus();
		return false;
	}
	if(checkEmail(email_from) == false)
	{
		alert("Invalid your e-mail! Please re-enter.");
		theForm.email_from.select();
		return false;		  
	}
	if(showsTitle.length==0)
	{
		alert("Please enter shows title!");
		theForm.showsTitle.focus();
		return false;
	}
	var dd1 = startDate.substring(0,2)
	var mm1 = startDate.substring(3,5)
	var yy1 = startDate.substring(6,10)

	var dd2 = closeDate.substring(0,2)
	var mm2 = closeDate.substring(3,5)
	var yy2 = closeDate.substring(6,10)
	var dt=0;
	
	if(dt==0 && period.length==0)
	{
	if (startDate.length==0)
	{
		
		alert("Please enter the Start Date!")
		theForm.startDate.focus();
		return false;
	}else	dt=1;

	var today = getCurrentDate();
	var date = yy1 + "-" + mm1 + "-" + dd1;
	if(date<today)
	{
		alert("Please enter valid Start Date!");
		theForm.startDate.focus();
		return false;
	}

	if (closeDate.length==0)
	{
		alert("Please enter the End date!")
		theForm.closeDate.focus();
		return false;
	}else dt=1;
	}
	if(dt==0 && period.length==0)
	{
		alert("Please enter start date 'OR' period!");
		theForm.startDate.focus();
		return false;
	}
	if(!dateDiff(dd1, mm1, yy1, dd2, mm2, yy2))
	{
		alert("Please recheck Start and End date!");
		theForm.closeDate.focus();
		return false;
	}	
	/*dd1=theForm.startDate_dd.value;
	mm1=theForm.startDate_mm.value;
	yy1=theForm.startDate_yyyy.value;
	dd2=theForm.closeDate_dd.value;
	mm2=theForm.closeDate_mm.value;
	yy2=theForm.closeDate_yyyy.value;
	var dt=0;
	
	if(dd1.length>0 && mm1.length>0 && yy1.length>0)
	{
		dt=1;
		if(!dateValid(dd1, mm1, yy1))
		{
			alert("Please select valid start date!");
			theForm.startDate_dd.focus();
			return false;
		}
		var today=getCurrentDate();
		var date=yy1+"-"+mm1+"-"+dd1;
		if(date<today)
		{
			alert("Please enter prospective event only!")
			theForm.startDate_dd.focus();
			return false;
		}
	}
	if(mm1.length>0 && yy1.length>0)
	{
		dt=1;
	}

	if(dt==0 && period.length==0)
	{
		alert("Please enter start date 'OR' period!");
		theForm.startDate_dd.focus();
		return false;
	}
	if(dd2.length>0 && mm2.length>0 && yy2.length>0)
	{
		if(!dateValid(dd2, mm2, yy2))
		{
			alert("Please select valid close date!");
			theForm.closeDate_dd.focus();
			return false;
		}
		if(!dateDiff(dd1, mm1, yy1, dd2, mm2, yy2))
		{
			alert("Please enter valid date difference between Start Date and Close Date!");
			theForm.closeDate_dd.focus();
			return false;
		}
	}*/
	if(eventProfile.length==0)
	{
		alert("Please enter event profile!");
		theForm.eventProfile.focus();
		return false;
	}
	if(countryName.length==0)
	{
		alert("Please Enter Country!");
		theForm.countryName.focus();
		return false;
	}
	if(cityName.length==0)
	{
		alert("Please Enter city!");
		theForm.cityName.focus();
		return false;
	}
	if(venueName.length==0)
	{
		alert("Please Enter Venue!");
		theForm.venueName.focus();
		return false;
	}
	if(req_imageCode.length<4)
	{
		alert("Please enter image code!");
		theForm.req_imageCode.focus();
		return false;
	}
	return true;
}
function checkArticleManager(theForm)
{
	
	var title    	= trim(theForm.title.value);
	var countryID   = trim(theForm.countryID.value);
	var metaTitle   = trim(theForm.metaTitle.value);
	//var description   = trim(theForm.description.value);
	
	if(title.length==0)
	{
		alert("Please enter title!");
		theForm.title.focus();
		return false;
	}
	
	if(countryID.length==0)
	{
		alert("Please select country!");
		theForm.title.focus();
		return false;
	}
	
	if(metaTitle.length==0)
	{
		alert("Please enter meta title!");
		theForm.metaTitle.focus();
		return false;
	}
	/*if(description.length==0)
	{
		alert("Please enter description!");
		theForm.description.focus();
		return false;
	}*/
}