badCharArray = new Array();

function reportErr(){
		var theEmail= 'info@paintings.name';
		document.location.href = 'mailto:'+theEmail;
		}

hitRefresh = 'Thank you for your submission.\n\nPlease Note: If you get an error message, KEEP HITTING YOUR BROWSER\'S refresh button until you get ART CHAT\'s welcoming message.\n\nIf the error persists, please mail me be using the "Report Error" button';

function submitForm(){
//alert('Due to a server error you cannot submit this form right now. Our apologies');
//return 0;
	for (x=0;x<document.form1.elements.length;x++){			
		if(document.form1.realname.value==""){alert('please enter your REAL NAME'); 
						document.form1.realname.focus();
						return 0;}
		if(document.form1.nickname.value==""){alert('please enter your NICKNAME');
						document.form1.nickname.focus();
						break; }
		if(document.form1.icqnr.value==""){alert('please enter your ICQ NR'); 
						document.form1.icqnr.focus();
						break;}
		if(document.form1.language.value==""){alert('please enter your LANGUAGE');
						document.form1.language.focus();
						 break;}
		if(document.form1.remarks.value=="" ){alert('please describe your relationship to art');
						document.form1.remarks.focus();
						break;}
		if(document.form1.password.value==""){alert('please enter a PASSWORD');
						document.form1.password.focus();
						break;}
		if(document.form1.password.value.length>10 || document.form1.password.value.length<6){
					                alert('Your PASSWORD must be 6 to 10 characters long');
	                                                                                document.form1.password.focus();
						break;}
		if(document.form1.email.value==""){alert('please enter your EMAIL ADDRESS');
						document.form1.email.focus();
						break;}
		for (x=0;x<document.form1.elements.length;x++){							
			var field = document.form1.elements[x].value;
			badChar(field);
			if(badCharArray.length>0){
				alert('The '+document.form1.elements[x].name+' field contains the following illegal characters:\n\n\t\t'+badCharArray.join(' ')+'\n\n Please remove all illegal characters and try again');
				emptyArray();
				return 0;
			}//end if
		}//end FOR								
		document.form1.hiddenSubmit.value="1";
		document.form1.hiddenEdit.value="";
		document.form1.hiddenDelete.value="";
		document.form1.hiddenNewIcq.value="";
		document.form1.hiddenNewPw.value="";
		if(navigator.cookieEnabled){
			writeCookie();}
		alert(hitRefresh);			
		document.form1.submit();
		break;				
							}<!--end FOR-->	
return false }

function editForm(){
	
	for (x=0;x<document.form1.elements.length;x++){

		if(document.form1.icqnr.value==""){alert('please enter your ICQ NR'); 
						document.form1.icqnr.focus();
						break;}
		if(document.form1.password.value==""){alert('please enter your PASSWORD');
	                                                                                document.form1.password.focus();
						break;}
		document.form1.hiddenSubmit.value="";
		document.form1.hiddenEdit.value="1";
		document.form1.hiddenDelete.value="";
		document.form1.hiddenNewIcq.value="";
		document.form1.hiddenNewPw.value="";
		if(navigator.cookieEnabled){
			writeCookie();}
		alert(hitRefresh);
		document.form1.submit();
		break;				}

return false }

function deleteForm(){
	
if(confirm('are you sure you want to DELETE your info?')){
	for (x=0;x<document.form1.elements.length;x++){

		if(document.form1.icqnr.value==""){alert('please enter your ICQ NR'); 
						document.form1.icqnr.focus();
						break;}
		if(document.form1.password.value.length>10 || document.form1.password.value.length<6){alert('please enter your PASSWORD - the length of your PASSWORD must be between 6 and 10 characters.');	                                                                          document.form1.password.focus();
						break;}
		document.form1.hiddenSubmit.value="";
		document.form1.hiddenEdit.value="";
		document.form1.hiddenDelete.value="1";
		document.form1.hiddenNewIcq.value="";
		document.form1.hiddenNewPw.value="";
		if(navigator.cookieEnabled){
			writeCookie();}
		alert(hitRefresh);
		document.form1.submit();
		break;				}
								}
		else{alert('DELETE CANCELLED')}
return false }

function changePw(){

	for (x=0;x<document.form1.elements.length;x++){
		if(document.form1.icqnr.value==""){alert('please enter your ICQ NR'); 
						document.form1.icqnr.focus();
						return 0;}
		if(document.form1.password.value==""){alert('please enter your OLD PASSWORD');
	                                                                                document.form1.password.focus();
						return 0;}
		if(document.form1.password.value.length>10 || document.form1.password.value.length<6){
					                alert('Your PASSWORD must be 6 to 10 characters long');
	                                                                                document.form1.password.focus();
						break;}					
							}<!--end FOR-->
		if(confirm('are you sure you want to CHANGE your PASSWORD?')){
			newPassword=prompt('Please enter your NEW PASSWORD','6 to 10 characters');
			while(newPassword.length>10 || newPassword.length<6){
				        alert('Your PASSWORD must be 6 to 10 characters long');
						newPassword=prompt('Please enter your NEW PASSWORD','6 to 10 characters');
	                    }	
			document.form1.hiddenSubmit.value="";
			document.form1.hiddenEdit.value="";
			document.form1.hiddenDelete.value="";
			document.form1.hiddenNewIcq.value="";
			document.form1.hiddenNewPw.value=newPassword;
			if(navigator.cookieEnabled){
				writeCookie();}
			alert(hitRefresh);
			document.form1.submit();
			return 0;							}
							
		else{alert('CHANGE PASSWORD CANCELLED')}
return false }

