/*Documentation located in navigation.js.doc in Dev Team Sharepoint */

function Is() { 	
	var agent = navigator.userAgent.toLowerCase();  
	
	this.major = parseInt(navigator.appVersion);  
	this.minor = parseFloat(navigator.appVersion);  
	
	this.ns = ((agent.indexOf('mozilla')!=-1) && (agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1) );  
	this.ns2 = (this.ns && (this.major == 2)); 
	this.ns3 = (this.ns && (this.major == 3));  
	this.ns4b = (this.ns && (this.minor < 4.04));  
	this.ns4 = (this.ns && (this.major >= 4)); 
	this.ns6 = (this.ns && (this.major >= 6)); 
	this.ie = (agent.indexOf('msie') != -1);  
	this.ie3 = (this.ie && (this.major == 2));  
	this.ie4 = (this.ie && (this.major >= 4));  
	this.op3 = (agent.indexOf('opera') != -1); 
	this.ver5m=(this.major >= 5); 
}
var is = new Is();

function menuOnclick(target){

	scrollText(target);
}
 
/* Function & Variables for Scrolling Text */ 
var scrollSpeed = 30//higher number is slower scrolling
var lineDelay= 1200
var txt= ""
var pos = 0

function scrollText(pos,target) {
	targetMsg = target
  	message = " ^"
 	if (message.charAt(pos) != '^') {
		txt = txt + message.charAt(pos)
		status = txt
		pauze  = scrollSpeed
 	}
 	else {
	  	pauze = lineDelay
		txt= " "
		if (pos == message.length-1) pos = -1
 	}
 	pos++
 	setTimeout("scrollText('"+pos+"',targetMsg)",pauze)
  }
  
// document.URL.split will enable the capture of either http or https prefixes. 
// split_url[0] will equal either http or https.
var split_url = document.URL.split(':');
// document domain can get the domain for the server dynamically. EG. localhost or mt.com
var baseUrl = split_url[0] + '://' + document.domain;
var ie4 = false; if(document.all) { ie4 = true; }
var openImg = baseUrl + '/images_nav/open.gif';
var closeImg = baseUrl + '/images_nav/close.gif'; 

function getMBObject(id) {/* if (ie4) { return document.all[id]; } else { */ return document.getElementById(id); /*}*/}

function toggle(link, divId, state) { 	
	var obj1 = getMBObject(divId + "_open");
	var obj2 = getMBObject(divId + "_close");
	var d = getMBObject(divId);
	if (obj1 != null) {
		if (obj1.style.display=='') { 
			obj1.style.display='none';
			obj2.style.display='';
			d.style.display = 'block'; 
		} 
		else { 
			if (state != 'open') {
				obj1.style.display='';
				obj2.style.display='none';
				d.style.display = 'none'; 
			}
		} 
	}
}

function toggle2(link, divId) { 	
	var d = getMBObject(divId);
	showtext = getMBObject("show_all");
	if (d != null) {
		if (d.style.display=='none') { 
			d.style.display = 'block'; 
			showtext.style.display = 'none';
		} 
		else { 
			d.style.display = 'none';
			showtext.style.display = 'block';
			
		} 
	}
}
	
function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); }}

function showMenu(navID,n) { 
	var d = getObject(navID);
	d.style.display = 'block';
	d.style.left = '-1px';
	var nav = getObject("n"+n+"");
	
	var selectMenu = document.getElementsByTagName("SELECT");
	if (selectMenu[0] != null) {
		if (selectMenu[0].name != 'country') {
			if (selectMenu[0] != null) {
				selectMenu[0].style.visibility="hidden";
			}
		}
		if (selectMenu[1] != null) {
			selectMenu[1].style.visibility="hidden";
		}
		if (selectMenu[2] != null) 
			selectMenu[2].style.visibility="hidden";
	}
	document.onmouseup= new Function('hideMenu(\''+navID+'\',\''+n+'\')');
}


function hideMenu(navID,n) {
	var d = getObject(navID);
	d.style.left = '-1000px';
	var nav = getObject("n"+n+"");
	
	var selectMenu = document.getElementsByTagName("SELECT");
	if (selectMenu[0] != null) {
		/*if (selectMenu[0].name != 'country')*/ {
				if (selectMenu[0] != null) {
					selectMenu[0].style.visibility="visible";
				}
		}
		if (selectMenu[1] != null) 
			selectMenu[1].style.visibility="visible";
		if (selectMenu[2] != null) 
			selectMenu[2].style.visibility="visible";
	}
}

