var is_email = /\w\@\w/;
var name_missing, email_missing, user_admin, incorrect_email, mark_all, unmark, no_directory_delete_from_updates, remove_you_from_updates;
	
function Get_Edit(hidden, divID) {
					
				var xmlHttp;
				try {  // Firefox, Opera 8.0+, Safari  
					xmlHttp=new XMLHttpRequest(); 
				}
				catch (e) {  // Internet Explorer  
					try {
						xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch (e) {   
						 try {
						 	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
						 }
				   	 catch (e)  {
				  		   alert("Your browser does not support AJAX!");  
				   		   return false;
						}
					}
				}
			  xmlHttp.onreadystatechange=function() {
			  			if(xmlHttp.readyState==4) {	  					
			  					var resp = xmlHttp.responseText;
			  					var values = resp.split('<%D%>');
			  					htm = values[0];
			  					script = values[1];
			  					end_script = values[2];
			  					try {
			  						script = script.replace(/<script>/ig,'');
								 		script = script.replace(/<\/script>/ig,'');
								 		//alert(script);
								 		eval(script);
			  					} catch(e){}
			  					putAjaxStyle(htm);
			  					if (divID) {
			  						document.getElementById(divID).innerHTML = htm;			  							
			  					}
			  					try {
			  						end_script = end_script.replace(/<script>/ig,'');
								 		end_script = end_script.replace(/<\/script>/ig,'');
			  					} catch(e){}
			  			}
			  	}
			  
			  var addUrl = '';
			  						
			  noheader = 'noheader';
			  //if (allnoheader == 1) noheader = 'allnoheader';
			  //alert(cgi_webaxy+"/tel/mig-tel.pl?"+hidden+"&"+noheader+"=1&"+addUrl);
			  xmlHttp.open("GET","/cgi-webaxy/new/tellme.pl?"+hidden+"&"+noheader+"=1&"+addUrl,true);
			  xmlHttp.send(null);
			  return false;
			  	
}

function Delete_me() {
		if (user_admin != "")
			return;
		form = document.getElementById('form_tellme');
		form.email.value = form.email1.value.replace(/\s/g,"");
		if (form.email.value.search(is_email) == -1) {
			form.email1.focus();
			return;
		}
		if (!confirm(remove_you_from_updates))
			return;
		form.action.value = "delete";
		win = open("","WIN","height=200,width=300");
		form.target = "WIN";
		form.submit();
}
	
function TellmeMarkAll() {
		var ch;
		ma = document.getElementById("tellme_markall");
		if (ma.value == mark_all) {
			ch = true;
			ma.value = unmark;
		//	document.form_tellme.all.checked = false;
		}
		else {
			ch = false;
			ma.value = mark_all;
		}
		
			
		for (cb=0;cb < document.getElementById('form_tellme').elements.length; cb++) {
			el = document.getElementById('form_tellme').elements[cb];
			if ((el.name.indexOf("t_") == 0) || (el.name.indexOf("sal_") == 0) || (el.name == "board") || (el.name == "forum") || (el.name == "cal") || (el.name == "events") || (el.name.indexOf("faq_") == 0)) {
				el.checked = ch;
			}
		}
		
	
}
	
function update_tellme() {
	
		form = document.getElementById('form_tellme');
		var msg = '';
		if (user_admin == "") 
			form.email1.value = form.email1.value.replace(/\s/g,"");
		if (form.email1.value == '') {	
			msg += email_missing+'\n';
			form.email1.focus();
		}
		else if (form.email1.value.search(is_email) == -1) {
			msg += incorrect_email+'\n';
			form.email1.focus();
		}
		if (form.name.value == '') {	
			msg += name_missing+'\n';
			form.name.focus();
		}		
		msg = msg.replace(/\n$/,'');
		if (msg.length > 0) {
			alert(msg);
			return false;
		}
		ok = false;
		for (i = 0; i < form.elements.length; i++)
			if ((form.elements[i].type == "checkbox") && form.elements[i].checked)
				ok = true;
		if (!ok && (user_admin == "") && confirm(no_directory_delete_from_updates))
			form.action.value = "delete";
		else if (!ok) 
			return;
		else 
			form.action.value = "register";
		
		win = open("","WIN","height=200,width=300");
		form.target = "WIN";
		form.submit();
		
}

function putAjaxStyle(rawHTML) {
  	
		var headEl = null;  // lazy-load
		styles = rawHTML.split(/\n/);
		var style = 0, stop = 1;
		var newStyleEl = document.createElement('style');
		newStyleEl.type = 'text/css';
		var styleIE = '';
		// add all found style blocks to the HEAD element.
    if (!headEl) {  
    		headEl = document.getElementsByTagName('head')[0];
        if (!headEl) return;
    }
    for (i = 0; i < styles.length; i++) {
        if (styles[i].search(/<style>/i) >= 0){
        		style = 1;
        		stop = 0;
        		continue;
        }
        else if (styles[i].search(/<\/style>/i) >= 0){
        		style = 0
        }
        else if (styles[i].search(/^\s*\/\*/) >= 0) {
        		stop = 1;
        		continue;
        }
        else if (styles[i].search(/\*\/\s*$/) >= 0) {
        		stop = 0;
        		continue;
        }
        if (style == 0 || stop == 1) continue;
        if (navigator.appVersion.indexOf("MSIE")!=-1) {  
            styleIE += styles[i]
        }
        else {  
            var cssDefinitionsEl = document.createTextNode(styles[i]);
            newStyleEl.appendChild(cssDefinitionsEl);
        }
     }
     if (navigator.appVersion.indexOf("MSIE")!=-1 && styleIE != '') newStyleEl.styleSheet.cssText = styleIE;
     headEl.appendChild(newStyleEl);
    
}	
