function hover(who, baseClass, what) {
	var current;
	
	eval('current = who.className.match(/(Sel)?'+baseClass+'(Hover)?/);');
	current = current[0];
	
	if(what && current && current.search(/Hover$/) == -1) {
		eval('who.className = who.className.replace(/'+current+'/, "'+current+'Hover");');
	} else if(!what && current && current.search(/Hover$/) != -1) {
		eval('who.className = who.className.replace(/'+current+'/, "'+current.replace(/Hover$/, '')+'");');
	}
}

function select(who, baseClass, what) {
	var current;
	
	eval('current = who.className.match(/(Sel)?'+baseClass+'(Hover)?/);');
	current = current[0];
	
	if(what && current && current.search(/^Sel/) == -1) {
		eval('who.className = who.className.replace(/'+current+'/, "Sel'+current+'");');
	} else if(!what && current && current.search(/^Sel/) != -1) {
		eval('who.className = who.className.replace(/'+current+'/, "'+current.replace(/^Sel/, '')+'");');
	}
}

function parseStr(str) {
	var first = str.split('&');
	var data = new Array();
	
	for(var i = 0; i < first.length; i++) {
		var last = first[i].split('=');
		
		data[last[0]] = last[1];
	}
	
	return data;
}

function fixPNG(who) {
	var isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);
	if(isIE) {
		// filter for MSIE 6.x and 5.5
		var ie6xFilter = /^.*MSIE [6]\.[0-9].*$/;
		var ie55Filter = /^.*MSIE [5].*$/;
		
		if(ie6xFilter.test(navigator.userAgent) || ie55Filter.test(navigator.userAgent)) {
			who.onload = function(){}
			who.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+who.src+')';
			who.src = 'images/pixel.gif';
		}
	}
}