function initializeMenu() {
	var navItems = 3;
	for (n=1;n<=navItems;n++) {
		var mainSub = getObject("sub"+n+"");
	}
	var subMenu = document.getElementsByTagName("li");
	for (i=0; i<subMenu.length; i++) {
		subMenu[i].onmouseover=function() {
			this.className+=" over";
		}
		subMenu[i].onmouseout=function() {
			this.className=this.className.replace("over", "");
		}
		
	}
}

function showView(v1,v2,v3,v4,v5,v6) {
	var v = new Array(v1,v2,v3,v4,v5,v6);
	var a1 = getObject('mainview_link'); 
	var a2 = getObject('mainview');
	var b1 = getObject('secondview_link'); 
	var b2 = getObject('secondview');
	for (i=0;i<4;i++) {
		if(v[i]==1) {v[i]='block';} else {v[i]='none';}
	}
	a1.style.display = v[0]; a2.style.display = v[1]; b1.style.display = v[2]; b2.style.display = v[3];
}
	
	

/* Browserabfrage: Layer-Object bekannt? */
if (document.layers)
{ns = 1; ie = 0;}
else  {ns = 0; ie = 1;}


function browserCheck() {	
	if (!document.getElementById) {
		window.location = "/upgrade.html";
  		//alert("This browser is not compliant with the W3C Document Object Model standard!\nAs a result, these pages may not display properly.\nTo ensure the best browsing experience, please upgrade your browser.");
	}
}


function checkPageCache() {
  //placeSearchCursor();
  if (navigator.appName.indexOf("Microso")==0) {
 var c=cachetrick;
 if (!c.checked) c.checked=true;
 else location.reload();
  }
  initializeMenu();  
}

function placeSearchCursor()
{
	if (typeof document.searchform != 'undefined') {
		if (typeof document.searchform.QueryText != 'undefined') {
			document.searchform.QueryText.focus();
			//alert("Query Text");
		} else {
			//alert("No Query Text");	
		}
	} else {
		//alert("No Search Form");	
	}
}

function placeLoginCursor() {
	document.login_form.username.focus();
}

function popup(url, height, width){
  window.open(url, "", "height=" + height + ",width=" + width + ",scrollbars=yes,menubar=no,resizable=yes,titlebar=no,status=no,toolbar=no,menubar=no,location=no");
}


function submitCountrySelectForm(pDropDown, pDefaultValue, pFormObj, pText){
	var bProceed=0;
	
	if (pFormObj.cartLength.value > 0) {
		if (confirm(pText)) {
			bProceed=0;
		} else {
			bProceed=1;
		}
	}
	if (bProceed==0 && pDropDown.options[pDropDown.selectedIndex].value != ""
					&& pDropDown.options[pDropDown.selectedIndex].value != pDefaultValue) {
				pFormObj.submit();
	}
}

function countryChangeValidate(pDropDown, pDefaultValue, pFormObj, pText){
	var bProceed=0;
	if (pFormObj.cartLength.value > 0) {
		if (! confirm(pText)) {
			//Change back to default
			var tmpOptionValue = "";
			for (i = pDropDown.length - 1; i >= 0; i--) {
				tmpOptionValue = pDropDown[i].value;
				if ( pDefaultValue.indexOf(tmpOptionValue) > -1 && tmpOptionValue != '' ) {
					pDropDown[i].selected = true;
				}
			}
			return false;
		}
	}
}

function titrationSearchAll()
{
 javascript:document.getElementById('SubmitValue').value='LIST_ALL';
 document.titrationForm.submit();
}

// Email validator expression from
// http://www.breakingpar.com/bkp/home.nsf/Doc!OpenNavigator&U=87256B280015193F87256C40004CC8C6
function isEmailFieldInvalid(pTextObj) {
	var emailAddress = pTextObj.value;
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

	return !re.test(emailAddress);
}


function setChecked(bChecked,pChkID) {

  var formObj = document.profile_update;
  if (formObj != null) {
	var iElementLen = formObj.elements.length;

	var iLoop = 0;
	for( iLoop=0 ; iLoop < iElementLen; iLoop++) {
		if (formObj.elements[iLoop].id == pChkID) {
			formObj.elements[iLoop].checked = bChecked;
		}
	}
}
}

