var Nav  = navigator.userAgent.toLowerCase();
var isNS = Nav.indexOf('netscape') >= 0;
var isMoz= (Nav.indexOf('mozilla') >= 0) && (!isNS) && (!document.all);
var isOpera = Nav.indexOf('opera') >= 0;
var isIE = document.all && !isOpera;
var isMacIE = isIE && Nav.indexOf('mac') >= 0;
//var FlashInstalled = isFlashInstalled();
//var tBox = false;
//var onLoadScript = "";
//var HTTPS = false;

function fo(id){return document.getElementById(id)}

function isEmailValid(em)
{
  var p1=em.indexOf('@'), p2=em.lastIndexOf('.'), l=em.length; 
  return (p1 > 0) && (p2 > p1+1) && (p2 < l-1); 
}


function BoxHover(o,bHover,bKeepBG)
{
  function out(id)
  {
    var o = document.getElementById(id+"_top");
//    if (o) o.className = o.className.substr(0,o.className.indexOf(" "));
	if  ( o )	o.className	= "sidebarBoxGreyTop"
    o = document.getElementById(id+"_img0");
    if (o) o.style.display="";
    o = document.getElementById(id+"_img1");
    if (o) o.style.display="none";
    o = document.getElementById(id+"");
    if (o) o.style.backgroundPosition="0px 0px";
  }
  if (!window.out) window.out = out;
  if (bHover) {
    if (o.bHover == 2) return;
    o.bHover = bHover;
    if (o.timer) clearTimeout(o.timer);
    var id =o.id;
    o = document.getElementById(id+"_top");
//alert(o.className)
//    if(o) o.className += " hover";
	if  ( o )	o.className	= "sidebarBoxBlueTop"
    o = document.getElementById(id+"_img0");
    if (o) o.style.display="none";
    o = document.getElementById(id+"_img1");
    if (o) o.style.display="";
    o = document.getElementById(id+"");
    if (o && !bKeepBG) o.style.backgroundPosition="185px 0px";
  } else if (o.bHover != 2) o.timer = setTimeout("out('"+o.id+"')",10);
}

function PL_adjustPath(path) {
  if ((path.charAt(0)=='/' || path.charAt(0)=='\\') && window.location.href.substr(0,5)== 'file:') path = 'file:///D|/Inetpub/wwwroot' + path;
  return path;
}

