// JavaScript Document


//ish for popups
function setMyDate(which){
  var myindex='false'; 
  day=$F(which+'_date_hf').slice(0,2);
  yrmth=$F(which+'_date_hf').slice(2,8);
  $(which+'_date_d').selectedIndex=day-1;
  //$(which+'_date_mth_yr').selectedIndex=yrmth;
  for(i=0;i<13;i++){
    if($(which+'_date_mth_yr').options[i].value==yrmth){
      myindex=i;
    }
  }
  if(myindex!='false'){
    $(which+'_date_mth_yr').selectedIndex=myindex;
    $('gen_error').hide();
  }else{
    showProfileError(which+'_date_mth_yr','Date is Outside Acceptable Range');
  }
}

function showBeta(theid){
	var el = document.getElementById(theid);
	el.style.display = (el.style.display != 'none' ? 'none' : '' );
}

function textCounter(field,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}
function invitesCounter(field,maxlimit) {
	if (field.value.length > maxlimit){ // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	if(document.invites.counter){
		document.invites.counter.value=field.value.length;
	}
}
function getDigits(str){
	var intl = str.indexOf("+");
	var mynums = str.replace(/[^\d]/g, "");
	var minLen=6;
	var maxLen=16;
	if(intl>=0){
		minLen=7;
		maxLen=18;
	}
	if(mynums.length>minLen && mynums.length<maxLen){
		return true;
	}else{
		return false;
	}
}
function okTelNum(num){
	var mynums = num.replace(/[\(\)\.\-\ \+]/g, '');
	/* remove all valid characters */
	var parsed = parseInt(mynums);
	if (isNaN(mynums)) {
		return false;
	}else{
		return true;
	}
}
function popup(page) {

	var display = page+'.html';

	window.open(display,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=480,height=420');

	}

function dateScreen(mydate) {

	var display = 'dates.html';

	window.open(display,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=250,height=150');

	}

function getexpirydate( nodays){

	var UTCstring;

	Today = new Date();

	nomilli=Date.parse(Today);

	Today.setTime(nomilli+nodays*24*60*60*1000);

	UTCstring = Today.toUTCString();

	return UTCstring;

}

function getcookie(cookiename) {

	var cookiestring=""+document.cookie;

	var index1=cookiestring.indexOf(cookiename);

	if (index1==-1 || cookiename=="") return ""; 

	var index2=cookiestring.indexOf(';',index1);

	if (index2==-1) index2=cookiestring.length; 

	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));

}

function setcookie(name,value,duration){

	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);

	document.cookie=cookiestring;

	if(!getcookie(name)){

		return false;

	}else{

		setUserName();

		return true;

	}

}

function check_imgupload(){

	if(document.imgupload.myimage){

		if(document.imgupload.myimage.value==''){

			alert("please search for a picture to upload first");

			return false;	

		}else{

			return true;

		}

	}else{

		return false;

	}

}

function check_imgupdate(){

	if(document.imgupdate){

		return true;

	}else{

		return false;

	}

}

function check_imgupdateOLD(){

	if(document.imgupdate){

		if((document.imgupdate.title) && (document.imgupdate.title.value=='') ){

			alert('Please enter a title for your image');

			return false;

		}else if((document.imgupdate.details) && (document.imgupdate.details.value=='') ){

			alert('Please enter a short description for your image');

			return false;

		}else{

			return true;

		}

	}else{

		return false;

	}

}

function checkAll(div,field,lbl,recs){

	//alert("got "+div+" and "+field+" and "+lbl+" and also "+recs);

	var checkState = lbl.checked;

	var msgDiv = document.getElementById(div);

	var empCnt =0;

	if(checkState==true){

		for (i = 0; i < recs; i++){

			var theDivId=field+""+i;

			if(document.getElementById(theDivId)){

				theDivIDVal=document.getElementById(theDivId).checked=true;

			}else{

				empCnt++;

			}

		}

		if((msgDiv) && (empCnt!=recs)){

			document.getElementById(div).style.display='block';

		}

	}else{

		for (i = 0; i < recs; i++){

			var theDivId=field+""+i;

			if(document.getElementById(theDivId)){

				theDivIDVal=document.getElementById(theDivId).checked=false;

			}else{

				empCnt++;	

			}

		}

		if((msgDiv) && (empCnt!=recs)){

			document.getElementById(div).style.display='none';

		}

	}

}

