function prepsel(form,fld,cas,mod) {
// mod: 0-select with conference_count>0    1-select all   2-select only states for country US (addconf)
switch (cas) {

case 'ctry': 
	if (fld.value=='US') {
		ajaxFunction(form.stat,'states','country_code',fld.value,'state_name','state_code',mod);
		if (mod!=2) ajaxFunction(form.city,'cities','no city',fld.value,'city','city_code',1);
		document.getElementById('stat').disabled=false;
	}
	else {
		if (mod!=2) ajaxFunction(form.city,'cities','country_code',fld.value,'city','city_code',mod);
		ajaxFunction(form.stat,'states','no state',fld.value,'state_name','state_code',mod);
		document.getElementById('stat').disabled=true;
	}
	break;
	
case 'ctry1': 
	if (fld.value=='US') {
		ajaxFunction(form.stat,'states','country_code',fld.value,'state_name','state_code',mod);
		if (mod!=2) ajaxFunction(form.city,'cities','no city',fld.value,'city','city_code',1);
		document.getElementById('stat1').disabled=false;
	}
	else {
		if (mod!=2) ajaxFunction(form.city,'cities','country_code',fld.value,'city','city_code',mod);
		ajaxFunction(form.stat,'states','no state',fld.value,'state_name','state_code',mod);
		document.getElementById('stat1').disabled=true;
	}
	break;
		
case 'stat':
	ajaxFunction(form.city,'cities','state_code',fld.value,'city','city_code',mod);
	break;

case 'cat':
	ajaxFunction(form.subj,'subjects','category_code',fld.value,'subject','subject_code',mod);
	break;

case 'ncat1':
	ajaxFunction(form.nsubj1,'subjects','category_code',fld.value,'subject','subject_code',mod);
	break;
	
case 'city':
	ajaxFunction(form.ven,'venues','city_code',fld.value,'venue','venue_code',mod);
	break;

case 'orgz':
	ajaxFunction(form.ver,'org_versions','org_code',fld.value,'version','version',mod);
	break;
	
default:
	break;
	
}
}

function ajaxFunction(selectbox,tab,fld1,val,fld2,key,mod){
	// tab=table, fld1=field for select, val=value of fld1 for select, fld2/key=for output
	// mod=0-select only items with conferences 1-select all items 2-used for addconf
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	//var url=phpfunc+"?dbt="+dbt"&code="+ccode;
	var url="changeselect.php?tab="+tab+"&fld1="+fld1+"&val="+val+"&fld2="+fld2+"&key="+key;
	if (mod==0) url=url+"&mod=0";
	if (mod==1 || mod==2) url=url+"&mod=1";
	if (fld1=='no city') {
		removeAllOptions(selectbox);
		addOption(selectbox, "0", "All", "");
		return;
	}
	if (fld1=='no state') {
		removeAllOptions(selectbox);
		addOption(selectbox, "-1", " ", "");
		return;
	}
// Create a function that will receive data sent from the server

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			removeAllOptions(selectbox);
			if (tab=='states' && val!='US') {
				addOption(selectbox, "-1", " ", "");
				return;
			}
			if (tab=='venues' || tab=='org_versions') {
				if (tab=='venues') {
					addOption(selectbox, "-1", "Choose", "");
					addOption(selectbox, "0", "Notify soon", "");
				}
				if (tab=='org_versions') {
					addOption(selectbox, "99", "All", "");
				}
			}
			else addOption(selectbox, "0", "All", "");
			
			createOptions(selectbox,ajaxRequest.responseText);

		}
	};
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}

function createOptions(selectbox,str)
{
      var array = str.split(";");
      var k=0;
      for (var i = 0; i < array.length-1; i=i+2) 
      {
    	  addOption(selectbox, array[i], array[i+1], "");
      }
}

function removeAllOptions(selectbox)
{
		var i;
		selectbox.options.length = 0;
//		for(i=selectbox.options.length-1;i>=0;i--)
//		{
//			selectbox.options.remove(i);
////			selectbox.remove(i);
//		}
}

function addOption(selectbox, value, text )
{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
//		selectbox.add(optn);


}

var ie4 = false; if(document.all) { ie4 = true; }
function getObject(id)
{
	if (ie4) { return document.all[id]; } 
	else { return document.getElementById(id); }
}
function toggle(link, divId) 
{
var lText = link.innerHTML;
var d = getObject(divId);
if (lText == 'Show description') {
	link.innerHTML = 'Close description';
	d.style.display = '';
	}
else {
	link.innerHTML = 'Show description';
	d.style.display = 'none';
	}
}

function chg_text_style(link,id) 
{
var d = getObject(id);
if (link.value=="Enter any text") link.value = '';
d.style.color = 'black';
}

function fld_empty (fld,name)
{
	if (fld.value.length == 0 || fld.value=="") {
		alert("'"+name+"' is missing.");
		fld.focus();
		return true;
	}	
}