function showTab(a,i,p)
{
	if  ( p + "" == "undefined" )	p = ""
	var o				= document.getElementById ( "selectedTab" + p )

	if  ( a == o || !o )	return

	o.id	= ""
	a.id				= "selectedTab"+p
	if  ( o.parentNode.className == "tabsBlock1" )
	{
		o.style.backgroundPosition	= "0px 0px"
		a.style.backgroundPosition	= "0px -39px"
	}

	var divs			= o.getElementsByTagName ( "div" )

	if  ( divs.length )
	{
		divs[0].style.fontWeight	= "normal"
		divs[1].style.fontSize		= "11px"
	}

	divs				= a.getElementsByTagName ( "div" )
	if  ( divs.length )
	{
		divs[0].style.fontWeight	= "bold"
		divs[1].style.fontSize		= "10px"
	}

  var j = 0;
  while (o=document.getElementById("tabPage"+p+(j++)))
    if (o.style.display == "block")
    {
      o.style.display = "none";
      break;
    }
  o=document.getElementById("tabPage"+p+i);
  if (o) o.style.display = "block";
}
function fireShowTab ( i )
{
  var o = document.getElementById ( "tabsLine" )
  if  ( !o )	return

  o = o.getElementsByTagName ( "a" )
//  alert(o[i].id)
  if  ( !o[i] )	return
  showTab ( o[i], i, '' )
//  alert(o[i].id)
	if  ( i == 1)	hideLeftSide ( "block" )
}
function showTabAndScroll ( i, id )
{
	fireShowTab ( i )

	if  ( id >= 0 )	id = "descr" + id

	var myScroll = new Fx.Scroll ( window )
	myScroll.toElement ( id )

}
function hoveringTab ( th )
{
	if  ( th.className.split("_")[1]+"" == "undefined" )
	{
		th.className	+= "_hover"
		th.style.cursor	= "pointer"
	}
	else
	{
		th.className = th.className.split("_")[0]+""
		th.style.cursor	= "default"
	}
}
function simpleTabHover ( th )
{
	if  ( th.id == "selectedTab" )	return;
	var pos	= th.style.backgroundPosition
	if  ( !pos  ||  pos == "0px 0px" )
		th.style.backgroundPosition	= "0px -39px"
	else
		th.style.backgroundPosition	= "0px 0px"
}
function cartUpdate ( id, isPack, isBack )
{
	if  ( isPack + "" == "undefined" )	isPack = 0
	if  ( isBack + "" == "undefined" )	isBack = 0

	var o	= fo ( "storeButton" + id )

	if  ( o.className == "storeAddButton" )
	{
		if  ( !isPack )		fo ( "discountField" + id ).style.color = "red"
		o.className = "storeRemoveButton"
		cartUpdateAdd ( id, 0, 0, isPack )
		if ( ! isBack )
		{
			if ( id == 36100 || id == 36200 )	id = 36
//			fo ( "ifr" ).src = "/buy.asp?noredir=1&prid=" + id + "&rnd=" + Math.random()
		}
		fo ( "selected" + id ).value	= 1
//		fo ( "totalItems" ).value ++
	}
		else
		{
			if  ( !isPack )		fo ( "discountField" + id ).style.color = "#7f7f7f"
			o.className = "storeAddButton"
			cartUpdateRemove ( id, 0, 0, isPack )
//			fo ( "ifr" ).src	= "/del.asp?prid=" + id + "&rnd=" + Math.random()
			fo ( "selected" + id ).value	= 0
//			fo ( "totalItems" ).value --
		}
}
function cartUpdateAdd ( id, noTotalCalculate, update, isPack )
{
	if  ( noTotalCalculate + "" == "undefined" )	noTotalCalculate = 0
	if  ( update + "" == "undefined" )		update = 0
	if  ( isPack + "" == "undefined" )		isPack = 0

	if  ( fo ( "storeButton" + id ).className != "storeAddButton" )
		if  ( ! noTotalCalculate && update )	cartUpdateTotal ( id, -1 )

	var priceUnit	= parseFloat	( fo ( "priceUnit" + id ).value.replace(",",".") )
	var subscr	= parseInt	( fo ( "subscrPeriod" + id ).value )
	var developers	= parseInt	( fo ( "developerQnt" + id ).value )

	if ( !developers )	window.location.href = "/contactus2.asp"

	var discount	= 0
	var discountS	= 80
	var discountP	= 0

	if ( isPack )	discountP = parseFloat ( fo ( "discountSuite" + id ).value.replace(",",".") )
	var discountT	= 0
	var price	= priceUnit
	var priceS	= 0

	switch ( developers )
	{
		case 3:		discount = 10;	break;
		case 4:		discount = 10;	break;
		case 5:		discount = 20;	break;
		case 6:		discount = 20;	break;
		case 7:		discount = 20;	break;
		default:	discount = 0;	break;
	}

	if ( subscr == 2 )
	{
		priceS		= developers * priceUnit * ( 100 - discountS ) / 100
		discountT	= developers * priceUnit * ( discountS - 50 ) / 100
	}

	price		= priceS + developers * priceUnit * ( 100 - discount ) / 100
	discountT	+= developers * ( priceUnit * discount / 100 + discountP )

	if  ( developers == 1  &&  subscr == 2 )
	{
		price		+= .01
		discount	+= .01
	}

	fo ( "price" + id ).value	= price.toFixed(2)
	fo ( "discount" + id ).value	= discountT.toFixed(2)

	fo ( "priceField" + id ).innerHTML	= "$ " + price.toFixed(2)
	if ( discountT > 0.01)
	{
		if ( isPack )	fo ( "discountField" + id ).innerHTML = "Saving you "
			else	fo ( "discountField" + id ).innerHTML = ""
		fo ( "discountField" + id ).innerHTML	+= "$ " + discountT.toFixed(2)
	}
	else
		fo ( "discountField" + id ).innerHTML	= "&nbsp;"

	if  ( fo ( "storeButton" + id ).className != "storeAddButton" )
		if  ( ! noTotalCalculate )	cartUpdateTotal ( id, 1 )
}
function cartUpdateRemove ( id )
{
	cartUpdateTotal ( id, -1 )

//	fo ( "priceField" + id ).innerHTML	= "&nbsp;"
//	fo ( "discountField" + id ).innerHTML	= "&nbsp;"
	fo ( "price" + id ).value		= 0
	fo ( "discount" + id ).value		= 0
}
function cartUpdateTotal ( id, sign )
{
	var priceTotal		= parseFloat ( fo ( "priceTotal" ).value.replace(",",".") )
	var discountTotal	= parseFloat ( fo ( "discountTotal" ).value.replace(",",".") )
	var price		= parseFloat ( fo ( "price" + id ).value )
	var discount		= parseFloat ( fo ( "discount" + id ).value )
//alert(priceTotal+"\n"+price)
	priceTotal	+= sign * price
	discountTotal	+= sign * discount

	fo ( "priceTotal" ).value	= priceTotal
	fo ( "discountTotal" ).value	= discountTotal

	if ( priceTotal > 0.01 )
		fo ( "priceTotalField" ).innerHTML	= "Total: $ " + priceTotal.toFixed(2) + " USD"
	else
		fo ( "priceTotalField" ).innerHTML	= "&nbsp;"
	if ( discountTotal > 0.01)
	{
		fo ( "discountTotalField" ).innerHTML	= "Saving you<br />$ " + discountTotal.toFixed(2)
		fo ( "priceTotalField" ).style.marginRight	= "0px"
		fo ( "discountTotalField" ).style.display	= "block"
	}
	else
	{
		fo ( "discountTotalField" ).innerHTML	= "&nbsp;"
		fo ( "discountTotalField" ).style.display	= "none"
		fo ( "priceTotalField" ).style.marginRight	= "24px"
	}
}
function syncById ( id, id1 )
{
//	alert (fo ( "developerQnt" + id ).selectedIndex)
	fo ( "developerQnt" + id1 ).selectedIndex	= fo ( "developerQnt" + id ).selectedIndex
	fo ( "subscrPeriod" + id1 ).selectedIndex	= fo ( "subscrPeriod" + id ).selectedIndex
	fo ( "priceField" + id1 ).innerHTML		= fo ( "priceField" + id ).innerHTML
	fo ( "discountField" + id1 ).innerHTML		= fo ( "discountField" + id ).innerHTML
	fo ( "price" + id1 ).value			= fo ( "price" + id ).value
	fo ( "discount" + id1 ).value			= fo ( "discount" + id ).value
	fo ( "storeButton" + id1 ).className		= fo ( "storeButton" + id ).className
}
function setDivFilter ( str, th )
{
	var o		= fo ( "selectedTab1" )
	var divs	= o.getElementsByTagName ( "div" )
	if  ( divs.length )
	{
		divs[0].style.fontWeight	= "normal"
		divs[1].style.fontSize		= "11px"
	}
	if (o)	o.id= ""

	th.id		= "selectedTab1"
	divs		= th.getElementsByTagName ( "div" )
	if  ( divs.length )
	{
		divs[0].style.fontWeight	= "bold"
		divs[1].style.fontSize		= "10px"
	}

	var arr		= document.getElementsByTagName ( "div" )
	var mids	= Array ()
	var count	= 0

	for ( var i = 0; i < arr.length; i ++ )
		if  ( arr[i].className == "storeItem" )
		{
			mids[count]	= arr[i]
			count ++
		}

	for ( i = 0; i < mids.length; i ++ )
		if ( mids[i].id.indexOf(str) < 0 )	mids[i].style.display	= "none"
			else if ( mids[i].style.display	!= "block" )
				mids[i].style.display	= "block"
}