function showMsg(theid,themode,thelist){

	var theDiv = document.getElementById(theid);

	var sectionhdr='Send a short messsage to all contact that are ';

	if(theDiv){

		if(theDiv.style.display=='block'){

			if(document.sendmessage.type){

				document.sendmessage.type.value='listings';

				document.sendmessage.f_id.value='';	

			}

			theDiv.style.display='none';

		}

		if (theDiv.style.display=='none' || theDiv.style.display==''){

			if(document.sendmessage.type){

				document.sendmessage.type.value=themode;

				document.sendmessage.f_id.value=thelist;		

			}

			if(document.getElementById('sectionhr')){

				if(themode=='business'){

					sectionhdr=sectionhdr+'Other Business Contacts';

				}else if(themode=='organisation'){

					sectionhdr=sectionhdr+'In Your Organisation';

				}else if(themode=='social'){

					sectionhdr=sectionhdr+'Social Contacts';

				}else if(themode=='other'){

					sectionhdr=sectionhdr+'Other Contacts';

				}

				document.getElementById('sectionhr').innerHTML = sectionhdr;

			}

			theDiv.style.display='block';	

		}

	}

}

function showRows(lbl,recs){

	for (i = 0; i < recs; i++){	

		var myrow = lbl+""+i;

		if(document.getElementById(myrow)){

			if(document.getElementById(myrow).style.display=='block'){

				document.getElementById(myrow).style.display='none';

			}else if(document.getElementById(myrow).style.display=='none'){	

				document.getElementById(myrow).style.display='block';

			}

		}

	}

}



function checkThisOne(div,field,recs){

	//alert("here and found "+div+" and also "+field+ " and also "+recs);

	var thdiv = document.getElementById(div);

	var checked=0;

	for (i = 0; i < recs; i++){

		var theDivId=field+""+i;

		if(document.getElementById(theDivId)){

			var theDivIDVal=document.getElementById(theDivId).checked;

			if(theDivIDVal==true){

				checked++;

			}

		}

	}

	if(checked>0){

		thdiv.style.display='block';	

	}else{

		thdiv.style.display='none';

	}

}





function uncheckAll(field)

{

	for (i = 0; i < field.length; i++){

		field[i].checked = false ;

	}

}



function datePop(curDate){

	dateScreen(curDate);

}



function setUserName(){

		if(document.mainlogin){

			document.mainlogin.usr.value = getcookie("visitorname");

			if(document.mainlogin.rememberusr){

				document.mainlogin.rememberusr.checked=true;	

			}

		}

}



function rememberUser(isChecked,cookieName,usrVal){

	if(isChecked){

		var mode = 2;

		if(usrVal.length<=5){

			alert("You must enter a valid username before we can remember your login");

			if(document.mainlogin.rememberusr){

				document.mainlogin.rememberusr.checked=false;	

			}

		}else{

			setcookie(cookieName,usrVal,mode);		

		}

	}else{

		var mode = -1;

		setcookie(cookieName,usrVal,mode);

	}

}



function unsetUserName(){

		if(document.mainlogin){

			document.mainlogin.usr.value = '';

			if(document.mainlogin.rememberusr){

				document.mainlogin.rememberusr.checked=false;	

			}

		}

}



function CheckForm() {

	if(document.signup){

		alert("in signup check");

		return CheckSignup();

	}else if (document.login){

		alert("in login check");

		return CheckLogin();

	}else{

		

	}

}



function changeBG(objRef, state) {

	objRef.style.backgroundColor = (1 == state) ? '#FEF9DB' : '#FFFFFF';

	objRef.style.border = (1 == state) ? '1px solid #B6B5B5' : '1px solid #B6B5B5';

	return;

}