function validate_collectparams1 (form)
{
with (form)
{
	if (orgz.value == 0 && orgz1.value == 0) {
		alert("Missing Organizer");
		orgz.focus();
		return false;
	}
	if (orgz.value > 0 && orgz1.value < 0) {
		alert("Duplicate Organizer");
		orgz.focus();
		return false;
	}
}
}
function validate_collectparams2 (form)
{
with (form)
{
	if (fld.value == 0 ) {
		alert("Missing field");
		fld.focus();
		return false;
	}
	if (fldo.value == 0 ) {
		alert("Missing field order");
		fldo.focus();
		return false;
	}
	if (fldo.value == 1 && fld_empty(id1,'Identify beginnig of field')) return false;
	if (fld_empty(eid,'Identify end of field')) return false;
	if (fldt.value == 2 && dmy1.value==0 ) {
		alert("Missing 'Date format'");
		dmy1.focus();
		return false;
	}
	var warn="";
	if (id1.value.length == 0) warn=warn+"'Beginnig IDs', ";	
	if (warn!="") { 
		var answer=confirm("The following fields are missing:\n"+warn+"\nPress 'OK' to proceed or 'Cancel' to return to form");
		if (answer) return true;
		else return false;
	}
}
}
function validate_collectparams3 (form)
{
with (form)
{
	if (fld.value == 0 ) {
		alert("Missing field");
		fld.focus();
		return false;
	}
}
}
function validate_collectparams4 (form)
{
with (form)
{
	if (ver.value == 99 ) {
		alert("Must specify a version");
		orgz.focus();
		return false;
	}
}
}

function validate_org_params (orgform)
{
with (orgform)
{
	if (orgz.value == 0 ) {
		alert("Missing Organizer");
		orgz.focus();
		return false;
	}
}
}
function validate_org (orgform)
{
with (orgform)
{
	if (fld_empty(orgname,'Organizer name')) return false;
	if (fld_empty(orgweb,'Website')) return false;
	if (orgweb.value.length > 0 && !urlcheck(orgweb.value)) {
		alert("Invalid 'web' format. Should be http://www.xxx....");
		orgweb.focus();
		return false;
	}
	if (fld_empty(orgmail,'Organizer mail')) return false;
	if (orgmail.value.length > 0 && !emailcheck(orgmail.value)) {
		alert("Invalid 'Mail address' format. Should be xxx@yyy.zzz");
		orgmail.focus();
		return false;
	}
	if (freq.value.length > 0 && !numeric(freq.value)) {
		alert("'Check frequency' is not numeric");
		freq.focus();
		return false;
	}
}
}

function validate_ven_params (vform)
{
with (vform)
{
	if (ctry.value == 0) {
		alert("Missing country.");
		ctry.focus();
		return false;
	}

	if (ctry.value =='US' && stat.value <= 0) {
		alert("Missing state for USA.");
		stat.focus();
		return false;
	}
	if (city.value == 0) {
		alert("Missing 'City'.");
		city.focus();
		return false;
	}
	if (ven.value <= 0 ) {
		alert("Missing 'Venue'.");
		ven.focus();
		return false;
	}
}
}
function validate_venue (vform)
{
with (vform)
{
	if (fld_empty(vnam,'Venue name')) return false;
	if (fld_empty(vadd,'Address')) return false;
	if (vweb.value.length > 0 && !urlcheck(vweb.value)) {
		alert("Invalid 'web' format. Should be http://www.xxx....");
		vweb.focus();
		return false;
	}
	if (vmail.value.length > 0 && !emailcheck(vmail.value)) {
		alert("Invalid 'Mail address' format. Should be xxx@yyy.zzz");
		vmail.focus();
		return false;
	}
	var warn="";
	if (vweb.value.length ==0) warn="'Website', ";
	if (vmail.value.length == 0) warn=warn+"'Mail', ";	
	if (warn!="") { 
		var answer=confirm("The following fields are missing:\n"+warn+"\nPress 'OK' to proceed or 'Cancel' to return to form");
		if (answer) return true;
		else return false;
	}
}
}


function validate_contact (form)
{
with (form)
{
	if (fld_empty(name,'Your name')) return false;
	if (fld_empty(mail,'Your email address')) return false;
	if (!emailcheck(mail.value)) {
		alert("Invalid 'Mail address' format.");
		mail.focus();
		return false;
	}	
	if (fld_empty(msg,'message')) return false;	
}
}