function ToggleFaq(id)
{
  var o = fo ( id )

  var o1= fo(id+"res");
  if (o1)
  {
    if  ( o1.style.display == "none" )	o.className = "faqHDivExpanded"
	else	o.className = "faqHDiv"
    o1.style.display = (o1.style.display=="none"?"":"none");
  }
  var o = fo(id+"ico");
  if (o && o1) o.src = "/shared/img/" + (o1.style.display=="none"?"expand.gif":"contract.gif");
}

function ExpandAllFAQs(sIDtempl, bExpand)
{
	var i = 1;
	var o = null;

	while (o = fo(sIDtempl+i+"res"))
	{
		if ((o.style.display=="none") && (bExpand)) ToggleFaq(sIDtempl+i);
		if ((o.style.display!="none") && (!bExpand)) ToggleFaq(sIDtempl+i);
        ++i;
	}
}
function checkContactUsForm()
{
  var o, sErrMsg="";
  o = fo('name');
  if (o.value == "") {
    sErrMsg+="* Username is a required field.\n";
  }
  o = fo('email');
  if (!isEmailValid(o.value)) {
    sErrMsg+="* Enter your valid email address.\n";
  }
  o = fo('message');
  if (o.value == "") {
    sErrMsg+="* Description is a required field.\n";
  }
  var bOK = (sErrMsg=="");
  if (!bOK) alert(sErrMsg);
  return bOK;
}