function whichRadio(thisform,myradiobutton){

	var myOption = -1;

	for (i=thisform.myradiobutton.length-1; i > -1; i--) {

		if (thisform.myradiobutton[i].checked) {

			myOption = i; i = -1;

		}

	}

	return myOption;

}

function divOnOff(theid){

	var theDiv = document.getElementById(theid);

	if(theDiv){

		if(theDiv.style.display=='block'){

			theDiv.style.display='none';

		}else if (theDiv.style.display=='none' || theDiv.style.display==''){

			theDiv.style.display='block';

		}

	}

}

function setOnOff(theid,max){

		for(i=0; i<max; i++){

			var myid = theid+""+i;

			if(document.getElementById(myid)){

				toggleOnOff(myid);

			}

		}
		
		if(theid=='advSearch'){
		  if($F('formname')=='advance'){
		    $('id_name').value='';
		    $('id_company').value='';
		  }else if($F('formname')=='useradv'){
		    $('id_city').value='';
		  }
		}

}


function toggleOnOff(theid){
	var el = document.getElementById(theid);
	//block only works consistently with IE to display the element again
	el.style.display = (el.style.display != 'none' ? 'none' : '' );
}

function toggleOnOffOld(theid){//replaced by above function

	var theDiv = document.getElementById(theid);

	var moreFlds = document.getElementById('moreflds');

	if(theDiv){

		if(theDiv.style.display=='block'){

			theDiv.style.display='none';

			if(moreFlds){

				//moreFlds.innerHTML='none';

			}

		}else if (theDiv.style.display=='none' || theDiv.style.display==''){

			theDiv.style.display='block';

			if(moreFlds){

				//moreFlds.style.display='block';

			}

		}

	}

}



function showOrHide(theid,myRadio,myCheck){

	var theDiv = document.getElementById(theid);

	var radLen = myRadio.length;

	

	if(theDiv){

		var theStyle = document.getElementById(theid).style.display;

		if(theStyle=='none' || theStyle==''){

			theDiv.style.display='block';

			theDiv.className='showrow';

			myRadio[1].checked=true;

		}else{

			for (i=myRadio.length-1; i > -1; i--) {

				if (myRadio[i].checked) {

					myRadio[i].checked=false;

				}

			}

			myCheck.checked=false;

			theDiv.style.display='none';

		}

	}

}

function check_forgotten(){

	var email = /^([\w.-]+)@(([\w.-]+\.)+\w+)$/;

	

	if ((document.forgotten.firstname) && (document.forgotten.firstname.value=='')) {

	alert("Please enter your first name");

	document.forgotten.firstname.focus();

	return false;

	}else if ((document.forgotten.lastname) && (document.forgotten.lastname.value=='')) {

	alert("Please enter your last name");

	document.forgotten.lastname.focus();

	return false;

	}else if ((document.forgotten.email) && (document.forgotten.email.value=='')) {

	alert("Please enter your contact email address for whozintown");

	document.forgotten.email.focus();

	return false;

	} else if ((document.forgotten.email) && (email.test(document.forgotten.email.value) == false)) {

	alert("Please enter a valid contact Email Address");

	document.forgotten.email.focus();

	return false;

	} else {

	return true;}

}

function check_demo(){

	if ((document.demo.country) && ((document.demo.country.value=='') || (document.demo.country.value=='XX'))) {

	alert("Please selecty a country");

	document.demo.country.focus();

	return false;

	}else if ((document.demo.city) && (document.demo.city.value=='')) {

	alert("Please enter a city for the country selected");

	document.demo.city.focus();

	return false;

	} else {

	return true;}

}

function check_simple(){

	if ((document.simple.city) && (document.simple.city.value=='0')) {

	alert("Please enter a city for the country selected");

	document.simple.city.focus();

	return false;

	} else {

	return true;}

}

