//----------------------------------------------------------------------------------------------------
//-- enlarge image pop-up page code
//-- call this script: <a href="javascript:openWin('imageURL','imageWidth','imageHeight');">
//----------------------------------------------------------------------------------------------------

var props;
var leftPosition;
var topPosition;
var pageWidth;
var pageHeight;
var smallWindow = null;

function closeWin(){
	if (smallWindow != null){
		if(!smallWindow.closed)
			smallWindow.close();
	}
}

function openWin(imageURL,imageWidth,imageHeight) {

	closeWin();

	pageWidth = parseInt(imageWidth) + 38; 
	pageHeight = parseInt(imageHeight) + 70;

	leftPosition = (screen.width) ? ((screen.width-pageWidth)/2) : 10;
	topPosition = (screen.height) ? ((screen.height-pageHeight)/2) : 10;
	props = "width=" + pageWidth + ",height=" + pageHeight + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=yes,scrollbars=yes";

	smallWindow = window.open("","Image",props);
	smallWindow.document.writeln('<html>');
	smallWindow.document.writeln('<head>');
	smallWindow.document.writeln('<title>Click image to close</title>');
	smallWindow.document.writeln('<link rel="stylesheet" href="/css/main.css" media="all" type="text/css" />');
	smallWindow.document.writeln('</head>');
	smallWindow.document.writeln('<body class="popup">');
	smallWindow.document.writeln('<table cellpadding="0" cellspacing="0"><tr><td><a href="javascript:self.close();"><img src="' + imageURL + '" width="' + imageWidth + '" height="' + imageHeight + '" alt="Click image to close" title="Click image to close" border="0" /></a></td></tr>');
	smallWindow.document.writeln('<tr><td align="center" style="font-family:Verdana,Arial,Helvetica;font-size:.8em;"><br /><a href="javascript:self.close();">Close Window</a></td></tr></table>');
	smallWindow.document.writeln('</body>');
	smallWindow.document.writeln('</html>');
	smallWindow.document.close();
	smallWindow.focus();
}

//----------------------------------------------------------------------------------------------------
//-- global left-nav contact form functions
//----------------------------------------------------------------------------------------------------

function validateContactForm() {
	if ((document.WEBForm_ContactSales.FullName__c.value.length == 0) || 
		(document.WEBForm_ContactSales.EmailAddress.value.length == 0) ||
		(document.WEBForm_ContactSales.WorkPhone.value.length == 0) ||
		(document.WEBForm_ContactSales.Company.value.length == 0) ||
		(document.WEBForm_ContactSales.Country.value.length == 0) ||
		(document.WEBForm_ContactSales.Region.value.length == 0 && (document.WEBForm_ContactSales.Country.value == "US" || document.WEBForm_ContactSales.Country.value == "CA"))) {
		//alert("Some field is blank");
		document.getElementById("formErrorMessage1").style.display="block";
		document.getElementById("formErrorMessage2").style.display="none";
	}
	else if ((document.WEBForm_ContactSales.EmailAddress.value.indexOf("@") < 0) ||
			 (document.WEBForm_ContactSales.EmailAddress.value.indexOf(".") < 0)) {
		//alert("Email field is NOT valid.");
		document.getElementById("formErrorMessage2").style.display="block";
		document.getElementById("formErrorMessage1").style.display="none";
	}
	else {
		//alert("Looks good!");
		mtcSubmitForm(document.WEBForm_ContactSales);
	}
}

function clearContactForm() {
	if (document.getElementById("contact-form-header") != null) {
		document.getElementById("contact-form-header").style.backgroundImage="url(/img/contact-form-arrow-down.gif)";
		document.getElementById("contactFormSubSec").style.display="none";
		document.getElementById("formErrorMessage1").style.display="none";
		document.getElementById("formErrorMessage2").style.display="none";
		document.getElementById("WEBFormContactSales").reset();
	}
}

//----------------------------------------------------------------------------------------------------
//-- worldwide dropdown scripts
//----------------------------------------------------------------------------------------------------

function hideDropdownWW() {
	document.getElementById('dropdown-ww1-here').style.borderTop="solid 1px #FFFFFF";
	document.getElementById('dropdown-ww1-here').style.borderLeft="solid 1px #FFFFFF";
	document.getElementById('dropdown-ww1-here').style.borderRight="solid 1px #FFFFFF";
	//document.getElementById('dropdown-ww1-here').style.borderBottom="solid 1px #878787";
}
function showDropdownWW() {
	document.getElementById('dropdown-ww1-here').style.borderTop="solid 1px #878787";
	document.getElementById('dropdown-ww1-here').style.borderLeft="solid 1px #878787";
	document.getElementById('dropdown-ww1-here').style.borderRight="solid 1px #878787";
	//document.getElementById('dropdown-ww1-here').style.borderBottom="solid 1px #878787";
}

//----------------------------------------------------------------------------------------------------
//-- contact form drop-down code
//----------------------------------------------------------------------------------------------------

function openContactPopup() {
	closeWin();

	pageWidth = 675; 
	pageHeight = 275;

	leftPosition = (screen.width) ? ((screen.width-pageWidth)/2) : 10;
	topPosition = (screen.height) ? ((screen.height-pageHeight)/2) : 10;
	props = "width=" + pageWidth + ",height=" + pageHeight + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=yes,scrollbars=yes";

	smallWindow = window.open("/company/contact-form.aspx","mywindow",props);
}