function validate_links_update (form)
{
with (form)
{
	if (fld_empty(url,'URL')) return false;
	if (url.value.length > 0 && !urlcheck(url.value)) {
		alert("Invalid 'URL' format. Should be http://www.xxx....");
		url.focus();
		return false;
	}
	if (hdr.value.length==0 && lnk.value.length==0) {
		alert("Missing Header,Descrption or Full link tag");
		lnk.focus();
		return false;
	}
	if (hdr.value.length>0 || desc.value.length>0) {
		if (lnk.value.length>0) {
			alert("Choose between Header,Descrption or Full link tag (but not both)");
			lnk.focus();
			return false;
		}
		if (hdr.value.length>0 && fld_empty(desc,'Description')) return false;
		if (desc.value.length>0 && fld_empty(hdr,'Header')) return false;
	}	
	if (lpag.value.length > 0 && !urlcheck(lpag.value)) {
		alert("Invalid 'Link page' format. Should be http://www.xxx....");
		lpag.focus();
		return false;
	}
	if (mail.value.length > 0 && !emailcheck(mail.value)) {
		alert("Invalid 'Mail' format.");
		mail.focus();
		return false;
	}
	if (cat.value == 0) {
		alert("Missing 'Category'.");
		cat.focus();
		return false;
	}
	var warn="";
	if (lpag.value ==0) warn="'Link page', ";
	if (mail.value.length == 0) warn=warn+"'Mail', ";	
	if (warn!="") { 
		var answer=confirm("The following fields are missing:\n"+warn+"\nPress 'OK' to proceed or 'Cancel' to return to form");
		if (answer) return true;
		else return false;
	}
	return true;
}
}

function validate_add (addform)
{
with (addform)
{
	if (fld_empty(name,'Your name')) return false;
	if (fld_empty(nmail,'Your email')) return false;
	if (nmail.value.length > 0 && !emailcheck(nmail.value)) {
		alert("'Your email' format is invalid.");
		nmail.focus();
		return false;
	}
	if (fld_empty(event,'Event name')) return false;
	if (fld_empty(web,'Website')) return false;
	if (web.value.length > 0 && !urlcheck(web.value)) {
		alert("Invalid 'Website' format. Should be http://www.xxx....");
		web.focus();
		return false;
	}
	if (fld_empty(fdate,'From date')) return false;
	else {
		if (!chkdate(fdate,'From date',fdate,0)) {
			fdate.focus();	
			return false;
		}
		var d=prep_date(new Date(),0);
		if (!compare_dates(fdate.value,d)) {
			alert("'From Date' cannot be before "+d);
			fdate.focus();
			return false;
		}
	}
	if (fld_empty(tdate,'To date')) return false;
	else {
		if (!chkdate(tdate,'To date',tdate,0)) {
			tdate.focus();	
			return false;
		}
		if (!compare_dates(tdate.value,fdate.value)) {
			alert("'To Date' must be later than 'From Date'.");
			fdate.focus();
			return false;
		}
	}
	if (ctry.value == 0) {
		alert("Country is missing.");
		ctry.focus();
		return false;
	}

	if (ctry.value =='US' && stat.value <= 0) {
		alert("Missing state for USA.");
		stat.focus();
		return false;
	}
	if (city.value == 0 && ncity.value.length == 0) {
		alert("Missing 'City'.");
		city.focus();
		return false;
	}
	if (city.value != 0 && ncity.value.length != 0) {
		alert("Duplicate Cities.");
		ncity.focus();
		return false;
	}
	if (mail.value.length > 0 && !emailcheck(mail.value)) {
		alert("Invalid 'Email' format.");
		mail.focus();
		return false;
	}
	if (fpr.value.length > 0 && !numeric(fpr.value)) {
		alert("'From price' is not numeric");
		fpr.focus();
		return false;
	}
	if (tpr.value.length > 0) {
		if (!numeric(tpr.value)) {
			alert("'To price'. is not numeric");
			tpr.focus();
			return false;
		}
		if (cur.value=="") {
			alert("'Currency' is missing");
			cur.focus();
			return false;
		}	
	}
	if (tpr.value.length > 0 && fpr.value.length > 0) {
		if (parseInt(tpr.value) < parseInt(fpr.value)) {
			alert("'From price' should be lower than 'To price");
			fpr.focus();
			return false;
		}
	}
//	alert ('rl='+rdate.value.length+' pl='+pdate.value.length+' fl='+fdate.value);
	if (rdate.value.length>0) {
		if (!chkdate(rdate,'Early registration',rdate,0)) {
			rdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,rdate.value)) {
			alert("'Early registration' cannot be later than conferece begining.");
			rdate.focus();
			return false;     
		}
	}	
	if (pdate.value.length>0) {
		if (!chkdate(pdate,'Abstract submission',pdate,0)) {
			pdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,pdate.value)) {
			alert("'Abstract submission' cannot be later than conference begining.");
			pdate.focus();
			return false;     
		}
	}
}
}