function CheckFullSearch(){

	if ( ((document.msearch.name) && (document.msearch.name.value == '')) && ((document.msearch.city) && (document.msearch.city.value == '')) ) {

	alert("Please enter the name Members's Name and City or both.");

	document.msearch.name.focus();

	return false;

	}else if ((document.msearch.position) && (document.msearch.position.value=='0')) {

	alert("Please select the job title or position");

	document.msearch.position.focus();

	return false;

	}else if ((document.msearch.country) && ((document.msearch.country.value == '') || (document.msearch.country.value == 'XX'))) {

	alert("Please select a country");

	document.msearch.country.focus();

	return false;

	} else {

	return true;}

}



function CheckUpload(){

if ((document.uploader.uplfile) && (document.uploader.uplfile.value == '')) {

alert("Please browse your local directories for a file");

document.uploader.uplfile.focus();

return false;

}else if ((document.uploader.mode) && (document.uploader.mode.value == '')) {

alert("Invalid Option Selected");

document.uploader.uplfile.focus();

return false;

} else {

return true;}

}







function CheckLogin(){
var email = /^([\w.-]+)@(([\w.-]+\.)+\w+)$/;
var passOne = /^[A-Za-z0-9\-\_]{5,15}$/i;

if ((document.login.usr) && (document.login.usr.value == '')) {

alert("Please enter your username. This is your email address.");

document.login.usr.focus();

return false;

}else if ((document.login.usr) && (document.login.usr.value == 'username')) {

alert("Please enter your username");

document.login.usr.focus();

return false;

} else if ((document.login.pws) && (document.login.pws.value == '')) {

alert("Please enter your password");

document.login.pws.focus();

return false;

} else if ((document.login.pws) && (document.login.pws.value == 'password')) {

alert("Please enter your password");

document.login.pws.focus();

return false;

} else {

return true;}

}



function CheckMainLogin(){

if ((document.mainlogin.usr) && (document.mainlogin.usr.value == '')) {

alert("Please enter your username");

document.mainlogin.usr.focus();

return false;

}else if ((document.mainlogin.usr) && (document.mainlogin.usr.value == '')) {

alert("Please enter your username");

document.mainlogin.usr.focus();

return false;

} else if ((document.mainlogin.pws) && (document.mainlogin.pws.value == '')) {

alert("Please enter your password");

document.mainlogin.pws.focus();

return false;

} else if ((document.mainlogin.pws) && (document.mainlogin.pws.value == '')) {

alert("Please enter your password");

document.mainlogin.pws.focus();

return false;

} else {

return true;}

}



function CheckAccess(){

if ((document.access.username) && (document.access.username.value == '')) {

alert("Please enter your username");

document.access.username.focus();

return false;

}else if ((document.access.username) && (document.access.username.value == 'username')) {

alert("Please enter your username");

document.access.username.focus();

return false;

} else if ((document.access.password) && (document.access.password.value == '')) {

alert("Please enter your password");

document.access.password.focus();

return false;

} else if ((document.access.password) && (document.access.password.value == 'password')) {

alert("Please enter your password");

document.access.password.focus();

return false;

} else {

return true;}

}