function getDiscount ( priceUnit, developers, subscr )
{
	var discount	= 0
	var discountS	= 80
	var discountP	= 0
	var discountT	= 0
	var price	= 0

	switch ( developers )
	{
		case 3:		discount = 10;	break;
		case 4:		discount = 10;	break;
		case 5:		discount = 20;	break;
		case 6:		discount = 20;	break;
		case 7:		discount = 20;	break;
		default:	discount = 0;	break;
	}

	if ( subscr == 2 )
	{
		price		= developers * priceUnit * ( 100 - discountS ) / 100
		discountT	= developers * priceUnit * ( discountS - 50 ) / 100
	}

	price		+= developers * priceUnit * ( 100 - discount ) / 100
	discountT	+= developers * ( priceUnit * discount / 100 + discountP )

	if  ( developers == 1  &&  subscr == 2 )
	{
		price		+= .01
		discount	+= .01
	}

	var arr	= new Array(2)
	arr[0]	= price.toFixed ( 2 )
	arr[1]	= discountT.toFixed ( 2 )

	return arr
}
function buyNowEvent ( marg )
{
if  ( marg == "undefined" )	marg=24

	var value	= parseFloat	( fo ( "price" ).value )
	var subscr	= parseInt	( fo ( "subscrPeriod" ).value )
	var developers	= parseInt	( fo ( "developerQnt" ).value )

	if ( !developers )	window.location.href = "/contactus2.asp"

	fo ( "devQnt" ).value	= developers
	fo ( "subsc" ).value	= subscr

	var arr		= new Array (2)
	arr		= getDiscount ( value, developers, subscr )

	value		= arr[0]
	discountAbs	= arr[1]
	
/*
	var discount	= 0
	var discountAbs	= 0

	if ( subscr == 2 )
	{
		discountAbs	= 20
		value		= 1.5 * value - discountAbs
	}

	switch ( developers )
	{
		case 3:		discount = 10;	break;
		case 4:		discount = 10;	break;
		case 5:		discount = 20;	break;
		case 6:		discount = 20;	break;
		case 7:		discount = 20;	break;
		default:	discount = 0;	break;
	}

//	alert ( value + "\n" + subscr + "\n" + developers + "\n" + discount )
	discountAbs	*= developers
	discountAbs	+= value * developers * discount / 100
	discountAbs	= discountAbs.toFixed(2)
	value *= ( developers * ( 100 - discount ) / 100 )
	value = value.toFixed ( 2 )
*/

	fo ( "priceFinal" ).value	= value
	fo ( "priceField" ).innerHTML	= "$ " + value + " USD" + "<div id='discount'></div>"

//discountAbs=350
	if ( discountAbs > 0.1 )
	{
		fo ( "priceField" ).style.marginTop	= "16px"
		fo ( "discount" ).style.display		= "block"
		fo ( "discount" ).innerHTML		= "Saving you&nbsp;&nbsp;$" + discountAbs + ""
	}
		else
		{
			fo ( "priceField" ).style.marginTop	= marg+"px"
			fo ( "discount" ).style.display		= "none"
		}
}