function outputPNG(imgSource, hoverSource, width, height, title) {	
	var isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);
	if(isIE) {
		// filter for MSIE 6.x and 5.5
		var ie6xFilter = /^.*MSIE [6]\.[0-9].*$/;
		var ie55Filter = /^.*MSIE [5].*$/;
		if (ie6xFilter.test(navigator.userAgent) || ie55Filter.test(navigator.userAgent)) {
			if (hoverSource) {
				document.write('<img src="images/pixel.gif" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+imgSource+');" onmouseover="this.filters(0).src=\''+hoverSource+'\';" onmouseout="this.filters(0).src=\''+imgSource+'\';" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');
			}
			else {
				document.write('<img src="images/pixel.gif" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+imgSource+');" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');
			}
		}
		else {
			if (hoverSource) {
				document.write('<img src="'+imgSource+'" onmouseover="this.src=\''+hoverSource+'\';" onmouseout="this.src=\''+imgSource+'\';" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
			}
			else {
				document.write('<img src="'+imgSource+'" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
			}
		}
	}
	else {
		if (hoverSource) {
			document.write('<img src="'+imgSource+'" onmouseover="this.src=\''+hoverSource+'\';" onmouseout="this.src=\''+imgSource+'\';" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
		}
		else {
			document.write('<img src="'+imgSource+'" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
		}
	}
}

function checkJS(what, where) {
	var needLoad;
	eval('needLoad = !document.'+what+';');
	if(needLoad)
		evalJSFrom(where);
}

function evalJSFrom(url) {
	var data = getPageDataDirect(url);
	
	if(data != null)
		eval(data);
}

function preload(imagePathArray) {
	var imageArray = new Array();
	for (var i = 0; i < imagePathArray.length; i++) {
		var nextImage = new Image();
		nextImage.src = imagePathArray[i];
		imageArray.push(nextImage);
	}
	return imageArray;
}

function submitForm(theForm, queryString, proccessFunction) {
	var data = '';
	
	if(theForm) {
		if(theForm.jt_submitted) {
			theForm.jt_submitted.value = 'isValid';
		}
		var formElements = theForm.elements;
	
		for(i = 0; i < formElements.length; i++) {
			if(formElements[i].disabled || ((formElements[i].type == 'radio' || formElements[i].type == 'checkbox') && !formElements[i].checked))
				continue;
				
			if(i)
				data += "&";
			
			if(formElements[i].options) {
				var valueAppend = '';
			
				for(k = 0; k < formElements[i].length; k++) {
					if(formElements[i].options[k].selected) {
						if(valueAppend != "") {
							valueAppend += ",";
						}
						
						valueAppend += formElements[i].options[k].value;
					}
				}
				
				data += escape(formElements[i].name) + '=' + escape(valueAppend);
			} else {
				data += escape(formElements[i].name) + '=' + escape(formElements[i].value);
			}
		}
	}
	
	sendRequest('view_controller.php', queryString, data, (proccessFunction ? proccessFunction : 'processDetailSlip(true);'));
}

function processDetailSlip(skipShowSlip) {
	if(httpReq.responseText.indexOf('--skipInnerHtml-->') == -1) {
		var el = document.getElementById('detailSlipContent');
		el.innerHTML = httpReq.responseText.replace(/\<script.+?\<\/script\>/g, '');
	}
	
	evalScripts(httpReq.responseText);
	
	if(!skipShowSlip) {
		showSlip('detail');
	}
}

function scrollFix(el, event) {
	if(window.event) {
		el.scrollTop -= (window.event.wheelDelta / 120 * 60);
		return false;
	} else if(this.scrollTop == 0 && event.wheelDelta > 0) {
		return false;
	} else if((el.scrollHeight - this.scrollTop) == el.offsetHeight && event.wheelDelta < 0) {
		return false;
	}
}

function evalScripts(data) {
	var index = data.indexOf('<script');
	var endIndex;
	
	while(index != -1) {
		index = data.indexOf('>', index) + 1;
		endIndex = data.indexOf('</script>', index);
		
		eval(data.substring(index, endIndex));
		
		index = data.indexOf('<script', endIndex);
	}
}

function setProfileContainerSize(content, animate) {
	var profileContainer = document.getElementById('profileContainer');
	
	if(profileContainer && content && profileContainer.offsetHeight-6 != content.offsetHeight) {
		if(animate) {
			if(profileContainer.animation) {
				profileContainer.animation.stop();
			}
			
			profileContainer.animation = new Fx.Styles(profileContainer.id, {duration: 750, transition: Fx.Transitions.quartOut, onComplete: function() {
					profileContainer.animation = null;
				}
			});
			profileContainer.animation.start({
				'height': [profileContainer.offsetHeight-6, content.offsetHeight]
			});
		} else {
			profileContainer.style.height = (content.offsetHeight+6)+'px';
		}
	}
}

function setSlipScrollers(container, overflow) {
	var divs = container.getElementsByTagName('div');
	for(var i = 0; i < divs.length; i++) {
		if(divs[i].className == 'slipScroller') {
			divs[i].style.overflow = overflow;
		}
	}
}

function processProfile(slideTo) {
	if(httpReq.responseText.indexOf('--skipInnerHtml-->') == -1) {
		var profileContent = document.getElementById('profileContent');
		
		if(profileContent) {
			if(httpReq.responseText.indexOf('--skipSlide-->') != -1) {
				profileContent.innerHTML = httpReq.responseText.replace(/\<script.+?\<\/script\>/g, '');
				evalScripts(httpReq.responseText);
				setProfileContainerSize(profileContent, true);
			} else {
				var profileScroller = document.getElementById('profileScroller');
				var newContent = document.createElement('div');
				
				if(!profileScroller.animation) {
					newContent.className = 'profileContent';
					newContent.style.left = (profileContent.offsetLeft + profileContent.offsetWidth)+'px';
					newContent.style.top = profileContent.offsetTop+'px';
		
					newContent.innerHTML = httpReq.responseText.replace(/\<script.+?\<\/script\>/g, '');
					
					profileScroller.appendChild(newContent);
					
					if(httpReq.responseText.indexOf('--evalScriptsOnSlide-->') == -1) {
						evalScripts(httpReq.responseText);
					}
					
					if(slideTo == 'left') {
						newContent.style.left = (profileContent.offsetLeft - profileContent.offsetWidth)+'px';
					} else if(slideTo == 'top') {
						newContent.style.left = (profileContent.offsetLeft - ((profileContent.offsetWidth - newContent.offsetWidth) / 2))+'px';
						newContent.style.top = (profileContent.offsetTop - newContent.offsetHeight)+'px';
					} else if(slideTo == 'bottom') {
						newContent.style.left = (slipContent.offsetLeft - ((slipContent.offsetWidth - newContent.offsetWidth) / 2))+'px';
						newContent.style.top = (slipContent.offsetTop + slipContent.offsetHeight)+'px';
					}
					
					setSlipScrollers(profileContent, 'hidden');
					
					setProfileContainerSize(newContent, true);
		
					profileScroller.animation = new Fx.Styles(profileScroller.id, {duration: 750, transition: Fx.Transitions.quartOut, onComplete: function() {
							profileScroller.removeChild(profileContent);
							newContent.id = 'profileContent';
							setSlipScrollers(newContent, 'auto');
							if(httpReq.responseText.indexOf('--evalScriptsOnSlide-->') != -1) {
								evalScripts(httpReq.responseText);
							}
							profileScroller.animation = null;
						}
					});
		
					profileScroller.animation.start({
						'left': [profileScroller.offsetLeft, -newContent.offsetLeft],
						'top': [profileScroller.offsetTop, -newContent.offsetTop]
					});
				}
			}
		}
	} else {
		evalScripts(httpReq.responseText);
	}
}

function profileDisplay(item, value, content) {
	var el = document.getElementById(content);
	
	if(item.value == value) {
		el.style.display = 'block';
	} else {
		el.style.display = 'none';
	}
	
	setProfileContainerSize(document.getElementById('profileContent'), true);
}

document.profileUploadFinish = function(job) {
	submitForm(document.getElementById('profileForm_3'), 'what=getProfileStep&to=4&from=3&job='+job, 'processProfile();');
}

function GetSymptomCheckerURL(docHWID, secHWID) {
	var url =  "healthlibrary_library_healthguide_en-us_illnessconditions_topic.asp?hwid=" + secHWID;
	return url;
}