//suckerfish dropdown for IE
sfHover = function() {
	var sfEls = $(".hasChildren");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			
			if(document.getElementById("menu_iframe")) {
	          var iframe = document.getElementById("menu_iframe");
	
	          var submenu = this.getElementsByTagName("UL");
	          if(submenu.length) {
	            iframe.style.top = submenu[0].offsetTop;// + this.offsetTop;
	            iframe.style.left = submenu[0].offsetLeft;// + this.offsetLeft;
	            iframe.style.width = submenu[0].scrollWidth+1;
	            iframe.style.height = submenu[0].clientHeight+1;
	            iframe.style.display = "inline";
	          }
	        }
        
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			
	        if(document.getElementById("menu_iframe")) {
	          var iframe = document.getElementById("menu_iframe");
	          iframe.style.display = "none";
	        }
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);




startList = function() {
	
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
			
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;



/********************************************************************/
//BASIC FUNCTIONS
/********************************************************************/
Array.prototype.contains = function (elem) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == elem) {
    	return true;
    }
  }
  return false;
};




Array.prototype.array_del = function(val) {
	for (var x = 0; x < this.length; x++) {
		if (this[x] == val) {
			this.splice(x,1);
		}
	}
};





/********************************************************************/
//Decrypt Email

function DecryptEmail(s)	{
	//location.href = UnCryptMailto( s );
	alert(UnCryptMailto( s ));
}


function UnCryptMailto( s ) {
        var n = 0;
        var r = "";
        for( var i = 0; i < s.length; i++)
        {
            n = s.charCodeAt( i );
            if( n >= 8364 )
            {
                n = 128;
            }
            r += String.fromCharCode( n - 1 );
        }
        return r;
}


/********************************************************************/
function SetUsertype(path,val) {
	
	document.newuser.usertype.value=val;

	for (i=2;i<=6;i++) {
		if (document.images["img_user"+i]) document.images["img_user"+i].src = path+"img/icn_user"+i+".jpg";
	}
	document.images["img_user"+val].src = path+"img/icn_user"+val+"sel.jpg";
	
	if (val==5) {
		//dealer
		$('.member').hide('fast');
		$('.dealer').show('fast');
	} else if (val==6) {
		//not member
		$('.member').show('fast');
		$('.dealer').show('fast');

	} else {
		$('.member').hide('fast');
		$('.dealer').hide('fast');
	}
	
	if (val==3) {
		$('#tab_userdata_2').show();
		$('#tab_userdata_3').show();
		ShowAdminRights(1);
	} else {
		$('#tab_userdata_2').hide();
		$('#tab_userdata_3').hide();
		$('#box_userdata_1').show();
		$('#box_userdata_2').hide();
		$('#box_userdata_3').hide();
		$('#tab_userdata_1').addClass("tabsel");
	}
	
}


/********************************************************************/
function ShowTabBox(val) {
	
	
	$('.tab').removeClass("tabsel");
	$('#tab_'+val).addClass("tabsel");
	
	$('.box').hide();
	$('#box_'+val).show();
		
}



/********************************************************************/
function ShowAdminRights(val) {
	
	$("#error").text("");
	
	for (i=1;i<=3;i++) {
		$('#tab_userdata_'+i).removeClass("tabsel");
		$('#box_userdata_'+i).hide();
	}
	$('#tab_userdata_'+val).addClass("tabsel");
	$('#box_userdata_'+val).show();
		
}



/********************************************************************/
function SetCountry(id,type) {
	
	if(!type) $("li#country_"+id).toggleClass("sel");
	if(type=="add")    $("li#country_"+id).addClass("sel");
	if(type=="rem")    $("li#country_"+id).removeClass("sel");

	//Get the countries from the hidden field
	val = $('#admincountries').val();
	if (val) {
		arr = val.split(",");
	} else {
		arr = new Array();
	}

	//Add the actual country to the array, if was missing, or remove, if was present
	if (arr.contains(id)) {
		if (type!="add") arr.array_del(id);
	} else {
		if (type!="rem") arr.push(id);
	}
	
	//Write array to hidden field
	str = arr.join(",");
	$('#admincountries').val(str);
}



