function msgType(msg){
	if(msg=='sales'){
		obj('supportContactForm').style.display='none';
		obj('salesContactForm').style.display='block';
	} else {
		obj('salesContactForm').style.display='none';
		obj('supportContactForm').style.display='block';
	}
}

function OnDocumentDblClick()
{
	obj('modalWindow').style.display = obj('modalBackground').style.display = 'block';

	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		var type = obj('hideType').value;
		
		if (type == 'iframe')
			obj('modalIframe').style.display = 'block';
		if (type == 'replace')
			ReplaceSelectsWithSpans();
	}

	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}
function hideNIC360(){
	obj('modalNIC360').style.display = 'none';
}
function showNIC360()
{
	obj('modalNIC360').style.display = obj('modalBackground').style.display = 'block';
	obj('viewer').style.overflow = 'hidden';
	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		var type = obj('hideType').value;
		
		if (type == 'iframe')
			obj('modalIframe').style.display = 'block';
		if (type == 'replace')
			ReplaceSelectsWithSpans();
	}

	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}


function OnWindowResize()
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = obj('modalWindow');
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
	if(obj('modalNIC360')){
		var div = obj('modalNIC360');
		div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
		div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
		
	}
	
}

function OnModalWindowClick()
{
	obj('modalWindow').style.display = obj('modalBackground').style.display = 'none';
	obj('supportName').value='';
	obj('supportEmail').value='';
	obj('supportCompany').value='';
	obj('supportPhone').value='';
	obj('supportProduct').value='';
	obj('supportSerial').value='';
	obj('supportVersion').value='';
	obj('contactMessage').value='';
	obj('contactName').value='';
	obj('contactEmail').value='';
	obj('contactCompany').value='';
	obj('contactPhone').value='';
	obj('contactTitle').value='';
	obj('contactMessage').value='';
	obj('createSupportError').innerHTML = '<span></span>';
	obj('createError').innerHTML = '<span></span>';
	if (obj('modalNIC360')){
		obj('modalNIC360').style.display = 'none';
	}
				
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		var type = obj('hideType').value;
		
		if (type == 'iframe')
			obj('modalIframe').style.display = 'none';
		if (type == 'replace')
			RemoveSelectSpans();
	}
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
		
}

/* These functions deal with IE's retardedness in not allowing divs to 
 * cover select elements by replacing the select elements with spans. */

function RemoveSelectSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}

function ReplaceSelectsWithSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className == 'selectReplacement')
		{
			continue;
		}
			
		var span = document.createElement('span');
		
		// this would be "- 3", but for that appears to shift the block that contains the span 
		//   one pixel down; instead we tolerate the span being 1px shorter than the select
		span.style.height = (select.clientHeight - 4) + 'px';
		span.style.width = (select.clientWidth - 6) + 'px';
		span.style.display = 'inline-block';
		span.style.border = '1px solid rgb(200, 210, 230)';
		span.style.padding = '1px 0 0 4px';
		span.style.fontFamily = 'Arial';
		span.style.fontSize = 'smaller';
		span.style.position = 'relative';
		span.style.top = '1px';
		span.className = 'selectReplacement';
		
		span.innerHTML = select.options[select.selectedIndex].innerHTML + 
			'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';
		
		select.cachedDisplay = select.style.display;
		select.style.display = 'none';
		select.parentNode.insertBefore(span, select.nextSibling);
	}
}
/* utiltiy functions */

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}

function setContactName(company){
	obj('contactFormCompany').innerHTML = company;
}

function checkInput(el, elError){
	if (obj(el).value==''){
		obj(el).style.background='#faafaa';
		if (obj(elError).innerHTML == ''){
			obj(elError).innerHTML = '<span></span>Must complete required fields';
		}
		return false;
	} else {
		obj(el).style.background = '#ffffff';
		return true;
	}
}

function sendMessage(){
	//alert(obj('contactFormCompany').innerHTML);
	obj('createError').innerHTML = '';
	if (checkInput('contactName','createError') && checkInput('contactEmail','createError') && checkInput('contactCompany','createError') && checkInput('contactPhone','createError') && checkInput('contactCountry','createError')){
		if (window.XMLHttpRequest){
			var http = new XMLHttpRequest();
		} else {
		  	var http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = "aj_sendMessage.php";
		var params = "contactName=" + 	obj('contactName').value;
		params += "&contactFormCompany=" + 	obj('contactFormCompany').innerHTML;
		params += "&contactEmail=" + 	obj('contactEmail').value;
		params += "&contactCompany=" + 	obj('contactCompany').value;
		params += "&contactPhone=" + 	obj('contactPhone').value;
		params += "&contactCountry=" + 	obj('contactCountry').value;
		params += "&contactTitle=" + 	obj('contactTitle').value;
		params += "&contactTechnology=" + obj('contactTechnology').value;
		params += "&contactSubject=" + obj('contactSubject').value;
		params += "&contactMessage=" + obj('contactMessage').value;
		http.open("POST", url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = function() {
			if(http.readyState == 4 && http.status == 200) {
				//obj('reportTicket').innerHTML = http.responseText;		
				obj('contactName').value='';
				obj('contactEmail').value='';
				obj('contactCompany').value='';
				obj('contactPhone').value='';
				obj('contactTitle').value='';
				obj('contactMessage').value='';
				obj('createError').innerHTML = '<span></span>Message sent.';
			}
		}
		http.send(params);	
	}
}

function sendSupportMessage(){
	//alert(obj('contactFormCompany').innerHTML);
	obj('createSupportError').innerHTML = '';
	if (checkInput('supportName', 'createSupportError') && checkInput('supportEmail', 'createSupportError') && checkInput('supportCompany', 'createSupportError') && checkInput('supportPhone', 'createSupportError')){
		if (window.XMLHttpRequest){
			var http = new XMLHttpRequest();
		} else {
		  	var http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = "aj_sendSupportMessage.php";
		var params = "supportName=" + 	obj('supportName').value;
		params += "&supportEmail=" + 	obj('supportEmail').value;
		params += "&supportCompany=" + 	obj('supportCompany').value;
		params += "&supportPhone=" + 	obj('supportPhone').value;
		params += "&supportCountry=" + 	obj('supportCountry').value;
		params += "&supportProduct=" + 	obj('supportProduct').value;
		params += "&supportSerial=" + 	obj('supportSerial').value;
		params += "&supportVersion=" + 	obj('supportVersion').value;
		params += "&supportMessage=" + 	obj('supportMessage').value;
		http.open("POST", url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = function() {
			if(http.readyState == 4 && http.status == 200) {
				//obj('reportTicket').innerHTML = http.responseText;		
				obj('supportName').value='';
				obj('supportEmail').value='';
				obj('supportCompany').value='';
				obj('supportPhone').value='';
				obj('supportProduct').value='';
				obj('supportSerial').value='';
				obj('supportVersion').value='';
				obj('supportMessage').value='';
				obj('createSupportError').innerHTML = '<span></span>Message sent.';
			}
		}
		http.send(params);	
	}
}