function validate_create (addform)
{

with (addform)
{
	if (fld_empty(event,'Event name')) return false;
	if (fld_empty(web,'Website')) return false;
	if (web.value.length > 0 && !urlcheck(web.value)) {
		alert("Invalid 'Website' format. Should be http://www.xxx....");
		web.focus();
		return false;
	}
	if (fld_empty(fdate,'From date')) return false;
	else {
		if (!chkdate(fdate,'From date',fdate,0)) {
			fdate.focus();	
			return false;
		}
		var d=prep_date(new Date(),0);
		if (!compare_dates(fdate.value,d)) {
			alert("'From Date' cannot be before "+d);
			fdate.focus();
			return false;
		}
	}
	if (fld_empty(tdate,'To date')) return false;
	else {
		if (!chkdate(tdate,'To date',tdate,0)) {
			tdate.focus();	
			return false;
		}
		if (!compare_dates(tdate.value,fdate.value)) {
			alert("'To Date' must be later than 'From Date'.");
			fdate.focus();
			return false;
		}
	}
	
	if (ctry.value == 0) {
		alert("Missing country.");
		ctry.focus();
		return false;
	}

	if (ctry.value =='US' && stat.value <= 0) {
		alert("Missing state for USA.");
		stat.focus();
		return false;
	}
	if (city.value == 0 && ncity.value.length == 0) {
		alert("Missing 'City'.");
		city.focus();
		return false;
	}
	if (city.value != 0 && ncity.value.length != 0) {
		alert("Duplicate City and 'New city'");
		ncity.focus();
		return false;
	}
	if (ncity.value.length > 0 && (lat.value.length == 0 || long.value.length == 0)) {
		alert("Missing 'latitude' or 'longitude' for 'New city'");
		lat.focus();
		return false;
	}
	if (city.value > 0 && (lat.value.length > 0 || long.value.length > 0)) {
		alert("'latitude' and 'longitude' should be used only for 'New city'");
		lat.focus();
		return false;
	}	
	if (lat.value.length > 0 && !ltnum(lat.value)) {
		alert("Invalid 'latitude'. format should be like '12.1234567'.");
		lat.focus();
		return false;
	}
	if (long.value.length > 0 && !ltnum(long.value)) {
		alert("Invalid 'longitude'. format should be like '12.1234567'.");
		long.focus();
		return false;
	}

	if (ven.value < 0 && nven.value.length == 0) {
		alert("Missing 'Venue'.");
		ven.focus();
		return false;
	}
	if (ven.value >= 0 && nven.value.length != 0) {
		alert("Duplicate 'Venue' and 'New venue'");
		nven.focus();
		return false;
	}
	if (nven.value.length > 0) {
		if (fld_empty(add,'Address')) return false;
		if (vweb.value.length > 0 && !urlcheck(vweb.value)) {
			alert("Invalid 'Venue web' format. Should be http://www.xxx..");
			vweb.focus();
			return false;
		}
		if (vmail.value.length > 0 && !emailcheck(vmail.value)) {
			alert("Invalid 'Venue Email' format. Should be xxx@yyy.zzz");
			vmail.focus();
			return false;
		}
	}	
//	alert ('desc='+desc.value+' desc1='+document.getElementById('wysiwygdesc').value);
//	if (desc.value.length == 0 || desc.value == '<P>&nbsp;</P>') {
//		alert("Missing 'Description'.");
//      Cannot focus because textarea is taken by wyzz
//		return false;
//	}	
		
	if (cat.value == 0 && ncat.value.length == 0) {
		alert("Missing 'Category'.");
		cat.focus();
		return false;
	}
	if (cat.value > 0 && ncat.value.length > 0) {
		alert("Duplicate category.");
		cat.focus();
		return false;
	}
	if (subj.value == 0 && nsubj.value.length == 0) {
		alert("Missing subject.");
		subj.focus();
		return false;
	}
	if (subj.value > 0 && nsubj.value.length > 0) {
		alert("Duplicate subject.");
		subj.focus();
		return false;
	}


	
	if (fld_empty(fpr,'From price')) return false;
	if (fpr.value.length > 0 && !numeric(fpr.value) && parseInt(fpr.value)!=-1) {
		alert("Invalid 'From price'. should be a number");
		fpr.focus();
		return false;
	}
	if (tpr.value.length > 0 && !numeric(tpr.value)) {
		alert("Invalid 'To price'. should be a number");
		tpr.focus();
		return false;
	}
	if (tpr.value.length > 0 && fpr.value.length > 0) {
		if (parseInt(tpr.value) < parseInt(fpr.value)) {
			alert("'To price' should be higher than 'From price");
			fpr.focus();
			return false;
		}
	}
	if ((fpr.value>0 || tpr.value>0) && fld_empty(cur,'Currency')) return false;
//	if (fld_empty(exh,'Exhibition information')) return false;
//	if (exh.value ==0) {
//		alert("Missing 'Exhibition' information.");
//		exh.focus();
//		return false;
//	}
	if (rdate.value.length!=0) {
		if (!chkdate(rdate,'Early registration',rdate,0)) {
			rdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,rdate.value)) {
			alert("'Early registration' cannot be later than conferece begining.");
			rdate.focus();
			return false;     
		}
	}	
	if (pdate.value.length!=0) {
		if (!chkdate(pdate,'Abstract submission',pdate,0)) {
			pdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,pdate.value)) {
			alert("'Abstract submission' cannot be later than conference begining.");
			pdate.focus();
			return false;     
		}
	}

	if (email.value.length > 0 && !emailcheck(email.value)) {
		alert("Invalid 'Email' format. Should be xxx@yyy.zzz");
		email.focus();
		return false;
	}
	if (orgz.value != '0' && norgz.value.length != 0) {
		alert("Duplicate Organizer and 'New organizer'");
		norgz.focus();
		return false;
	}	
	if (omail.value.length > 0 && !emailcheck(omail.value)) {
		alert("Invalid 'Organizer mail' format. Should be xxx@yyy.zzz");
		omail.focus();
		return false;
	}
	if (oweb.value.length > 0 && !urlcheck(oweb.value)) {
		alert("Invalid 'Organizer web' format. Should be http://www.xxx....");
		oweb.focus();
		return false;
	}	
	var warn="";
	if (exh.value ==0) warn="'Exhibition', ";
	if (nven.value.length > 0 && vweb.value.length == 0) warn=warn+"'Venue web', ";	
	if (nven.value.length > 0 && vmail.value.length == 0) warn=warn+"'Venue mail', ";
	if (org.value.length == 0) warn=warn+"Organization, ";
	if (email.value.length == 0) warn=warn+"Email, ";
	if (cont.value.length == 0) warn=warn+"Contact, ";
	if (pdate.value.length == 0) warn=warn+"Abstract submit., ";
	if (rdate.value.length == 0) warn=warn+"'Early registration', ";
	if (orgz.value == '0' && norgz.value.length == 0) warn=warn+"Organizer, ";
	if (norgz.value.length > 0 && omail.value.length == 0) warn=warn+"'Organizer email', ";
	if (norgz.value.length > 0 && oweb.value.length == 0) warn=warn+" 'Organizer web'";
	if (warn!="") { 
		var answer=confirm("The following fields are missing:\n"+warn+"\nPress 'OK' to proceed or 'Cancel' to return to form");
		if (answer) return true;
		else return false;
	}
	return true;
}
}
function validate_update (addform)
{

with (addform)
{
	if (fld_empty(event,'Event name')) return false;
	if (fld_empty(web,'Website')) return false;
	if (web.value.length > 0 && !urlcheck(web.value)) {
		alert("Invalid 'Website' format. Should be http://www.xxx....");
		web.focus();
		return false;
	}
	if (fld_empty(fdate,'From date')) return false;
	else {
		if (!chkdate(fdate,'From date',fdate,0)) {
			fdate.focus();	
			return false;
		}
		var d=prep_date(new Date(),0);
//		if (!compare_dates(fdate.value,d)) {
//			alert("'From Date' cannot be before "+d);
//			fdate.focus();
//			return false;
//		}
	}
	if (fld_empty(tdate,'To date')) return false;
	else {
		if (!chkdate(tdate,'To date',tdate,0)) {
			tdate.focus();	
			return false;
		}
		if (!compare_dates(tdate.value,fdate.value)) {
			alert("'To Date' must be later than 'From Date'.");
			fdate.focus();
			return false;
		}
	}
	
	if (ctry.value == 0) {
		alert("Missing country.");
		ctry.focus();
		return false;
	}

	if (ctry.value =='US' && stat.value <= 0) {
		alert("Missing state for USA.");
		stat.focus();
		return false;
	}
	if (city.value == 0 && ncity.value.length == 0) {
		alert("Missing 'City'.");
		city.focus();
		return false;
	}
	if (city.value != 0 && ncity.value.length != 0) {
		alert("Duplicate City and 'New city'");
		ncity.focus();
		return false;
	}
	if (ncity.value.length > 0 && (lat.value.length == 0 || long.value.length == 0)) {
		alert("Missing 'latitude' or 'longitude' for 'New city'");
		lat.focus();
		return false;
	}
	if (city.value > 0 && (lat.value.length > 0 || long.value.length > 0)) {
		alert("'latitude' and 'longitude' should be used only for 'New city'");
		lat.focus();
		return false;
	}	
	if (lat.value.length > 0 && !ltnum(lat.value)) {
		alert("Invalid 'latitude'. format should be like '12.1234567'.");
		lat.focus();
		return false;
	}
	if (long.value.length > 0 && !ltnum(long.value)) {
		alert("Invalid 'longitude'. format should be like '12.1234567'.");
		long.focus();
		return false;
	}

	if (ven.value < 0 && nven.value.length == 0) {
		alert("Missing 'Venue'.");
		ven.focus();
		return false;
	}
	if (ven.value >= 0 && nven.value.length != 0) {
		alert("Duplicate 'Venue' and 'New venue'");
		nven.focus();
		return false;
	}
	if (nven.value.length > 0) {
		if (fld_empty(add,'Address')) return false;
		if (vweb.value.length > 0 && !urlcheck(vweb.value)) {
			alert("Invalid 'Venue web' format. Should be http://www.xxx...");
			vweb.focus();
			return false;
		}
		if (vmail.value.length > 0 && !emailcheck(vmail.value)) {
			alert("Invalid 'Venue Email' format. Should be xxx@yyy.zzz");
			vmail.focus();
			return false;
		}
	}	
//	alert ('desc='+desc.value+' desc1='+document.getElementById('wysiwygdesc').value);
//	if (desc.value.length == 0 || desc.value == '<P>&nbsp;</P>') {
//		alert("Missing 'Description'.");
//      Cannot focus because textarea is taken by wyzz
//		return false;
//	}	
		
	if (cat.value == 0 && ncat.value.length == 0) {
		alert("Missing 'Category'.");
		cat.focus();
		return false;
	}
	if (cat.value > 0 && ncat.value.length > 0) {
		alert("Duplicate category.");
		cat.focus();
		return false;
	}
	if (subj.value == 0 && nsubj.value.length == 0) {
		alert("Missing subject.");
		subj.focus();
		return false;
	}
	if (subj.value > 0 && nsubj.value.length > 0) {
		alert("Duplicate subject.");
		subj.focus();
		return false;
	}


	
	if (fld_empty(fpr,'From price')) return false;
	if (fpr.value.length > 0 && !numeric(fpr.value) && parseInt(fpr.value)!=-1) {
		alert("Invalid 'From price'. should be a number");
		fpr.focus();
		return false;
	}
	if (tpr.value.length > 0 && !numeric(tpr.value)) {
		alert("Invalid 'To price'. should be a number");
		tpr.focus();
		return false;
	}
	if (tpr.value.length > 0 && fpr.value.length > 0) {
		if (parseInt(tpr.value) < parseInt(fpr.value)) {
			alert("'To price' should be higher than 'From price");
			long.focus();
			return false;
		}
	}
	if ((fpr.value>0 || tpr.value>0) && fld_empty(cur,'Currency')) return false;
//	if (fld_empty(exh,'Exhibition information')) return false;
//	if (exh.value ==0) {
//		alert("Missing 'Exhibition' information.");
//		exh.focus();
//		return false;
//	}
	if (rdate.value.length!=0) {
		if (!chkdate(rdate,'Early registration',rdate,0)) {
			rdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,rdate.value)) {
			alert("'Early registration' cannot be later than conferece begining.");
			rdate.focus();
			return false;     
		}
	}	
	if (pdate.value.length!=0) {
		if (!chkdate(pdate,'Abstract submission',pdate,0)) {
			pdate.focus();	
			return false;
		}
		if (!compare_dates(fdate.value,pdate.value)) {
			alert("'Abstract submission' cannot be later than conference begining.");
			pdate.focus();
			return false;     
		}
	}

	if (email.value.length > 0 && !emailcheck(email.value)) {
		alert("Invalid 'Email' format. Should be xxx@yyy.zzz");
		email.focus();
		return false;
	}
	if (orgz.value != '0' && norgz.value.length != 0) {
		alert("Duplicate Organizer and 'New organizer'");
		norgz.focus();
		return false;
	}	
	if (omail.value.length > 0 && !emailcheck(omail.value)) {
		alert("Invalid 'Organizer mail' format. Should be xxx@yyy.zzz");
		omail.focus();
		return false;
	}
	if (oweb.value.length > 0 && !urlcheck(oweb.value)) {
		alert("Invalid 'Organizer web' format. Should be http://www.xxx....");
		oweb.focus();
		return false;
	}	
	var warn="";
	if (exh.value ==0) warn="'Exhibition', ";
	if (nven.value.length > 0 && vweb.value.length == 0) warn=warn+"'Venue web', ";	
	if (nven.value.length > 0 && vmail.value.length == 0) warn=warn+"'Venue mail', ";
	if (org.value.length == 0) warn=warn+"Organization, ";
	if (email.value.length == 0) warn=warn+"Email, ";
	if (cont.value.length == 0) warn=warn+"Contact, ";
	if (pdate.value.length == 0) warn=warn+"Abstract submit., ";
	if (rdate.value.length == 0) warn=warn+"'Early registration', ";
	if (orgz.value == '0' && norgz.value.length == 0) warn=warn+"Organizer, ";
	if (norgz.value.length > 0 && omail.value.length == 0) warn=warn+"'Organizer email', ";
	if (norgz.value.length > 0 && oweb.value.length == 0) warn=warn+" 'Organizer web'";
	if (warn!="") { 
		var answer=confirm("The following fields are missing:\n"+warn+"\nPress 'OK' to proceed or 'Cancel' to return to form");
		if (answer) return true;
		else return false;
	}
	return true;
}
}
function confirm_delete() {
	var answer=confirm("Are you sure you want to delete conference ??\nPress 'OK' to proceed or 'Cancel' to return to form");
	if (answer) return true;
	else return false;
}