/********************************************************************/
function SelectAllCountries(add) {
	
	region = $(".region_sel").attr("id");
	region = region.replace(/btn_/,"");
	//alert(region);
	
	if (region == "region_all") {
		if(add) {
			$("#box_country ul li").each(function() {
				
				country = this.id;
				id = country.replace(/country_/,"");
				SetCountry(id,"add");
			});
		} else {
			$("#box_country ul li").removeClass("sel");
			$('#admincountries').val("");
		}
	} else if(region == "region_sel") {
		if (!add) {
			$("#box_country ul li").removeClass("sel");
			$("#box_country ul li").hide();
			$('#admincountries').val("");
		} 
			
	} else {
		
		$("#"+region+" ul li").each(function() {	
			country = this.id;
			id = country.replace(/country_/,"");
			if(add) SetCountry(id,"add"); else SetCountry(id,"rem");
		});
	}
}




/********************************************************************/
function SelectAllAdminCountries(add) {
	
	//region = $(".region_sel").attr("id");
	//region = region.replace(/btn_/,"");
	//alert(region);

	$("#box_country ul li").each(function() {
		country = this.id;
		id = country.replace(/country_/,"");
		if(add) SetCountry(id,"add"); else SetCountry(id,"rem");
	});
	
}


/********************************************************************/
function ShowPole(id) {
	
	if (id=='all') {
		$("#box_country ul li").show();
		$("#box_country div").show();
		$(".btn_region").show();
	} else if (id=='sel') {
		$("#box_country div").show();
		$("#box_country ul li").hide();
		$("#box_country ul li.sel").show();
	} else if (id=='0') {
		$("#box_country div").hide();
		$("#box_country ul li").show();
	} else {
		$("#box_country ul li").show();
		$("#box_country div").hide();
		$("#region_"+id).show();
		
		$(".btn_region").hide();
		$("#box_country div").hide();
		$(".region_parent"+id).show();
	}
	
	/*
	//$("#box_region ul li").show();
	$(".btn_region").hide();
	$("#box_country div").hide();
	$(".region_parent"+id).show();
	*/
	
	
	//Highlight Button
	$(".btn_pole").removeClass('region_sel');
	$("#btn_pole_"+id).addClass("region_sel");
}


/********************************************************************/
function ShowRegion(id) {
	if (id=='all') {
		$("#box_country ul li").show();
		$("#box_country div").show();
	} else if (id=='sel') {
		$("#box_country div").show();
		$("#box_country ul li").hide();
		$("#box_country ul li.sel").show();
	} else if (id=='0') {
		$("#box_country div").hide();
		$("#box_country ul li").show();
	} else {
		$("#box_country ul li").show();
		$("#box_country div").hide();
		$("#region_"+id).show();
	}
	
	//Highlight Button
	$(".btn_pole").removeClass('region_sel');
	$(".btn_region").removeClass('region_sel');
	$("#btn_region_"+id).addClass("region_sel");
}



