
window.onbeforeprint = ExpandBeforePrint;
window.onafterprint = HideAfterPrint;
window.onresize = scrollFunc;

function ExpandBeforePrint()
{
	var scrolldiv = document.getElementById("scrolldiv");
	if (scrolldiv)
	{
		scrolldiv.style.overflow = "visible";
		scrolldiv.style.overflowY = "visible";
		scrolldiv.style.overflowX = "hidden";
		scrolldiv.style.height = "";
	}
}

function HideAfterPrint()
{
	var scrolldiv = document.getElementById("scrolldiv");
	if (scrolldiv)
	{
		scrolldiv.style.overflow = "scroll";
		scrolldiv.style.overflowY = "scroll";
		scrolldiv.style.overflowX = "scroll";
	}
	scrollFunc();
}

function scrollFunc()
{
	var curBodyHeight = document.body.clientHeight;

	var headerHeight = 100;
	//var bottomHeight = 153;	//old news
	
	var bottomHeight = 21;
	
	var trimmedNewsTable = document.getElementById("trimmedNews");
	if (trimmedNewsTable)
		bottomHeight = 68;	//we now use trimmed news	
	
	var maxHeight = 600;

	var MaxHeightAllowed = maxHeight - headerHeight - bottomHeight;
	var curHeightAllowed = curBodyHeight - headerHeight - bottomHeight;

	//default page don't have scroll bar it's not necessary
	var MainWhiteContent = document.getElementById("MainWhiteContent");
	var scrolldiv = document.getElementById("scrolldiv");
	if (scrolldiv)
	{
		var scrolldivHeight = scrolldiv.scrollHeight;	//height of white content
		var curMainWhiteContentHeight = MainWhiteContent.clientHeight;
		if (curHeightAllowed < scrolldivHeight)
			scrolldiv.style.height = curHeightAllowed - 20;
		else
			scrolldiv.style.height = '';
	}	
}//function

function gotoLink(link)
{
	var linkLocation = "";
	var qstringtxt = "";
	
	if (SessionID != "" && BCAcc != "")
	{
		qstringtxt = "?SessionID=" + SessionID + "&BCAcc=" + BCAcc;
	}
	else if (SessionID != "")
	{
		qstringtxt = "?SessionID=" + SessionID;
	}
	else if (BCAcc != "")
	{
		qstringtxt = "?BCAcc=" + BCAcc;
	}
	
	linkLocation = link + qstringtxt;	
	window.location.href = 	linkLocation;
	
}//function

function show_calendar(item)
{
	var ifrm =null;
	//item = eval(item);

	calenderField = item;
	
	if (document.getElementById)
		 ifrm = document.getElementById("todayCalendar");
	else if (document.all)
		 ifrm =  document.all("todayCalendar");
	if (ifrm != null)
	{
		ifrm.style.left = getLeft(item);
		ifrm.style.top = getBottom(item);
		ifrm.src = "todaycal.htm";
		ifrm.style.display = "";
	}	 
	else	 
	{
		var buf = "<iframe id='todayCalendar'"
				+ " style='position:absolute;"
				+ "left:" + getLeft(item)
				+ ";top:" + getBottom(item)
				+ ";width:20"
				+ ";height:20"
				+ "' src='todaycal.htm' scrolling=no></iframe>";
		document.body.insertAdjacentHTML("AfterBegin", buf);	
	}

	
}

function checkFill(numToLoop)
{
	for(var i = 1; i <= numToLoop; ++i)
	{
		if(eval("document.all('textfield"+i+"').value")=='')
		{
			alert("Please fill in all fields.");
			return false;			
		}		
	}
	
	return true;
	
}//function

function redirectProduct()
{
	var otherLoginObj = document.getElementById("otherlogin");
	if (otherLoginObj)
	{
		var productLink = otherLoginObj.options[otherLoginObj.selectedIndex].value;

		if (productLink == "")
			alert("Please select product from list!");
		else
			window.open(productLink,'_blank');
			//window.location._self = productLink;
	}
}//function