function compare_dates(frst_date,scnd_date) {
	var date1 = unprep_date(frst_date);
	var date2 = unprep_date(scnd_date);
//	alert ('a='+date1+' b='+date2);
	if (date1 < date2) {
		return false;
		alert('false');
	}	
	else return true;
}

function unprep_date(ndate) {
	var dmy = ndate.split("-");
	var d = new Date();
	d.setFullYear(dmy[2],dmy[1]-1,dmy[0]);
	return d;
}

function prep_date1(ndate,weeks,format)
//format=0 dd-mm-YYYY  ,  format=1 dd-MON-YYYY
{
	var MonthNames = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var oneMinute = 60 * 1000;  // milliseconds in a minute
	var oneHour = oneMinute * 60;
	var oneDay = oneHour * 24;
	var oneWeek = oneDay * 7;
	var dateInMS = ndate.getTime() + oneWeek * weeks;
	var nextDate = new Date(dateInMS);
	var day = nextDate.getDate();
	var m = nextDate.getMonth();
	if (format==1) var month = MonthNames[m];
	else month=m+1;
	var year = nextDate.getFullYear();
	var newdate = day + "-" + month + "-" + year;
	return newdate;
}
function prep_date(now,days)
{
	now.setDate(now.getDate()+days);
	var next = now.getDate() + "-" + (now.getMonth()+1) + "-" + now.getFullYear();
	return(next);
}