function changeIcq(){

	for (x=0;x<document.form1.elements.length;x++){
		if(document.form1.icqnr.value==""){alert('please enter your OLD ICQ NR'); 
						document.form1.icqnr.focus();
						return 0;}
		if(document.form1.password.value==""){alert('please enter your PASSWORD');
	                                                                                document.form1.password.focus();
						return 0;}
							}<!--end FOR-->

		if(confirm('are you sure you want to CHANGE your ICQ NR?')){
			newIcqNr=prompt('Please enter your NEW ICQ NR','');
			
			document.form1.hiddenSubmit.value="";
			document.form1.hiddenEdit.value="";
			document.form1.hiddenDelete.value="";
			document.form1.hiddenNewIcq.value=newIcqNr;
			document.form1.hiddenNewPw.value="";
			if(navigator.cookieEnabled){
				writeCookie();}
			alert(hitRefresh);
			document.form1.submit();
			return 0;							}
							
		else{alert('CHANGE ICQ NR CANCELLED')}
return false }

function random(){
		a=Math.round((Math.random())*100000000)
		document.form1.password.value=a;
		}

function writeCookie(){

	timeOffset=3650;	
	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (timeOffset*24 * 60 * 60 * 1000)); // timeOffset in days 

	
	if(document.form1.hiddenSubmit.value==1 || document.form1.hiddenEdit.value==1){
        
		name="ICQNR";
		value=document.form1.icqnr.value;
		if(navigator.cookieEnabled){
			SetCookie(name, value,expdate);}

		name="PASSWORD";
		value=document.form1.password.value;
		if(navigator.cookieEnabled){
			SetCookie(name, value,expdate);}
		
		if(document.form1.nickname.value){
		name="NICKNAME";
		value=document.form1.nickname.value;
		if(navigator.cookieEnabled){
			SetCookie(name, value,expdate);}
		}
		
		return 1;						}//END IF SUBMIT/EDIT 
		
	if(document.form1.hiddenDelete.value==1){
		if(navigator.cookieEnabled){
			deleteTheCookie("ICQNR");
			deleteTheCookie("PASSWORD");
			deleteTheCookie("fav");
			}
		return 1;						}//END IF DELETE

	if(document.form1.hiddenNewIcq.value){
		name="ICQNR";
		value=document.form1.hiddenNewIcq.value;
		if(navigator.cookieEnabled){
			SetCookie(name, value,expdate);}	
		return 1;						}//END IF NEWICQNR

	if(document.form1.hiddenNewPw.value){
		name="PASSWORD";
		value=document.form1.hiddenNewPw.value;
		if(navigator.cookieEnabled){
			SetCookie(name, value,expdate);}	
		return 1;						}//END IF NEW PASSWORD

							
}//END WRITECOOKIE

function deleteTheCookie(cookieName){
	name=cookieName
	value=0;
	timeOffset=0;

	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (timeOffset*24 * 60 * 60 * 1000)); // timeOffset in days 
	
SetCookie (name, value,expdate);
}

function addFav(){
if(navigator.cookieEnabled){		
	if(GetCookie("fav")=="yes"){return 0;}
	if(document.form1.hiddenSubmit.value!=""){return 0;}
	if(document.form1.hiddenEdit.value!=""){return 0;}
	if(document.form1.hiddenDelete.value!=""){return 0;}
	if(document.form1.hiddenNewPw.value!=""){return 0;}
	if(document.form1.hiddenNewIcq.value!=""){return 0;}
	else{
	
	window.external.AddFavorite("http://maarten.net/Art4all/Icq/list.php3","Art4all ICQ List");
	timeOffset=90;	
	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (timeOffset*24 * 60 * 60 * 1000)); // timeOffset in days 
	name="fav";
	value="yes";
	SetCookie(name, value,expdate);
	}
	
}//END IF COOKIE ENABLED
}	
function autoFill(){
if(navigator.cookieEnabled){
	if(document.cookie){
		if(GetCookie("ICQNR")){document.form1.icqnr.value=GetCookie("ICQNR");}
			else{alert("I couldn't find the ICQ NR COOKIE. Please enter your ICQ NR and your PASSWORD manually.");
				document.form1.icqnr.focus();
				return 1;}
		if(GetCookie("PASSWORD")){document.form1.password.value=GetCookie("PASSWORD");}	
			else{alert("I couldn't find the PASSWORD COOKIE. Please enter your PASSWORD and your ICQNR manually.");	
				document.form1.password.focus();	
				return 1;}
													}//END IF COOKIE
													}//END IF COOKIE ENABLED
	else{alert("The AUTOFILL function only works if you have our COOKIE, but I couldn't find it. Maybe you didn't accept the cookie when you submitted the form, or you haven't submitted the form yet, or you have cleared your cookie-file.")}
}

function badChar(file){
var theChar;
var pattern3 =/[\¬|\§|\!|\"|\#|\$|\(|\)|\'|\~|\°|\¸|\^|\¨|\*|\+|\±|\´|\`|\<|\>|\,|\;|\·|\=|\[|\]|\¦|\«|\»|\¢|\µ]/;	
	if(theChar = file.match(pattern3)){
		var newStr = file.replace(pattern3,"");		
		badCharArray.push(theChar);	
		badChar(newStr);
	}
}	
function emptyArray(){
	if(badCharArray.pop()){
		emptyArray();
		}//end IF	 
}//end function	
