function add_contact(id){
   if(id.length>0){
        uploader_init();
        uploader_go(id);
   }
}

function clUploadData ( thesrc ) {
        this.src = thesrc;
        this.src += "?";
        this.type = "text/javascript";
        this.oldScript  = document.createElement("SCRIPT");
        this.oldScript.type = this.type;
        this.callId = 0;
        
        document.body.appendChild(this.oldScript);
        this.upload = function ( theparams ) {
                var tParams = theparams || "";
                var newScript = document.createElement("SCRIPT");
                newScript.type = this.type;
                newScript.src  = this.src + tParams;
    document.body.replaceChild(newScript,this.oldScript);
                this.oldScript = newScript;
        }
}


function uploader_init () {
   uploader = new clUploadData('javascript.php');
}

function uploader_go (src) {
        uploader.upload(src);
}


function select_all_ls(z){
         document.getElementById("select_all").title=(z)?"Снять выделение":"Выделить все";
         for(i=0;i<document.delall.length;i++){
             if(document.delall.elements[i].type=="checkbox"&&document.delall.elements[i].name=="ids[]")
                 document.delall.elements[i].checked=z;
         }
}

function fnChoiceRegion(id) {

       var cover_div=document.getElementById("Region");
       cover_div.style.display =(id==1)?'block':'none';
}

function close_div(id) {
	var d = get_by_id(id);
	if (d) {
		d.innerHTML = '';
		d.style.top = -999;
		d.style.left = -999;
		d.id="";
	}
}

function get_by_id(id) {
	var itm = null;
	if (document.getElementById){
		itm = document.getElementById(id);
	}
	else if (document.all){
		itm = document.all[id];
	}
	else if (document.layers){
		itm = document.layers[id];
	}
	return itm;
}


function trimStr(s) {
  //s = s.replace( /\s+/g, '');
  return s.replace( /\s+/g, '');
}
function allow_editing() {
	var lgnform = document.getElementById('megafonid-api-signin-alt');
	if(lgnform!=null) {
		var gn = document.getElementById('guest-nick');
		if(gn!=null) {
			if(gn.value!='') {
				if(gn.value.indexOf(" ")!=-1)
				gn.value = trimStr(gn.value);
				if(gn.value.length >= 3)
					return true;
				else return false;	
			} else {

				return false; 
			}
		} else { 
			return true; 
		}
	} else {
		return true;
	}	
}