function CheckSignup() {
var postcode = /^([A-Za-z]{1,2}[\s]{0,3}\d{1,2}[A-Za-z]{0,1}[\s]{0,3}\d{1}[\s]{0,3}[A-Za-z]{2})$/;
var email = /^([\w.-]+)@(([\w.-]+\.)+\w+)$/;
var rate = /(^\d{0,3}$)/;
var dayz = /^\d{1,3}$/;
var rate = /^\d{1,3}(\.\d{2})?$/;
var telnum = /^[0]\d{8,10}$/;
var passOne = /^[A-Za-z0-9\-\_]{5,15}$/i;
var passTwo = /\d/;
var username = /^[A-Za-z0-9\-\_]{5,15}$/i;


if ((document.signup.title) && (document.signup.title.selectedIndex < 1)) {
alert("Please select your Title");
document.signup.title.focus();
return false;
} else if ((document.signup.firstname) && (document.signup.firstname.value == '')) {
alert("Please enter your First Name");
document.signup.firstname.focus();
return false;
} else if ((document.signup.lastname) && (document.signup.lastname.value == '')) {
alert("Please enter a valid Last Name");
document.signup.lastname.focus();
return false;
} else if ((document.signup.city) && (document.signup.city.value == '')) {
alert("Please enter a valid City");
document.signup.city.focus();
return false;
}else if ((document.signup.email) && ('' == document.signup.email.value)) {
alert("Please enter your contact Email Address");
document.signup.email.focus();
return false;
} else if ((document.signup.email) && (email.test(document.signup.email.value) == false)) {
alert("Please enter a valid contact Email Address");
document.signup.email.focus();
return false;
} else if ((document.signup.password) && (document.signup.password.value == '')) {
alert("Please enter a Password for your new Ourtryst account");
document.signup.password.focus();
return false;
} else if ((document.signup.password) && (passOne.test(document.signup.password.value) == false)) {
alert("Please enter a Password between 5-15 alphanumeric characters");
document.signup.password.focus();
return false;
} else if ( (document.signup.password) && (document.signup.password2) && (document.signup.password2.value != document.signup.password.value)) {
alert("Password mismatch. Please enter the correct password.");
document.signup.password2.focus();
return false;
}else if ((document.signup.terms) && (! document.signup.terms.checked)) {
alert("Please confirm that you have accepted our Terms and Conditions");
document.signup.terms.focus();
return false;
}else if ((document.signup.newuser_hf) && (document.signup.newuser_hf.value==1)) {
alert("The username you have selected in not valid. Please select another.");
document.signup.username.focus();
return false;
}else if ((document.signup.newemail_hf) && (document.signup.newemail_hf.value==1)) {
alert("The email address you have entered already exist. Please select another.");
document.signup.email.focus();
return false;
} else {
return true;}
}

function checkbirthdate(d,m,y)   //Function added by Ish for checking date
{

  var yl=1930; // least year to consider
  var ym=2026; // most year to consider
  if (m<1 || m>12) return(false);
  if (d<1 || d>31) return(false);
  if (y<yl || y>ym) return(false);
  if (m==4 || m==6 || m==9 || m==11)
  if (d==31) return(false);
  if (m==2)
  {
    var b=parseInt(y/4);
    if (isNaN(b)) return(false);
    if (d>29) return(false);
    if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
  }
  return(true);
}


function showProfileError(field,message){
  $('gen_error').innerHTML=message;
  $('gen_error').show();
  $(field).focus();
}