/********************************************************************/
function RegNext(val) {
	
	next = false;
	pattern = false;
	
	if(val==2) {
		if ($("#country1").valid()) next = true;
	}
	
	if(val==3) {
		if ($("#unit").valid()) next = true;
	}
	
	if(val==4) {
		
		
		if ($("#serial").valid() && $("#purchase_year").valid()) {
			next = true;
		}
		
		if ($("#congress").val()) next = true;
		
		//Check Serial Number
		
		if ($("#club_id").val()==1 && next==true && !$("#congress").val()) {
			str = $("#serial").val();
					
			if($("#unit").val()==7 || $("#unit").val()==9) {
				pattern = new RegExp(/^[D,d][0-9]{5}$/);
			} else if ($("#unit").val()==8 || $("#unit").val()==6) {
				pattern = new RegExp(/^[B,b][0-9]{5}$/);
			} else if ($("#unit").val()==10) { 
				//
			} else {
				pattern = new RegExp(/^[A,a][0-9]{5}$/);
			}
			
			if (pattern) {
				if (pattern.test(str)) {
					next = true; 
				} else {
					next = false;
					$("#serial").after('<label class="error" for="serial" style="display: inline;">Wrong Serial number for this unit!</label>');
				}
			}
		}	
	}
	
	if(val==5) {
		if ($("#register").valid() && $("#email").valid()) {
			
			$("#register input").each(function(intIndex) {
				set_id = $(this).attr("id");
				if (set_id) {
					$("#chk_"+set_id).text($(this).val());
				}
			});
			
			$("#register select").each(function(intIndex) {
				set_id = $(this).attr("id");
				if (set_id) {
					$("#chk_"+set_id).text($(this).children("[@selected]").text());
				}
			});
			$("#chk_purchase_year").text($("#purchase_year").val());
			
			if ($("#newsletter").attr('checked')) {
				$("#chk_news").text("Yes");
			} else {
				$("#chk_news").text("No");
			}
			
			if ($("#address_type").attr('checked')) {
				$("#chk_address_type").text("Private Address");
			} else {
				$("#chk_address_type").text("Hospital / Institution Address");
			}
			/*
			alert($.ajax({
				url: "/file.php?f=ajax/checkserial.php&user_id="+$("#user_id").val(),
				success: function(html){
				    if (html=="false") {
				    	val=4;
				    }
  				}

			}));
			*/
			next = true;
		}
	}
	
	if (next) {
		for (i=1;i<=5;i++) {
			$("#box_step"+i).hide();
		}
		$("#box_step"+val).show();
	}
}

/********************************************************************/
function RegPrev(val) {
	
	for (i=1;i<=5;i++) {
		$("#box_step"+i).hide();
	}
	$("#box_step"+val).show();
}





/********************************************************************/
function SetUnit(val) {
	$("#unit").val(val);
	
	//fill random number and revalidate to initiate new validation after unit change.
	//otherwise the validate script wouldn´t recheck the same number.
	if ($("#serial").val()) {
		$("#serial").val(".");
		$("#serial").valid();
		$("#serial").val("");
	}
	
	//Set image for location of serial number
	img = $("#boxunit_"+val+" img").attr("name");
	$("#imgserial").attr("src","/data/images/serials/"+img+".jpg");
	
	//set the selection for the unit
	$(".box_unit").removeClass("unitsel");
	$("#boxunit_"+val).addClass("unitsel");
	
	src = $("#unitimg_"+val).attr("src");
	$("#chk_unitimg").attr("src",src);
	$("#chk_unitname").text($("#boxunit_"+val+" div").text());
}


/********************************************************************/
function SetNameonCard() {
	var f = $("#firstname").val();
	var l = $("#lastname").val();
	
	f= MakeCleanName(f);
	f= MakeCleanName2(f);
	
	l= MakeCleanName(l);
	l= MakeCleanName2(l);

	$("#nameoncard").val(f+" "+l);
	
}


function CheckNameonCard() {
	
	name = $("#nameoncard").val();
	name = MakeCleanName2(name);
	$("#nameoncard").val(name);
}