function chkdate(ndate,name,tdate,mod) {
	if (ndate.value=="") return true;
	var re_date = /^\s*(\d{1,2})\-(\d{1,2})\-(\d{4})\s*$/;
	if (!re_date.exec(ndate.value)) {
		alert ("'"+name+"' is Invalid. Accepted format is dd-mm-yyyy.");
		return false;
	}
	var dmy = ndate.value.split("-");
	var nday = dmy[0];
	var	nmonth = dmy[1];
	var	nyear = dmy[2];

	if (nmonth < 1 || nmonth > 12) {
		alert ("Invalid month in '"+name+"'.");
		return false;
	}
	var dnumdays = new Date(nyear, nmonth, 0);
	if (nday > dnumdays.getDate()) {
		alert("Invalid day in '"+name+"'. Selected month has only " + dnumdays.getDate() + " days");
		return false;
	}
	if (mod==1 && compare_dates(ndate.value,tdate.value)) tdate.value = ndate.value;
	return true;
}

function validate_qry (addform)
{
with (addform)
{
	if (fdate.value.length == 0 || tdate.value.length == 0) {
		alert("Dates must be specified ('From date' and 'To date').");
		fdate.focus();
		return false;
	}
	if (!chkdate(fdate,'From date',fdate,0)) {
		fdate.focus();	
		return false;
	}
	if (!chkdate(tdate,'To date',tdate,0)) {
		tdate.focus();	
		return false;
	}
//	var d=prep_date(new Date(),0);
//	if (!compare_dates(fdate.value,d)) {
//		alert("'From Date' cannot be before "+d);
//		fdate.focus();
//		return false;
//	}		
	if (!compare_dates(tdate.value,fdate.value)) {
		alert("'To Date' must be later than 'From Date'.");
		fdate.focus();
		return false;
	}
	return true;
}
}

