function setCheckboxes(the_form, do_check)
{
    var elts = the_form.elements['linkid[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else
}


//Cookie functions

function getArgs() {
	var args = new Object();
	// Get Query String
	var query = location.search.substring(1); 
	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 
		// if not found, skip to next
		if (pos == -1) continue; 
		// Extract the name
		var argname = pairs[i].substring(0,pos); 
		
		// Extract the value
		var value = pairs[i].substring(pos+1); 
		// Store as a property
		args[argname] = unescape(value);
	}
	return args; // Return the Object
}


// This function retreives the value of the tracking cookie
function getCookies () {
	// Get the document.cookie
	var dc = document.cookie;
        var args = new Object();
        // Split cookie at the semicolon
        var pairs = dc.split(";");
        // Begin loop through the cookie
        for(var i = 0; i < pairs.length; i++) {

                // Look for "name=value"
                var pos = pairs[i].indexOf('=');
                // if not found, skip to next
                if (pos == -1) continue;
                // Extract the name
                var argname = pairs[i].substring(0,pos);

                // Extract the value
                var value = pairs[i].substring(pos+1);
                // Store as a property
                args[argname.toLowerCase()] = unescape(value.toLowerCase());
        }
        return args; // Return the Object
}

// Gets the tracking code and makes it sticky
function getTrackingCode() {
	var args = getArgs();
	var cookies = getCookies();

	if (args.id) {
		clearCookie("id");
		setCookie("id", args.id, "60");
		return args.id;
	}
	if (cookies.id) {
		return cookies.id;
	}
	if (document.referrer.indexOf("google") != -1) {
		setCookie("id", "gs", "60");
		return "gs";
	}
	if (document.referrer.indexOf("yahoo") != -1) {
		setCookie("id", "yh", "60");
		return "yh";
	}
	return null;
}


function getCookieVal (offset) 
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
   endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) 
{
   var j = i + alen;
   if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
   i = document.cookie.indexOf(" ", i) + 1;
   if (i == 0) break; 
   }
return null;
}

function SetCookie (name, value) 
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : "/";
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function SetCookieEverlasting(name, value) 
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (2 * 365 * 24 * 3600 * 1000));
SetCookie(name,value,ExpireDate);
}

function DeleteCookie (name) 
{
var exp = new Date();
exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
SetCookie(name,"",exp);
//var cval = GetCookie ( name );
//document.cookie =name + "=" + cval + "; expires=" + exp.toGMTString();
}


//Qarbon demo functions
function isViewletCompliant()
{
  answer=true;
  version=Math.round(parseFloat(navigator.appVersion) * 1000);
  if (navigator.appName.substring(0,9) == "Microsoft")
  {
    if(version<4000) answer=false;
  }
  if (navigator.appName.substring(0,8) == "Netscape")
  {
    if ((navigator.appVersion.indexOf("Mac")> 0) && (version<5000))
      answer=false;
    else
    if (version<4060)
      answer=false;
  }

  plugins=navigator.plugins;
  if (answer==false && plugins!=null)
  {
    for(i=0;i!=plugins.length;i++)
    if((plugins[i].name.indexOf("Java Plug-in")>=0) && (plugins[i].name.indexOf("1.0")<0))
    answer=true;
  }
  return answer;
}

function openViewlet(htmlFile,htmlWidth,htmlHeight)
{
  str = 'resizable=0,toolbar=0,menubar=0,';
  str = str + 'scrollbars=0,status=0,location=0,directory=0,width=350,height=200';

  version=Math.round(parseFloat(navigator.appVersion) * 1000);

  if(navigator.appName.indexOf("Konqueror")!=-1) // konqueror
  {
    htmlWidth+=18;
    htmlHeight+=96;
  }

  if(navigator.appName.indexOf("Netscape")!=-1)
  {
    if(version>=5000)
    {
      if(navigator.appVersion.indexOf("Mac")!=-1) // Netscape6+ on mac
      {
        htmlHeight+=5;
      }
    }
  }

  if(navigator.appName.indexOf("Microsoft")!=-1)
  {
    if(navigator.appVersion.indexOf("Mac")!=-1) // IE on Mac
    {
       htmlWidth  -= 11;
       htmlHeight -= 11;
    }
  }

    if(!isViewletCompliant())
    {
      open("http://www.qarbon.com/warning/index.html",'Leelou',str);
    }
    else
    {
      window.open(htmlFile,'Leelou','width='+htmlWidth+',height='+htmlHeight+',top=10,left=20');
    }

}