function MakeCleanName(f) {
	
	f = f.replace("ä","ae","g");
	f = f.replace("à","a","g");
	f = f.replace("á","a","g");
	f = f.replace("â","a","g");
	f = f.replace("ã","a","g");
	f = f.replace("ã","a","g");
	
	f = f.replace("è","e","g");
	f = f.replace("é","e","g");
	f = f.replace("ê","e","g");
	f = f.replace("ë","e","g");
	
	f = f.replace("Ä","Ae","g");
	f = f.replace("À","A","g");
	f = f.replace("Á","A","g");
	f = f.replace("Â","A","g");
	f = f.replace("Ã","A","g");
	f = f.replace("Ä","A","g");
	
	f = f.replace("È","E","g");
	f = f.replace("É","E","g");
	f = f.replace("Ê","E","g");
	f = f.replace("Ë","E","g");
	
	f = f.replace("Ì","I","g");
	f = f.replace("Í","I","g");
	f = f.replace("Î","I","g");
	f = f.replace("Ï","I","g");
	
	f = f.replace("ü","ue","g");
	f = f.replace("Ü","Ue","g");
	f = f.replace("ö","oe","g");
	f = f.replace("ò","o","g");
	f = f.replace("ó","o","g");
	f = f.replace("ô","o","g");
	f = f.replace("õ","o","g");
	
	f = f.replace("Ö","Oe","g");
	f = f.replace("Ò","O","g");
	f = f.replace("Ó","O","g");
	f = f.replace("Ô","O","g");
	f = f.replace("Õ","O","g");
	f = f.replace("Ö","O","g");
	
	f = f.replace("ß","ss","g");
	
	
	
	return f;
}


function MakeCleanName2(f) {
	return f.match(/[A-Za-z\.\-\s]*/);
}

/********************************************************************/
function SetSort(val) {
	old = $("#sort").val();	
	if (old==val) {
		if (val=="created_date DESC") val="created_date"; else val = val+" DESC";
	}
	$("#sort").val(val);
	
	document.selector.submit();
}

/********************************************************************/
function isMember() {
	if ($("#usertype").val()==6) return true; else return false;
}


/********************************************************************/
function checkCongress() {
	if ($("#congress").val()) return false; else return true;
}


/********************************************************************/
function checkEmail() {
	return "/file.php?f=ajax/checkemail.php&user_id="+$("#user_id").val();
}


/********************************************************************/
function checkSerial() {
	return "/file.php?f=ajax/checkserial.php&unit_id="+$("#unit").val();
}


function updateSerialCheck() {
	val = $("#serial").val();
	if (val) {
		$("#serial").val(val+".");
		$("#serial").valid();
		$("#serial").val(val);
		$("#serial").valid();
	}
}

function ShowAbstract(id) {
	$("#abstract_id").val(id);
	document.pubmed.submit();
}


function SetPage(ps) {
	$("#ps").val(ps);
	document.selector.submit();
}


function ShowLogin() {
	$("#dialog").show();
	$("#dialog").dialog("open");
	$("#dialog #un").focus();
}

function ShowPayBox() {
	$("#paybox").toggle();
	$("#registerformbox").toggle();
}

function DeselectApps() {
	$('#applications option').attr('selected', false);
}

function DeselectUnits() {
	$('#units option').attr('selected', false);
}

function SubmitAskExpert() {
	val = $("#question").val();
	if (val.length < 5) {
		alert("Please enter a question!");
	} else {
		document.form_askexpert.submit();
	}
}

/********************************************************************/
function DelPersonal(page,id) {
	if(confirm("Do you want to delete this "+page+" entry?")) {
		$.ajax({
			url: "/file.php?f=ajax/delpersonal.php",
			data: "id="+id,
			success: function(msg){
			$("#item_"+id).hide();
		}
		});
	}
}

function ViewFocus(item,name,id) {
	
	url = '/focus!/'+item+'/flash.html';
	window.open(url,name,"width=1280,height=1000,scrollbars=no");
	var data = "id="+id;
	$.post("/file.php?f=ajax/log_focus.php",data);
	
}


function ShowChangeUnit() {
	
	$(".btn_changeunitdatabox").html("");
	$("#changeunitdatabox").show();
	
}


function OpenCeus() {
	wnd = window.open('http://www.logiqclub.net/ceus/ceus.html','CEUS','scrollbars=no,width=1000,height=600');
	wnd.focus();
}