function numeric(sText)
{
   var ValidChars = "0123456789.";
   var Char;
   for (i = 0; i < sText.length; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) { 
         return false;
      }
   }
   return true;
}
function ltnum (num)
{
//	var re_date = /^\s*(\d{1,3})\.(\d{1,7})\s*$/;
	var re_date = /^\s*-*\d{1,3}\.\d{1,7}\s*$/;
	if (!re_date.exec(num)) {
		return false;
	}
return true;	
}

function urlcheck(url)
{
     var u= /http(s?):\/\/[-\w\.]{3,}\.[A-Za-z]{2,3}/;
     return u.test(url);
}

function emailcheck(email)
{      
   var e = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return e.test(email);
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}


function create_keywords(string) 
{
	var text=string.replace(/\W/g," "); // Clean none alpha and none numeric
	text=text.replace(/\d/g," ");   // Clean numeric
	text=text.replace(/(\s\w{1,3}\s)/g," "); // Clean 1-3 letter words
	text=text.replace(/(\s\w{1,3}\s)/g," "); // Clean 1-3 letter words
	text=text.replace(/(\s\w{1,3}\s)/g," "); // Clean 1-3 letter words	
	text=text.replace(/^(\w{1,3}\s)|(\s\w{1,3})$/g," "); // Clean 1-3 letter words
	text=text.replace(/^(\s+)|(\s+)$/g,''); //Clean spaces at the beginning and the end
	text=text.replace(/\s+/g,',');
	return(text);
}
function prep_keywords(element,keywords) {
	keywords.value=create_keywords(element.value);
}

function kH(e) {
	var pK = document.all? window.event.keyCode:e.which;
	return pK != 13;
}