// get the absolute top position of given item
function getTop( item )
{
	var absTop = 0;
	while( item != null && item.tagName != "BODY" )
	{
		absTop += item.offsetTop;
		item = item.offsetParent;
	}
	return absTop;
}

function getBottom( item )
{
	var absBottom = getTop( item );
	absBottom += item.offsetHeight;
	return absBottom;
}
// get the absolute left position of given item
function getLeft( item )
{
	var absLeft = 0 ;
	while( item != null && item.tagName != "BODY" )
	{
		absLeft +=item.offsetLeft;
		item = item.offsetParent;
	}
	return absLeft;
}



function setNewsScrollBarPos(toppos)
{
	//when news or productsupdate is clicked, scrollbar pos should be set.	
	var NewsUpdateTable = document.getElementById("NewsUpdateTable");
	
	if (NewsUpdateTable)
	{
		//expand before setting scroll bar pos
		ExpandHideNews(ShowNewsID);
		var curNews = document.getElementById("news_" + ShowNewsID);
		var MainWhiteContent = document.getElementById("MainWhiteContent");
		var scrolldiv = document.getElementById("scrolldiv");
		
		if (curNews && MainWhiteContent && scrolldiv)
		{
			var WhiteContentTopPos = GetAbsolutePosition("top", MainWhiteContent);
			var curNewsTopPos = GetAbsolutePosition("top", curNews);
			
			var scrollbarPos = curNewsTopPos - WhiteContentTopPos;
			scrolldiv.scrollTop = scrollbarPos;
		}
	}
}//function

function GetAbsolutePosition(type, obj)
{
	var ret = 0;
	var offParent = obj;
	while(offParent && offParent.tagName != "BODY")
	{
		if(type == "left")
			ret += offParent.offsetLeft;
		else if(type == "top")
			ret += offParent.offsetTop;
		offParent = offParent.offsetParent;
	}
	return ret;
}

var closetimer = 0;

function showMenuLinks(t)
{
	//show links when cursor is pointing to current spanTopic, hide other links
	
	var showID = t.id;
	showID = showID.replace(/spanTopicID/g, "");
	var showLink = document.getElementById("TableLinksID" + showID);

	var tdMenu = document.getElementById("tdTopics");
	if (tdMenu)
	{
		//hide all links except t

		//var allspan = tdMenu.all.tags("span");
		var allspan = tdMenu.childNodes;

		for (var i = 0; i < allspan.length; i++)
		{
			curID = allspan[i].id;
			curID = curID.replace(/spanTopicID/g, "");

			allspan[i].style.color="white"; 

			var curLink = document.getElementById("TableLinksID" + curID);
			if (curLink)	//hide
			{
				curLink.style.display = "none";
			}

		}
		//now show the one that should show
		if (showLink)
		{
			showLink.style.display = "";
			showLink.style.visibility = "visible";
		}
		t.style.color="black"; 
	}//if (tdMenu)

	clearMenuTimeOut();
}//function

var signupBG = "url(images/signupbg1.gif)";
function setMenuLinkBG(t, setcolor, setothercolor)
{
	//t color set to setcolor, the rest set to setothercolor
	t.style.backgroundColor = setcolor;

	if (t.style.backgroundImage > "")
	{
		t.style.backgroundImage = "";
	}

	var allSpanTopicObj = t.parentNode.childNodes;
	
	for (var i = 0; i < allSpanTopicObj.length; i++)
	{
		if (t.id != allSpanTopicObj[i].id)
		{
			allSpanTopicObj[i].style.backgroundColor = setothercolor;
			
			//if span has background img, unhide it
			if (allSpanTopicObj[i].getAttribute("hasImageBackground") == "1")
			{
				allSpanTopicObj[i].style.backgroundImage = "" + signupBG;
			}
		}
	}//for
	
}//function