function buyFromProducts ( id )
{
	fo ( "buyItemForm" ).action	= "/additem.asp?item=" + id
	fo ( "buyItemForm" ).submit()
}

function hideLeftSide ( param )
{
	fo ( "OurCln" ).style.display	= param
	fo ( "Brws" ).style.display	= param
	fo ( "Quote" ).style.display	= param
	fo ( "Tuts" ).style.display	= param
}

function changeCountry ( th )
{
	var o	= fo ( "strState" )
	if  ( !o )	return

	loadStates ( th.options[th.selectedIndex].value, "" )
}

function loadStates ( country, state )
{
//alert("c: "+ country+ "\n"+"s: "+state)

	var usaValue	= [ "AK", "AL", "AZ", "AR", "AA", "AE", "AP", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
			    "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT",
			    "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD",
			    "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" ]

	var usaText	= [ "Alaska",
			    "Alabama",
			    "Arizona",
			    "Arkansas",
			    "Armed Forces Americas",
			    "Armed Forces (General)",
			    "Armed Forces Pacific",
			    "California",
			    "Colorado",
			    "Connecticut",
			    "District of Columbia",
			    "Delaware",
			    "Florida",
			    "Georgia",
			    "Hawaii",
			    "Idaho",
			    "Illinois",
			    "Indiana",
			    "Iowa",
			    "Kansas",
			    "Kentucky",
			    "Louisiana",
			    "Maine",
			    "Maryland",
			    "Massachusetts",
			    "Michigan",
			    "Minnesota",
			    "Mississippi",
			    "Missouri",
			    "Montana",
			    "Nebraska",
			    "Nevada",
			    "New Hampshire",
			    "New Jersey",
			    "Mexico",
			    "New York",
			    "North Carolina",
			    "North Dakota",
			    "Ohio",
			    "Oklahoma",
			    "Oregon",
			    "Pennsylvania",
			    "Rhode Island",
			    "South Carolina",
			    "South Dakota",
			    "Tennessee",
			    "Texas",
			    "Utah",
			    "Vermont",
			    "Virginia",
			    "Washington",
			    "West Virginia",
			    "Wisconsin",
			    "Wyoming"
			  ]

	var canadaValue	= [ "AB", "BC", "MB", "NB", "NF", "NT", "NS", "NU", "ON", "PE", "QC", "SK", "YT" ]

	var canadaText	= [ "Alberta",
			    "British Columbia",
			    "Manitoba",
			    "New Brunswick",
			    "Newfoundland / Labrador",
			    "Northwest Territories",
			    "Nova Scotia",
			    "Nunavut",
			    "Ontario",
			    "Prince Edward Island",
			    "Quebec",
			    "Saskatchewan",
			    "Yukon"
			  ]

	var o	= fo ( "strState" )
	if  ( o.options.length > 1 )
		while  ( o.options.length )	o.remove ( 0 )

	if  ( country == "US" )
	{
		var statesText	= usaText
		var statesValue	= usaValue
	}

	if  ( country == "CA" )
	{
		var statesText	= canadaText
		var statesValue	= canadaValue
	}

	o.options[0]		= new Option ( "Select a State", "" )
	o.options[0].selected	= true
	o.options[0].disabled	= true

	if ( country != "US"  &&  country != "CA" )
	{
		o.disabled	= true
		return
	}

	o.disabled	= false

	for  ( var i = 0; i < statesText.length; i ++ )
	{
		o.options[i+1]	= new Option ( statesText[i], statesValue[i] )
		if  ( statesValue[i] == state )
			o.options[i+1].selected = true
	}
}
function sborderImgLoaded ( th )
{
	var p	= th

	while  ( p.className != "sborder" )	p = p.parentNode

	p.style.marginLeft	= ( p.parentNode.clientWidth - p.clientWidth ) / 2 + "px"

//	if ( p.className )	alert(p.clientWidth)
}