function validate_enter (form)
{
with (form)
{
	if (fld_empty(user,'User name')) return false;
	if (fld_empty(passw,'Password')) return false;
	if (user.value!='ayelet' && user.value!='clocate1_ayelet') {
		alert("!!! You are not allowed to enter the page !!!");
		passw.value="";
		user.focus();
		return false;
	}
}
}
function duplicates1(form)
{
with (form) {
//alert ('cy='+ctry.value+'ct='+city.value+'v='+ven.value+'f='+fdate.value+'t='+tdate.value);
	if (fdate.value!="" && tdate.value!="") {
		var args="";
		
		if (event.value!="") 
			var args='getresults.php?event='+event.value+'&fdate='+fdate.value+'&tdate='+tdate.value;

		if (ctry.value=='US' && stat.value!="") var state='&stat='+stat.value;
		else state='';
		if (ctry.value!="" && city.value>0 && ven.value>=0) 
			var args='getresults.php?ctry='+ctry.value+state+'&city='+city.value+'&ven='+ven.value+'&fdate='+fdate.value+'&tdate='+tdate.value;

//		alert('args='+args);
		if (args!="")
			window.open( args );
		else alert('Cannot check duplicates. Some fields missing: Event name or Country,city,venue');

	}
	else alert('Cannot check duplicates. Dates fields missing.');
}
}
function duplicates(form)
{
with (form) {
//alert ('cy='+ctry.value+'ct='+city.value+'v='+ven.value+'f='+fdate.value+'t='+tdate.value);
// http://www.clocate.com/25-01-2010+25-04-2010/conference
// http://test2/Venue/Country/United-States+AZ+Bullhead-City/25-01-2010+25-01-2013/ HELEXPO		
	var today=new Date();
	var nextdate=new Date();
	var dd=today.getDate();
	if (dd<10) dd='0'+dd;
	var mm=today.getMonth()+1;
	if (mm<10) mm='0'+mm;
	var yy=today.getFullYear();
	now=dd+"-"+mm+"-"+yy;
	nextdate.setFullYear(today.getFullYear()+1);
	var dd=nextdate.getDate();
	if (dd<10) dd='0'+dd;
	var mm=nextdate.getMonth()+1;
	if (mm<10) mm='0'+mm;
	var yy=nextdate.getFullYear();
	then=dd+"-"+mm+"-"+yy;
	
	var args="";
//	alert ('tday='+now+' nxt='+then+' e='+event.value);
	if (event.value!="") {
		var str=event.value;
		str=str.replace(/\//g,"");
//		var args='getresults.php?event='+str+'&fdate='+now+'&tdate='+then;
		var args=now+"+"+then+"/"+str;
	}	

	if (ctry.value=='US' && stat.value!="") var state='&stat='+stat.value;
	else state='';
	if (ctry.value!="" && city.value>0 && ven.value>=0) 
		var args='getresults.php?ctry='+ctry.value+state+'&city='+city.value+'&ven='+ven.value+'&fdate='+fdate.value+'&tdate='+tdate.value+'&q=Venue';

//	alert('args='+args);
	if (args!="")
		window.open( args );
	else alert('Cannot check duplicates. Some fields missing: Event name or Country,city,venue');

}
}

//so backspace doesn't go back
//document.onkeydown = checkForBackspace;
//function checkForBackspace() {
 //we can backspace in a textbox 
// if(window.event.srcElement.type.match("text") || window.event.target.type.match("text")) {
//  return true;
// }
 
// if(window.event && window.event.keyCode == 8) {
  // try to cancel the backspace
//  window.event.cancelBubble = true;
//  window.event.returnValue = false;
//  return false;
// }
//}

//Every single key press action will call this function.
function shouldCancelbackspace(e) {
var key;
if(e){
key = e.which? e.which : e.keyCode;
if(key == null || ( key != 8 && key != 13)){ // return when the key is not backspace key.
return false;
}
}else{
return false;
}

if (e.srcElement) { // in IE
tag = e.srcElement.tagName.toUpperCase();
type = e.srcElement.type;
readOnly =e.srcElement.readOnly;
if( type == null){ // Type is null means the mouse focus on a non-form field. disable backspace button
return true;
}else{
type = e.srcElement.type.toUpperCase();
}

} else { // in FF
tag = e.target.nodeName.toUpperCase();
type = (e.target.type) ? e.target.type.toUpperCase() : "";
}

// we don't want to cancel the keypress (ever) if we are in an input/text area
if ( tag == 'inPUT' || type == 'TEXT' || type == 'TEXTAREA') {
if (e.srcElement) {
	if(readOnly == true ) // if the field has been dsabled, disbale the back space button
		return true;
}
if( ((tag == 'inPUT' && type == 'RADIO') || (tag == 'inPUT' && type == 'CHECKBOX'))
&& (key == 8 || key == 13) ){
return true; // the mouse is on the radio button/checkbox, disbale the backspace button
}
return false;
}

// if we are not in one of the above things, then we want to cancel (true) if backspace
return (key == 8 || key == 13);
}

// check the browser type
function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';

if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));
}else
return 'Netscape';
}else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else
return navigator.userAgent;
}

// Global events (every key press)

var browser = whichBrs();
if(browser == 'internet Explorer'){
document.onkeydown = function() { return !shouldCancelbackspace(event); }
}else if(browser == 'firefox'){
document.onkeypress = function(e) { return !shouldCancelbackspace(e); }
} 