function hideShowContactSection(secId, imgId, mouseoverOrClick) {
	var sec = document.getElementById(secId);
	var img = document.getElementById(imgId);
	
	var testString = new String(img.id);

	if (sec.style.display == "block") {
		if (mouseoverOrClick == "click") {
			sec.style.display = "none";
			if (testString.indexOf("contact") > -1) {
				img.style.backgroundImage="url(/img/contact-form-arrow-down.gif)";
			} else {
				img.src = "/img/icons/icon-plus.gif";
			}
		}
	}
	else {
		sec.style.display = "block";
		if (testString.indexOf("contact") > -1) {
			img.style.backgroundImage="url(/img/contact-form-arrow-up.gif)";
		} else {
			img.src = "/img/icons/icon-minus.gif";
		}
		
	}			  
}

//----------------------------------------------------------------------------------------------------
//-- print popup code
//----------------------------------------------------------------------------------------------------

function openPrintPopup(theURL) {
	closeWin();

	pageWidth = 700; 
	pageHeight = 600;

	leftPosition = (screen.width) ? ((screen.width-pageWidth)/2) : 10;
	topPosition = (screen.height) ? ((screen.height-pageHeight)/2) : 10;
	props = "width=" + pageWidth + ",height=" + pageHeight + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=yes,scrollbars=yes";

	smallWindow = window.open(theURL,"printpreview",props);
}

if (window.name == "printpreview") {
	document.write('<link rel="stylesheet" href="/css/main-blogs-print.css" type="text/css" media="all" />');
	document.write('<![if !IE]><style media="all">* { overflow: visible !important; }</style><![endif]>');
}

//----------------------------------------------------------------------------------------------------
//-- additional worldwide drop-down code (taken from leftnav-us.js file on Planview.com)
//----------------------------------------------------------------------------------------------------

function hideShowSection(secId, imgId) {
	var sec = document.getElementById(secId);
	var img = document.getElementById(imgId);
	
	var testString = new String(img.id);

	if (sec.style.display == "block" || (sec.style.display == "" && sec.className.indexOf("nodisplay") < 0)) {
		sec.style.display = "none";
		if (testString.indexOf("contact") > -1) {
			img.style.backgroundImage="url(/img/contact-form-arrow-down.gif)";
		} else {
			img.src = "/img/icons/icon-plus.gif";
		}
	}
	else {
		sec.style.display = "block";
		if (testString.indexOf("contact") > -1) {
			img.style.backgroundImage="url(/img/contact-form-arrow-up.gif)";
		} else {
			img.src = "/img/icons/icon-minus.gif";
		}
		
	}			  
}
  
function showFlyout(anchorElement, popupDiv, flag){
// alert(findPosX( document.getElementById('imgfly2')));
 
	if(document.getElementById(popupDiv).id=='flyout2'){     
		//alert(findPosX( document.getElementById(anchorElement)));
		//alert(findPosY( document.getElementById(anchorElement)));
	}
	
	if(flag) {		
			var yCoord = findPosY(document.getElementById(anchorElement)) - (document.getElementById(popupDiv).offsetHeight);
			var xCoord = findPosX(document.getElementById(anchorElement)) + 8;
			
			document.getElementById(popupDiv).style.display="block";
			document.getElementById(popupDiv).style.left = xCoord + "px";
			document.getElementById(popupDiv).style.top = yCoord + "px";
			
			(document.getElementById(popupDiv).offsetHeight);
		
	  }else{
		 
		   if(onFlyout) {
		      //do nothing
		 }else{	
			//document.getElementById(popupDiv).style.display="none"; 
			//no longer need this but leaving it for debug reasons
		    }//end if onFlyout
		}
	}
	
function showDropdown(anchorElement, popupDiv, flag){ 	
	if(flag) {		
			if((document.getElementById(popupDiv).style.display=="none") || (document.getElementById(popupDiv).style.display=="")) {
			
				var yCoord = findPosY(document.getElementById(anchorElement)) - (document.getElementById(popupDiv).offsetHeight);
				var xCoord = findPosX(document.getElementById(anchorElement)) + 8;
			
				document.getElementById(popupDiv).style.display="block";
				document.getElementById(popupDiv).style.left = (xCoord - 179) + "px";
				document.getElementById(popupDiv).style.top = (yCoord + 18) + "px";
			
				(document.getElementById(popupDiv).offsetHeight);
			}
			else {
				document.getElementById(popupDiv).style.display="none";
			}
	  }else{
		 
		   if(onFlyout) {
		      //do nothing
		 }else{	
			//document.getElementById(popupDiv).style.display="none"; 
			//no longer need this but leaving it for debug reasons
		    }//end if onFlyout
		}
	}	

function findPosX(obj)
{
		var curleft = 0;
		if (obj.offsetParent)
		{
				while (obj.offsetParent)
				{
						curleft += obj.offsetLeft
						obj = obj.offsetParent;
				}
		}
		else if (obj.x)
				curleft += obj.x;
		return curleft;
}

function findPosY(obj)
{
		var curtop = 0;
		if (obj.offsetParent)
		{
				while (obj.offsetParent)
				{
						curtop += obj.offsetTop
						obj = obj.offsetParent;
				}
		}
		else if (obj.y)
				curtop += obj.y;
		return curtop;
}

//----------------------------------------------------------------------------------------------------
//-- 
//----------------------------------------------------------------------------------------------------