//Qarbon demo functions
function isDemoOk(){     IsOk=true;     bver=Math.round(parseFloat(navigator.appVersion) * 1000);     if (navigator.appName.substring(0,8) == "Netscape")     {         if ((bver<5000) && (navigator.appVersion.indexOf("Mac")> 0))             IsOk=false;         else if (bver<4060)             IsOk=false;     }	 if (navigator.appName.substring(0,9) == "Microsoft")     {         if(bver<4000)             IsOk=false;     }     plugins=navigator.plugins;     if (plugins!=null && IsOk==false)     {         for(i=0;i!=plugins.length;i++)              if((plugins[i].name.indexOf("1.0")<0) && (plugins[i].name.indexOf("Java Plug-in")>=0))                  IsOk=true;     }     return IsOk;}


function openDemo2(htmlFile,htmlWidth,htmlHeight)
{
  var bua = navigator.userAgent;     
  s = 'resizable=0,toolbar=0,menubar=0,scrollbars=0,status=0,location=0,directory=0,width=350,height=200';
  if(!isDemoOk())
  { open("http://www.turbodemo.com/error.html",'',s); }
  else
  {
    if (bua.indexOf("Opera")!= -1)
    {
      window.open(htmlFile,'','width='+htmlWidth+',height='+htmlHeight+',top=10,left=10');
    }
    else
    {
      window.open(htmlFile,'','width='+htmlWidth+',height='+htmlHeight+',top=10,left=10');
    }
  }
}


function openDemo(htmlFile,htmlWidth,htmlHeight)
{ openDemo2( htmlFile+".htm",htmlWidth,htmlHeight); }


function getQuote()
{
  quote = new Array(1);
  quote[0] = "\"Can I suggest you mention this prog on Langa.com - Fred Langa's newsletter gets huge circulation and I'm sure many people would absolutely love this prog (and your others)\"<p><strong>Grant McIntosh</strong>";
  quote[1] = "\"DetachPipe has changed my life, making my PST files far smaller and easier to backup!\"<p>Andrew Simmonds</strong>";
  quote[2] = "\"Outlook is so much more reliable and stable with the DetachPipe Add On\"<p>Kullen Armstrong</strong>";
  quote[3] = "\"With DetachPipe.com I can send 100MB images, video and AutoCAD plans to my clients\"<p>Rowan Fredir - Architect</strong>";
  quote[4] = "\"I LOVE the abaility to see if a prospect has read my white paper!\"<p>Helen Cotswald - Online Sales</strong>";
  quote[5] = "\"Being able to revise a proposal before my client read it saved my life!\"<p>Mark Jeffreys - Enterprise Sales</strong>";

  //calculate a random index
  index = Math.floor(Math.random() * quote.length);

  return (quote[index]);
}


function showTestimonial()
{
  return (
"<div class=\"sideblock\"> " +
"<h4>What People Are Saying About DetachPipe</h4> " +
"<div class=\"quote\"><div> " +
getQuote() +
"</strong></div></div> " +
"<p style=\"text-align: right\"><a href=\"/customers.html\" title=\"More &gt;\"> " +
"<img src=\"/images/btn_more.gif\" width=\"53\" height=\"17\" alt=\"More &gt;\"></a></div>"
 );
}


function showSideBar()
{
  //don't show on home page
//  if ( (document.location.pathname != "/") &&
//       (document.location.pathname != "/index.html")
//     )
    document.write( showTestimonial() );
}


function phone()
{
  document.write( "USA Toll Free 1-800 831-8631" );
}


function checkandset( name, value )
{
  if ( !(GetCookie(name) && (GetCookie(name) != "") && (GetCookie(name) != "undefined")) )
    if (value && value != "")  SetCookieEverlasting( name, value );
}


function override( name, value )
{
  if (value && value != "")  
    SetCookieEverlasting( name, value );
}


//Set a cookie with the referring URL if it is not already set
checkandset( "jsreferrer", document.referrer );

var args = getArgs();

//download source
checkandset( "landing", document.location );

//these all come from the app and can be overridden
override( "src", args.src );   //download site
override( "application", args.application );
override( "ver", args.ver );
override( "source", args.source );    //which button or menu item
override( "daysrun", args.daysrun );
override( args.application + "_" + args.ver, args.daysrun + "_" + args.source );
override( "currency", args.currency );  

localTime = new Date();
checkandset( "timezone", localTime.getTimezoneOffset() / 60 );