function resetMenuLinkBG(origcolor)
{
	//reset bg color in menu, this func needs to be called by hideMenuLinks to sync.
	var TopMenuTd = document.getElementById("tdTopics");

	var allSpanTopicObj = TopMenuTd.childNodes;
	
	for (var i = 0; i < allSpanTopicObj.length; i++)
	{
		allSpanTopicObj[i].style.backgroundColor = origcolor;
		allSpanTopicObj[i].style.color="white"; 		
	}
}//function

function clearMenuTimeOut()
{
	if (closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function hideMenuLinks(t, curid, bResetBGMenu)
{
	//hide links when cursor is not pointing to current spanTopic
	closetimer = window.setTimeout(function(){SetMenuLinkInvisible(t, curid, bResetBGMenu), curid = null},500);
}//function

function SetMenuLinkInvisible(t, curid, bResetBGMenu)
{
	document.getElementById("TableLinksID" + curid).style.visibility = 'hidden';
	document.getElementById("TableLinksID" + curid).style.display = 'none';
	
	var spanTopicIDObj = document.getElementById("spanTopicID" + curid);
	if (spanTopicIDObj)
	{
		if (spanTopicIDObj.style.backgroundImage > "")
		{
			var bgimageLink = "" + spanTopicIDObj.style.backgroundImage;
			bgimageLink = bgimageLink.replace(/_/g, "");
			spanTopicIDObj.style.backgroundImage = bgimageLink;
		}
	}
	
	if (bResetBGMenu)
	{
		resetMenuLinkBG('4F91CD');
	}
	//alert(curid);
}

function setInitialDisplayMenuLink()
{
	//call by onload, set current menu link

	var tdTopicsObj = document.getElementById("tdTopics");
	if (tdTopicsObj)
	{
		var allMenuSpans = tdTopicsObj.childNodes;
		for (var i = 0; i < allMenuSpans.length; i++)
		{
			//alert(allMenuSpans[i].getAttribute("curspanmenu"));
			//if (allMenuSpans[i].curspanmenu) firefox doesn't support
			if (allMenuSpans[i].getAttribute("curspanmenu"))
			{
				setMenuLinkBG(allMenuSpans[i], "A1C4E4", "4F91CD");
				showMenuLinks(allMenuSpans[i]);
			}
		}//for
	}

}//function

//keep track of the last news displaying on screen
var firstDisplayingNews = 1;
var numNewsToDisplay = 2;

function displayNews()
{
	//this function is to display news 
	//outerHTML, innerText, removeNode, childNodes[x], insertAdjacentHTML, document.all, .name="" ALL NOT WORKING on firefox!
	
	var allBanner = document.getElementsByName("BannerID");
	var TableBody = document.getElementById("tableTBody");
	
	if (TableBody)
	{
		while (TableBody.hasChildNodes())
		{
			TableBody.removeChild(TableBody.firstChild);
		}
	}

	//enable

	if (allBanner.length > 1)
	{
		for (var i = 0; i < numNewsToDisplay; i++)
		{
			var currentObj = allBanner[firstDisplayingNews - 1];	
			
			var newcurrentObj = currentObj.cloneNode(true);
			
			newcurrentObj.style.display="";
			newcurrentObj.name="";	//doesn't work on firefox!!!!!!!
			newcurrentObj.removeAttribute("name");	//have to use this for firefox!!!
			newcurrentObj.id="";

			if (firstDisplayingNews == allBanner.length)
			{
				TableBody.insertBefore(newcurrentObj, null);
				firstDisplayingNews = 1;
			}
			else
			{
				TableBody.insertBefore(newcurrentObj, null);		
				firstDisplayingNews++;
			}
		}//for
	}
	else if (allBanner.length > 0)
	{
		//only 1 item
		var currentObj = allBanner[0];	
		var newcurrentObj = currentObj.cloneNode(true);
			
		newcurrentObj.style.display="";
		newcurrentObj.name="";	//doesn't work on firefox!!!!!!!
		newcurrentObj.removeAttribute("name");	//have to use this for firefox!!!
		newcurrentObj.id="";
		TableBody.insertBefore(newcurrentObj, null);
		
	}
}//function

//keep track of the last testimonials displaying on screen
var curDisplayingTestimonial = 1;

function displayTestimonials()
{
	//this function is to display news 
	//outerHTML, innerText, removeNode, childNodes[x], insertAdjacentHTML, document.all, .name="" ALL NOT WORKING on firefox!
	
	var allTestimonials = document.getElementById("TestimonialTD");
	if (allTestimonials)
	{		
		var allTestimonialTables = allTestimonials.childNodes;

		//first remove all nodeType != 1
		for (var i = 0; i < allTestimonialTables.length; i++)
		{
			if (allTestimonialTables[i].nodeType != 1)
				allTestimonials.removeChild(allTestimonialTables[i]);
		}
		
		for (var i = 0; i < allTestimonialTables.length; i++)
		{
			var curid = "" + allTestimonialTables[i].id;
			curid = curid.replace(/TestimonialTable/g, "");
				
			if (curid == curDisplayingTestimonial)
				allTestimonialTables[i].style.display="";
			else
				allTestimonialTables[i].style.display="none";
		}
		
		if (allTestimonialTables.length == curDisplayingTestimonial)
			curDisplayingTestimonial = 1;
		else
			curDisplayingTestimonial++;

	}//if (allTestimonials)
}//function

//keep track of the last testimonials displaying on screen
var curAnimatedGifArray = 0;
function displayAnimatedGif()
{
	//this function is to display animated gif 
	//var GifArray = new Array("url('images/web_ad_1.gif')", "url('images/LDD-web-ad-2.gif')");
	var GifArray = new Array("url('images/ldd_bc.jpg')");
	var AnimatedGifTD = document.getElementById("animatedGifTD");
	if (AnimatedGifTD)
	{	
		//alert(1);
		AnimatedGifTD.style.backgroundImage = "" + GifArray[curAnimatedGifArray];
		
		//alert(AnimatedGifTD.style);
		curAnimatedGifArray++;
		
		//alert(typeof(GifArray[curAnimatedGifArray]));
		
		if (typeof(GifArray[curAnimatedGifArray]) == "undefined")
			curAnimatedGifArray = 0;

	}//if (AnimatedGifTD)
}//func

function ExpandHideNews(curid)
{
	var ExpandNewsObj = document.getElementById("DetailNews" + curid);
	if (ExpandNewsObj)
	{
		if (ExpandNewsObj.style.display == "")
			ExpandNewsObj.style.display = "none";
		else
			ExpandNewsObj.style.display = "";
	}//if (ExpandNewsObj)
}//function

function LTrim(str)
/*** PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim
RETVAL: An LTrimmed string!
***/
{

	var whitespace = new String(" \t\n\r");
	var s = new String(str);
			
	if (whitespace.indexOf(s.charAt(0)) != -1) 
	{
		// We have a string with leading blank(s)...
		var j=0;
		var i = s.length;
		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while ((j < i) && (whitespace.indexOf(s.charAt(j)) != -1))
			j++;
		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = s.substring(j, i);
	}
	return (""+s);
}
			
function Trim(str)
{
	return (""+RTrim(LTrim(str)));
}
			
function RTrim(str)
	/***
	PURPOSE: Remove trailing blanks from our string.
	IN: str - the string we want to RTrim
	RETVAL: An RTrimmed string!
	***/
{
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t");
	var s = new String(str);
				
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		// We have a string with trailing blank(s)...
		var i = s.length - 1;       // Get length of string
					
		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while ((i >= 0) && (whitespace.indexOf(s.charAt(i)) != -1))
			i--;
		// Get the substring from the front of the string to
		// where the last non-whitespace character is...
		s = s.substring(0, i+1);
		
	}	
	return (""+s);
}

function ExpandHideSection(detailSectionName, briefSectionName, curid, t)
{

	var curOption = Trim(t.innerHTML);
	var curDetailSection = document.getElementById(detailSectionName + curid);
	var curBriefSection = document.getElementById(briefSectionName + curid);
	if (curDetailSection && curBriefSection)
	{
		if (curDetailSection.style.display == "")
		{
			curBriefSection.style.display = "";
			curDetailSection.style.display = "none";
			t.innerHTML = "FULL TESTIMONIAL";
		}
		else
		{
			curBriefSection.style.display = "none";
			curDetailSection.style.display = "";
			t.innerHTML = "BRIEF TESTIMONIAL";
		}
	}//if

}//function

function ExpandCollapse(t, curid)
{
	//function name explains all
	//firefox doesn't support innerText!
	var curName = t.innerText;
	
	if (typeof(curName) == "undefined")
		curName = t.textContent;	//firefox

	curName = curName.replace(/ /g, "");
	curName = curName.toLowerCase();
	
	if (curName.indexOf("expand") != -1)
	{
		//expand full contents, hide brief contents
		t.innerHTML = "H<span style=\"font-size: 10px\">IDE</span> <img src=\"images/hidearrow.gif\" >";
		var curMainDiv = document.getElementById("MainFrame" + curid);
		if (curMainDiv)
		{
			curMainDiv.style.display = "";
		}
		
		var curBriefDiv = document.getElementById("BriefMainFrame" + curid);
		if (curBriefDiv)
		{
			curBriefDiv.style.display = "none";
		}
	}	
	else
	{
		//hide full contents, expand brief contents
		t.innerHTML = "E<span style=\"font-size: 10px\">XPAND</span> <img src=\"images/expandarrow.gif\" >";
		
		var curMainDiv = document.getElementById("MainFrame" + curid);
		if (curMainDiv)
		{
			curMainDiv.style.display = "none";
		}
		
		var curBriefDiv = document.getElementById("BriefMainFrame" + curid);
		if (curBriefDiv)
		{
			curBriefDiv.style.display = "";
		}		
	}
}//function

function ExpandHideDynamicFrame(curobjid, expandbgcolor, origcolor, t, bHideOtherTable)
{
	//this function is to expand/hide Dynamic Blue Frame
	if (expandbgcolor > "")
		expandbgcolor = expandbgcolor.toLowerCase();
	if (origcolor > "")
		origcolor = origcolor.toLowerCase();
		
	var SubItemsTable = document.getElementById(curobjid);
	
	if (SubItemsTable)
	{
		if (SubItemsTable.style.display == "none")
		{
			SubItemsTable.style.display = "";
			if (expandbgcolor > "")
			{
				SubItemsTable.style.backgroundColor = expandbgcolor;
				t.style.backgroundColor = expandbgcolor;
			}
			
			if (bHideOtherTable)
			{
				//hide everything else
				//bad but fast
				var tableNameToHide = curobjid.substr(0, curobjid.indexOf("_") + 1);
				
				var allTables = document.getElementsByTagName("table");
			
				for (var i = 0; i < allTables.length; i++)
				{
					var curtableid = "" + allTables[i].id;
					if (curtableid.indexOf(tableNameToHide) != -1)
					{
						if (curtableid != curobjid)
						{
							//hide
							allTables[i].style.display = "none";
							
							var bulletToHide = allTables[i].parentNode.parentNode.previousSibling;
							while (bulletToHide && bulletToHide.nodeType != 1)
							{
								bulletToHide = bulletToHide.previousSibling;
							}
							
							if (bulletToHide)
								bulletToHide.style.backgroundColor = origcolor;
						}
					}//if
				}//for
			}//need to hide other table				
		}
		else
		{
			//if redirectlink is called check if the obj that triggers the onclick is currently selected already
			//if so no need to set display: none and change color
			//otherwise screen will show hide then expand which dun look gd
			
			var bgcolor = "" + t.style.backgroundColor;
			var onclickfunc = "" + t.onclick;
			var bHideAndResetColor = true;
			
			if (onclickfunc.indexOf("redirectlink") != -1)
			{
				//firefox will only return rgb code, need to convert to hex	
				if (bgcolor.substr(0, 3) == "rgb")
					bgcolor = rgbToHex(bgcolor);
				
				if (bgcolor.indexOf(expandbgcolor) != -1)
				{
					//currently selected, do not hide;
					bHideAndResetColor = false;
				}				
			}
			
			if (bHideAndResetColor)
			{
				SubItemsTable.style.display = "none";		
				if (origcolor > "")
				{
					SubItemsTable.style.backgroundColor = origcolor;
					t.style.backgroundColor = origcolor;
				}
			}

		}//else
	}
}//function

function redirectlink(t, link, expandcolor)
{
	expandcolor = expandcolor.toLowerCase();
	gotoLink(link);
	/*
	if (t.style.backgroundColor.indexOf(expandcolor) != -1)
	{
		//alert(1);
		//alert("expandcolor: " + expandcolor);
		//alert(t.style.backgroundColor);
	}
	else
	{
		//alert(2);
		//alert("expandcolor: " + expandcolor);
		//alert(t.style.backgroundColor);
		
		gotoLink(link);
	}
	*/
	//alert(expandcolor);
	//alert(link);
}//redirectlink

function popupRefLetter(imgLink)
{	
	var url = "popupLetter.asp?img=" + imgLink;
	var dialogStyle = "dialogHeight:500px;dialogWidth:750px;help:no;status:no;resizable:yes"; 
	
	//alert(dialogStyle);
	
	//firefox doesn't support showModalDialog!
	if (window.showModalDialog)
		var diag = window.showModalDialog(url, "", dialogStyle);
	else
		window.open(url, "", "height=500,width=750,resizable=yes, scrollbars=yes");
}

function openWinDialog(url, dialogStyle)
{
	if (window.showModalDialog)
		var diag = window.showModalDialog(url, "", dialogStyle);
	else
		window.open(url, "", dialogStyle);
}

function showPage(codes, tableid, totalnum, t, pname, sectionToDisplay, bProductPage)
{	
	setTimeout(function() {     CallShowPage(codes, tableid, totalnum, t, pname, sectionToDisplay, bProductPage) }, 200) 	
}

//use by testimonials/products update left frame
function CallShowPage(codes, tableid, totalnum, t, pname, sectionToDisplay, bProductPage)
{
	//sayaboutname
	var sectionToDisplay = document.getElementsByName(sectionToDisplay);
	var highlightColor = "#F4F8FC";

	//show/hide main table
	for (var i = 0; i < sectionToDisplay.length; i++)
	{
		var codesArray = codes.split("|");
		var bcodeMatch = false;
		for (var j = 0; j < codesArray.length; j++)
		{
			if (bProductPage == "1")
				codesArray[j] = "|" + codesArray[j] + "|";
			
			var curbriefCode = sectionToDisplay[i].getAttribute("briefcode");
			if (curbriefCode)
			{
				if (curbriefCode.indexOf(codesArray[j]) != -1)
					bcodeMatch = true;
			}
			
		}//for
		
	
		if (bcodeMatch)
			sectionToDisplay[i].style.display = "";
		else
			sectionToDisplay[i].style.display = "none";
	}
	
	if (t)
	{
		for (var k = 1; k <= totalnum; k++)
		{
			var curTable = document.getElementById("BulletTable_" + k);
			
			var bulletSubitems = document.getElementsByName("bulletSubitemTR");
			for (var m = 0; m < bulletSubitems.length; m++)
			{
				bulletSubitems[m].style.backgroundColor = "";
			}
			
			/*
			var curTableTR = curTable.firstChild.childNodes;
			
			for (var m = 0; m < curTableTR.length; m++)
			{
				curTableTR[m].style.backgroundColor = "";
			}
			*/
			curTable.style.backgroundColor = "";
		}//for
		
		t.style.backgroundColor = highlightColor;
		
		if (pname > "")
		{
			var productname = document.getElementById("productname");
			if (productname)
			{
				productname.innerHTML = pname;
			}
		}
		
		var alleachtestimonialsproductname = document.getElementsByName("eachtestimonialsproductname");
		for (var n = 0; n < alleachtestimonialsproductname.length; n++)
		{
			alleachtestimonialsproductname[n].style.display = "none";
		}
		
	}
	else
	{
		for (var k = 1; k <= totalnum; k++)
		{
			var curTable = document.getElementById("BulletTable_" + k);
			
			var bulletSubitems = document.getElementsByName("bulletSubitemTR");
			for (var m = 0; m < bulletSubitems.length; m++)
			{
				bulletSubitems[m].style.backgroundColor = "";
			}
			
			/*
			var curTableTR = curTable.firstChild.childNodes;
			
			for (var m = 0; m < curTableTR.length; m++)
			{
				curTableTR[m].style.backgroundColor = "";
			}
			*/
			if (tableid != k)
			{
				if (curTable)
				{
					curTable.style.backgroundColor = "";	
				}	
			}
			else
				curTable.style.backgroundColor = highlightColor;
		}//for
		
		var productname = document.getElementById("productname");
		if (productname)
		{
			productname.innerHTML = "";
		}
		
		var alleachtestimonialsproductname = document.getElementsByName("eachtestimonialsproductname");
		for (var n = 0; n < alleachtestimonialsproductname.length; n++)
		{
			alleachtestimonialsproductname[n].style.display = "";
		}
		
	}
	
	var curNum = tableid - 1;
	var sayAboutName = document.getElementsByName("sayaboutname");
	var sayAboutNameText = "";
	
	if (sayAboutName.length > 0)
	{
		var cursayAboutName = sayAboutName[curNum];
		if (cursayAboutName)
			sayAboutNameText = sayAboutName[curNum].innerHTML;
	}	

	if (sayAboutNameText > "")
	{
		var productstypename = document.getElementById("productstypename");
		if (productstypename)
			productstypename.innerHTML = sayAboutNameText;
	}
		
}//showPage

function displayFinePrint(t, numToDisplay, totalFinePrintNum)
{
	var finePrintToDisplay = document.getElementById("FinePrint_" + numToDisplay);
	var highlightColor = "F4F8FC";

	if (finePrintToDisplay)
	{
		finePrintToDisplay.style.display = "";

		t.style.backgroundColor = highlightColor;
		for (var i = 0; i <= totalFinePrintNum; i++)
		{
			if (numToDisplay != i)
			{				
				var curFinePrint = document.getElementById("FinePrint_" + i);
				var curFinePrintRow = document.getElementById("finePrintFrameRow_" + i);
				
				//hide section, reset bg
				if (curFinePrint)
					curFinePrint.style.display = "none";	
				
				if (curFinePrintRow)
					curFinePrintRow.style.backgroundColor = "";
			}	
		}//for
	}
}//function

function FormCheck(numSection)
{
	for (var i = 1; i <= numSection; i++)
	{
		var curFormSection = document.getElementsByName("FormSection_" + i);
		var numPDFToGenerate = 1;
		alert(i + ": " + curFormSection.length);
		
		/*
		if (curFormSection.length > 0)
		{
			numPDFToGenerate = numPDFToGenerate * curFormSection.length;
		}
		*/
	}//for
}//function

function addNewSection(sectionNum, fieldsToCopy)
{
	var allSections = document.getElementsByName("FormSection_" + sectionNum);
	var fieldsArray = fieldsToCopy.split(",");

	bAddedNew = false;
	
	for (var i = 0; i < allSections.length; i++)
	{
		if (allSections[i].style.display == "none")
		{
			allSections[i].style.display = "";
			bAddedNew = true;
			
			var loopSectionNum = parseInt(i) + 1;
			var curDisplayLoopSection = document.getElementById("displayLoopSection" + loopSectionNum);

			if (curDisplayLoopSection)
			{
				curDisplayLoopSection.value= "1";
			}
			
			//var testdoc = alert(document.signupform.HasHighSpeedInternet1[0].checked);
			
			/*
			var testdoc = document.getElementsByName("HasHighSpeedInternet1");
			for (var m = 0; m < testdoc.length; m++)
			{
				alert("fff: " + testdoc[m].checked);
			}
			*/
			
			//always copy field from first set
			for (var j = 0; j < fieldsArray.length; j++)
			{
				var curFieldCopyFrom = document.getElementById(fieldsArray[j] + "1");
				var curFieldCopyTo = document.getElementById(fieldsArray[j] + loopSectionNum);
				if (curFieldCopyFrom && curFieldCopyTo)
				{
					curFieldCopyTo.value = curFieldCopyFrom.value;
				}//copy field value
			}//for j
			break;
		}
	}//for


	if (bAddedNew == false)
		alert("You are allowed to have a max of " + allSections.length + " section(s)!");

}//function

function checkOnSubmit()
{
	//SignupFormValidate();
	
	
	
	return true;
}//function

function SignupFormValidate(numSection)
{
	//validate field in signup form
	var bSubmitForm = true;
	for (var i = 1; i <= numSection; i++)
	{
		var curSection = document.getElementsByName("FormSection_" + i);
		for (var j = 0; j < curSection.length; j++)
		{
			//check only if section is not hidden
			if (curSection[j].style.display == "")
			{
				var inputsInCurSection = curSection[j].getElementsByTagName("input");

				for (var k = 0; k < inputsInCurSection.length; k++)
				{
					//var curInputValue = Trim(inputsInCurSection[k].value);
					var curInputValue = "" + inputsInCurSection[k].value;
					curInputValue = Trim(curInputValue);
					var bpasswordFlag = "";
					
					switch (inputsInCurSection[k].type)
					{
						case "hidden":
							break;
						case "text":
							if (curInputValue == "")
								bSubmitForm = false;
							break;
						case "password":
							if (curInputValue == "")
								bSubmitForm = false;
							else	
							{
								//next field probably is confirm password
								var confirmPasswordField = inputsInCurSection[k + 1];
								if (confirmPasswordField && confirmPasswordField.type == "password")
								{
									if (confirmPasswordField.value != curInputValue)
									{
										bpasswordFlag = 1;
									}
								}
							}
							break;	
						case "radio":
							var radioField = document.getElementsByName(inputsInCurSection[k].name);
							var bradioChecked = false;

							for (var m = 0; m < radioField.length; m++)
							{
								if (radioField[m].checked == true)
								{
									bradioChecked = true;
									break;
								}
							}//for m
							
							if (bradioChecked == false)
								bSubmitForm = false;
							
							break;
						default:	
								
					}
					
					
					if (bSubmitForm == false)
					{
						alert("Please fill in: " + inputsInCurSection[k].id);
						return bSubmitForm;
					}
					else if (bpasswordFlag == 1)
					{
						alert("password fields not the same, please re-enter password fields");
						return false;
					}
					
				}//for k	
			
				var inputsInCurSection = curSection[j].getElementsByTagName("select");
				for (var k = 0; k < inputsInCurSection.length; k++)
				{
					var curInputValue = "" + inputsInCurSection[k].value;
					curInputValue = Trim(curInputValue);
					var bpasswordFlag = "";
					if (curInputValue == "") {
						alert("Please fill in: " + inputsInCurSection[k].id);
						return false;
					}
				}
			}// if
		}//for j
		
	}//for i

	return bSubmitForm;
}//function

function rgbToHex(rgb) 
{
	//this function is to convert rgb code to hex
	//backgroundColor in firefox always return rgb
	
   rgb = rgb.replace(/rgb\(|\)/g, "").split(",");
   rgb[0] = parseInt(rgb[0], 10).toString(16).toLowerCase();
   rgb[1] = parseInt(rgb[1], 10).toString(16).toLowerCase();
   rgb[2] = parseInt(rgb[2], 10).toString(16).toLowerCase();
   rgb[0] = (rgb[0].length == 1) ? '0' + rgb[0] : rgb[0];
   rgb[1] = (rgb[1].length == 1) ? '0' + rgb[1] : rgb[1];
   rgb[2] = (rgb[2].length == 1) ? '0' + rgb[2] : rgb[2];
   return ('#' + rgb.join(""));
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