function checkChildren(bChecked,pParentID) {

	var formObj = document.profile_update;
	
	if (formObj != null) {
		var iCheckboxLen = formObj.elements.length;

		var iLoop = 0;
		var iParentLen = pParentID.length;
		var sElementID = "";

		for( iLoop=0 ; iLoop < iCheckboxLen; iLoop++) {
			sElementID = formObj.elements[iLoop].id;
			if (sElementID.length > iParentLen) {
				if (sElementID.substring(0, iParentLen) == pParentID) {
					formObj.elements[iLoop].checked = bChecked;
				}
			}
		}
	}
}

function checkTree(pCheckBox) {
	if (window.navigator.appName=="Microsoft Internet Explorer" && parseInt(window.navigator.appVersion) >= 4 ){
		var sCurrentID = pCheckBox.id;
		var sSplit = "/"
		var iLastSplit = 0;
		var sParent = "";
		var sCurrentNode = pCheckBox.id;		
		if (pCheckBox.checked == true) {
						iLastSplit = sCurrentNode.lastIndexOf(sSplit);
			while (iLastSplit > 0) {
				sParent = sCurrentNode.substring(0,iLastSplit);
				setChecked(true, sParent);
				sCurrentNode = sParent;
			 	iLastSplit = sCurrentNode.lastIndexOf(sSplit);
			}			
			checkChildren(true, sCurrentID + sSplit);
		} else { 			
			checkChildren(false, sCurrentID + sSplit);
		}
	}
}

function checkRadioTree(pRadioButton) {

	var formObj = document.profile_update;
	if (formObj != null) {
		var iRadioFormLen = formObj.elements.length;
	
		var sRadioID = pRadioButton.id;
		var sRadioName = pRadioButton.name;
		sRadioName = sRadioName.substring(0,sRadioName.length -1);
	
		var iLoop = 0;
		var sSplit = "/";
		var sElementID = "";
	
		var iRadioIDLen = sRadioID.length;
		var iLastSplit = sRadioID.lastIndexOf(sSplit);
		var sParent = sRadioID.substring(0,iLastSplit);
	
		//Loop through each Radio Button.
		for( iLoop=0 ; iLoop < iRadioFormLen; iLoop++) {
			sElementID = formObj.elements[iLoop].id;
			sElementName = formObj.elements[iLoop].name;
			sElementName = sElementName.substring(0,sElementName.length-1);
	
	
			//Make sure same Radio Button Array
			if (sRadioName == sElementName) {
				//  1)Check to make sure that only children of mine are checked.
				if (sElementID.length > iRadioIDLen) {
					//  If Path is longer, then if the Path does not start with the Current Name, then uncheck it.
					if (sElementID.substring(0, iRadioIDLen) != sRadioID) {
						formObj.elements[iLoop].checked = false;
					}
				} else {
					//Else if the Path is not longer, then definetly uncheck it.
					formObj.elements[iLoop].checked = false;
				}
	
				if (sElementID == sParent) {
					//  2)Check if my Parent is checked, if not, then check it.
					formObj.elements[iLoop].checked = true;
				}
			}
		}

		//Just incase it set the Current Button Off line, make sure it is checked
		pRadioButton.checked = true;
	}
}


function popup_full(url) {
  window.open(url, "", "scrollbars=yes,menubar=yes,resizable=yes,titlebar=yes,status=yes,toolbar=yes,menubar=yes,location=yes");
}


function resetForm(f) {
	for (i = 0; i < f.elements.length; i++)	{
		if (f.elements[i].type == "text") {
			f.elements[i].value = "";
		}
		else if (f.elements[i].type == "textarea") {
			f.elements[i].value = "";
		}
		else if (f.elements[i].type == "radio")	{
			f.elements[i].checked = false;
		}
		else if (f.elements[i].type == "checkbox"){
			f.elements[i].checked = false;
		}
		else if (f.elements[i].type == "select-one") {
			f.elements[i].selectedIndex = 0;
		}
	}
}

function resetSearchForm(f) {
  f.reset();
}


function isTxtFieldEmpty(pTextObj) {
	var fieldText = pTextObj.value.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ;

	if (fieldText.length > 0) {
		return false;
	} else {
		return true;
	}
}

function isDropDownEmpty(pDDObj) {
	if (pDDObj.options[pDDObj.selectedIndex].value.length > 0) {
		return false;
	} else {
		return true;
	}
}

function isStringEmpty(pStringObj) {
var fieldText = pStringObj.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ; 
if (fieldText.length > 0) {
 return false;
} else {
 return true;
}
}


function limitChars(ta, n){
  return (ta.value.length < n);
}	


function sfMouseover(linkObj) {
	linkObj.style.background='#E2F5D1';
}

function sfMouseout(linkObj) {
	linkObj.style.background='#ffffff';
}