function CheckProfile() {

var postcode = /^([A-Za-z]{1,2}[\s]{0,3}\d{1,2}[A-Za-z]{0,1}[\s]{0,3}\d{1}[\s]{0,3}[A-Za-z]{2})$/;
var email = /^([\w.-]+)@(([\w.-]+\.)+\w+)$/;
var telnum = /^[0]\d{8,10}$/;
var mobile = /^[0]\d{10,13}$/;

var international = /^\+[\d]{1,3}[\ \.\-\]?[\d]{3,4}[\ \.\-\]?+[\d]{3,5}[\ \.\-\]?+[\d]{3,4}$/;
var localnum = /^[\d]{1,4}[\ \.\-\]?[\d]{3,4}[\ \.\-\]?+[\d]{3,5}$/;
var passOne = /^[a-z\d\(\)\-\_\.\@\!]{6,15}$/i;
var passOneOLD = /^[a-z\d]{6,15}$/i;
var passTwo = /\d/;
var username = /^[A-Za-z0-9\-\_]{6,15}$/i;
var name = /^[A-Za-z\-]+$/;
var genalpha = /^[A-Za-z\-\ \,]+$/;
var genalpha_2 = /^[A-Za-z0-9\-\_\!\.\@\ \,]+$/;
var genalpha2 = /^[A-Za-z0-9\-\_\!\/'\.\@\ \,]+$/;
var genalpha3 = /^[A-Za-z\-\ \,\&\_\$\.\']+$/;
  
  if($('part_hf').value=='prof_gen'){
    //validate general fields
    if($('id_firstname').value==''){
      showProfileError('id_firstname','First Name is Mandatory');
      return false;
    }else if (name.test($('id_firstname').value)==false){
      showProfileError('id_firstname','First Name has Invalid Characters');
      return false;
    }
    if($('id_lastname').value==''){
      showProfileError('id_lastname','Last Name is Mandatory');
      return false;
    }else if (name.test($('id_lastname').value)==false){
      showProfileError('id_lastname','Last Name has Invalid Characters');
      return false;
    }
    if($('id_company').value==''){
      showProfileError('id_company','Company Name is Mandatory');
      return false;
    }else if (genalpha3.test($('id_company').value)==false){
      showProfileError('id_company','Company Name has Invalid Characters');
      return false;
    }
    if($('id_city').value==''){
      showProfileError('id_city','Home Town/City is Mandatory');
      return false;
    }else if (genalpha.test($('id_city').value)==false){
      showProfileError('id_city','Home Town/City has Invalid Characters');
      return false;
    }
    if($('id_country').value=='' || $('id_country').value=='XX'){
      showProfileError('id_country','Please Select a Country');
      return false;
    }
    if($('id_position').value==''){
      showProfileError('id_position','Please Select a Position / Job Title');
      return false;
    }
    if($('id_email').value==''){
      showProfileError('id_email','Personal Email Address is Mandatory');
      return false;
    }else if(email.test($('id_email').value)==false){
      showProfileError('id_email','Please Enter a Valid Personal Email Address');
      return false;
    }
   if($('id_tel').value!='' && getDigits($('id_tel').value)==false){
      showProfileError('id_tel','Telehone number does not contain sufficient digits');
      return false;
    }
    if($('id_tel').value!='' && okTelNum($('id_tel').value)==false){
      showProfileError('id_tel','Telehone number contains invalid characters. E.g. +44 161 424 9999');
      return false;
    } 
    if($('id_mobile').value!='' && getDigits($('id_mobile').value)==false){
      showProfileError('id_mobile','Mobile number does not contain sufficient digits');
      return false;
    }
    if($('id_mobile').value!='' && okTelNum($('id_mobile').value)==false){
      showProfileError('id_mobile','Mobile number contains invalid characters. E.g. +44 7512 444 999');
      return false;
    } 
  }else if($('part_hf').value=='prof_work'){
  //validate employment fields
  
    if($('id_work_city').value!='' && genalpha.test($('id_work_city').value)==false){
      showProfileError('id_work_city','Work Town/City has Invalid Characters');
      return false;
    }
    if($('id_p_email').value!='' && email.test($('id_p_email').value)==false){
      showProfileError('id_p_email','Please Enter a Valid Business Email Address');
      return false;
    }
    if($('id_worktel').value!='' && getDigits($('id_worktel').value)==false){
      showProfileError('id_worktel','Business Telephone number does not contain sufficient digits');
      return false;
    }
   if($('id_worktel').value!='' && okTelNum($('id_worktel').value)==false){
      showProfileError('id_worktel','Business Telephone contains invalid characters. E.g. +44 161 424 9999');
      return false;
    }
    if($('id_responsibility').value!='' && genalpha2.test($('id_responsibility').value)==false){
      showProfileError('id_responsibility','Responsibility has Invalid Characters');
      return false;
    }
  
  }else if($('part_hf').value=='prof_misc'){
  //validate other fields
    if(!checkbirthdate($('id_birth_date').value,$('birth_date_mth').value,$('birth_date_yr').value)){
      showProfileError('id_birth_date','Date of Birth is Invalid');
      return false;
    }
    if($('id_nationality').value!='' && genalpha.test($('id_nationality').value)==false){
      showProfileError('id_nationality','Nationality has Invalid Characters');
      return false;
    }
    if($('id_interests').value!='' && genalpha2.test($('id_interests').value)==false){
      showProfileError('id_interests','My Interests has Invalid Characters');
      return false;
    }
    if($('id_notes').value!='' && genalpha2.test($('id_notes').value)==false){
      showProfileError('id_notes','Other Notes has Invalid Characters');
      return false;
    }
  
  }else if($('part_hf').value=='prof_pws'){
  //validate password fields
    if($('id_password1').value==''){
      showProfileError('id_password1','Current Password is Mandatory');
      return false;
	}else if (passOne.test($('id_password1').value)==false){
      showProfileError('id_password1',"Password contains invalid characters or is not between 6-15 characters");
      return false;
    }
    if($('id_password').value==''){
      showProfileError('id_password','New Password is Mandatory');
      return false;
    }else if (passOne.test($('id_password').value)==false){
      showProfileError('id_password','Password contains invalid characters or is not between 6-15 characters');
      return false;
    }
    if($('id_password2').value==''){
      showProfileError('id_password2','Retype Password is Mandatory');
      return false;
    }
    if($('id_password').value != $('id_password2').value){
      showProfileError('id_password','The 2 Passwords do not Match');
      return false;
    }    
  }

}

function checkdate(d,m,y)  { //Function added by Ish for checking date

  var yl=2006; // least year to consider
  var ym=2026; // most year to consider
  if (m<1 || m>12) return(false);
  if (d<1 || d>31) return(false);
  if (y<yl || y>ym) return(false);
  if (m==4 || m==6 || m==9 || m==11)
  if (d==31) return(false);
  if (m==2){
    var b=parseInt(y/4);
    if (isNaN(b)) return(false);
    if (d>29) return(false);
    if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
  }

  return(true);
}

function check_advance(){

var name = /^[A-Za-z\-]+$/;
var genalpha = /^[A-Za-z\-\ ]+$/;

	if($F('id_country')=='' || $F('id_country')=='XX'){
      showProfileError('id_country','Please Select a Country');
      return false;
  }
  if($F('id_city')==''){
    showProfileError('id_city','Town/City is Mandatory');
    return false;
  }else if (genalpha.test($F('id_city'))==false){
    showProfileError('id_city','Town/City has Invalid Characters');
    return false;
  }
  if($F('id_event')!='' && genalpha.test($F('id_event'))==false){
    showProfileError('id_event','Event has Invalid Characters');
    return false;
  }
  if($('advSearch0').style.display=='block' && $F('id_name')!='' && genalpha.test($F('id_name'))==false){
    showProfileError('id_name','Member has Invalid Characters');
    return false;
  }
  if($('advSearch1').style.display=='block' && $F('id_company')!='' && genalpha.test($F('id_company'))==false){
    showProfileError('id_name','Organisation has Invalid Characters');
    return false;
  }
  
  var start=0;
  var end=0;
  var sy = $F('start_date_mth_yr').slice(0,4);
  var sm = $F('start_date_mth_yr').slice(4,6);
  var sd = $F('start_date_d');
  start=(sy+sm+sd)*1;
  var ey = $F('end_date_mth_yr').slice(0,4);
  var em = $F('end_date_mth_yr').slice(4,6);
  var ed = $F('end_date_d');
  end=(ey+em+ed)*1;
  
  if (!checkdate(sd,sm,sy)){
    showProfileError('start_date_d','Start Date is Invalid');
    return false;
  }
  if (!checkdate(ed,em,ey)){
    showProfileError('end_date_d','End Date is Invalid');
    return false;
  } 

  if (start > end){
    showProfileError('start_date_d','End Date is earlier that Start Date');
    return false;
  }

  
}

function check_useradv(){

var name = /^[A-Za-z\-]+$/;
var genalpha = /^[A-Za-z\-\ ]+$/;

  if($F('id_firstname')!='' && genalpha.test($F('id_firstname'))==false){
    showProfileError('id_firstname','First Name has Invalid Characters');
    return false;
  }
  if($F('id_lastname')==''){
    showProfileError('id_lastname','Last Name is Mandatory');
    return false;
  }else if($F('id_lastname').length<2){
  showProfileError('id_lastname','Last Name must contain at least 2 characters');
    return false;
  }else if (name.test($F('id_lastname'))==false){
    showProfileError('id_lastname','Last Name has Invalid Characters');
    return false;
  }
	if($F('id_company')!='' && genalpha.test($F('id_company'))==false){
    showProfileError('id_company','Company has Invalid Characters');
    return false;
  }
  if($F('id_city')!='' && genalpha.test($F('id_city'))==false){
    showProfileError('id_city','Home Town/City has Invalid Characters');
    return false;
  }

}


	//functions to incorporate

	function fade(step, endOpacity, interval, callback) {

		clearTimeout(timers.fade);

		setOpacity(opacity + step);

		if (opacity != endOpacity) {

			timers.fade = setTimeout(function() { fade(step, endOpacity, interval, callback) }, interval);

		} else if (callback) {

			callback();

		}

	}



	function fadeIn(e) {

		if (e) {

			for (var el = e.srcElement || e.target; el && el != src; el = el.parentNode);

			state |= el ? 1 : 2;

			clearTimeout(timers.hide);

		} else {

			setOpacity(0);

		}

		var nsteps = info.fadeInDuration / info.fadeInInterval || 1;

		fade(Math.ceil(info.opacity / nsteps), info.opacity, info.fadeInInterval);

	}



	function fadeOut() {

		var nsteps = info.fadeOutDuration / info.fadeOutInterval || 1;

		fade(-Math.ceil(info.opacity / nsteps), 0, info.fadeOutInterval, hide);

	}



	function setOpacity(level) {

		if (level < 0) {

			opacity = 0;

		} else if (level > info.opacity) {

			opacity = info.opacity;

		} else {

			opacity = level;

		}

		iframe.style.opacity = opacity / 100;

		iframe.style.MozOpacity = opacity / 100;

		iframe.style.KHTMLOpacity = opacity / 100;

		iframe.style.filter = 'alpha(opacity=' + opacity + ')';

	}

	

function getDup(usr,element){



return false;

}



function getDuplicate(usr,element) {



	var http_request = false;

	if (element.value == "") {

		document.getElementById("username").value = "";

		return;

	}

	/* Check browser type */

	if ( window.XMLHttpRequest ) {

		http_request = new XMLHttpRequest();

		if ( http_request.overrideMimeType )

			http_request.overrideMimeType('text/xml');

        }

	else if ( window.ActiveXObject ) {

        try {

			http_request = new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch ( exception ) {

			try {

				ttp_request = new ActiveXObject("Microsoft.XMLHTTP");

			} 

			catch ( exception ) {}

		}

	}

	if ( !http_request ) {

		alert('Problem creating an XMLHTTP instance');

			return false;

	}

	http_request.onreadystatechange = function() { processResponse(http_request,usr,element); };

	http_request.open('GET', 'getDuplicate.cgi?username='+usr, true);

	http_request.send(null);

}




function CheckModEvent(){  //Function added by Ish



  var start=0;

  var end=0;

  var sy = $('start_date_mth_yr').value.slice(0,4);

  var sm = $('start_date_mth_yr').value.slice(4,6);

  var sd = $('start_date_d').value;

  start=(sy+sm+sd)*1;

  var ey = $('end_date_mth_yr').value.slice(0,4);

  var em = $('end_date_mth_yr').value.slice(4,6);

  var ed = $('end_date_d').value;

  end=(ey+em+ed)*1;

  if (!checkdate(sd,sm,sy)){
    showProfileError('start_date_d','Start Date is Invalid');
    return false;
  }
  
  if (!checkdate(ed,em,ey)){
    showProfileError('end_date_d','End Date is Invalid');
    return false;
  }
  
  if (start > end){
    showProfileError('start_date_d','End Date is Before Start Date');
    return false;
  }

  if ($('qs_country').value=='' || $('qs_country').value=='XX'){
    showProfileError('qs_country','Please Select a Country');
    return false;
  }

  if ($('qs_city').value==''){
    showProfileError('qs_city','Please Select a City');
    return false;
  }

  return true;

}

function showDemoHiddenDiv(){
  $('signup').show();
}

