//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() 
{
//mandatory
var name = arguments[0];
var value = arguments[1];

var expires = (arguments.length > 2) ? arguments[2] : null;
var path = (arguments.length > 3) ? arguments[3] : "/";
var domain = (arguments.length > 4) ? arguments[4] : null;
var secure = (arguments.length > 5) ? arguments[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); }

var currentQuote;
  

function getQuote()
{
  quote = new Array(10);
  quote[0] = "\"...despite all these bells and whistles, it's amazingly easy to use.\" <p><strong>ZDNet Review<br>download.com</strong>";
  quote[1] = "\"I just wanted to congratulate your company on a fine piece of software. Not only do I find the software intellectually stimulating (I haven't come across something so fine in at least ten years) but the software works like a dream. This software has revolutionised the way I work on a large aspect of my IT Consultancy business. What used to take hours to do now only takes minutes. It has provided me with a cutting edge tool to compete with, against other IT Consultant companies, in data mining and data manipulation. Used in conjunction with the database development I provide my clients I am able to reduce their costs, and provide a faster and more accurate service.\"<p><strong>Andrew Phillips<br>ExpertComSoftware</strong>";
  quote[2] = "\"I wanted to let you how much I've appreciated having TextPipe Pro in my \"tool box\". It is easily one of the best utilities I have ever used, particularly because it does text cleaning, correction, and organization with ease in ways other programs can't or do only with difficulty. In the court community, I often have to work with very dirty / challenging data sets that haven't been properly edited or checked and that's when TextPipe comes in very handy...TextPipe is great for a million other things that word processors and standard software can't do. You've a great product and the high quality of your service and nearly immediate response time has been equally spectacular\"<p><strong>Edwin Kennedy, Ph.D<br>Director<br>CourtStats.com</strong>";
  quote[3] = "\"I just wanted to let y'all know that I can attribute my 7 person and growing company to TextPipe Pro. Practically every developer I've met has turned their nose up at TextPipe. It usually isn't long before a problem comes up, and I recommend a TextPipe solution, which they inevitably ignore, and then go screw up royally using some other method. Fortunately I have TextPipe to save the day. I'm not a developer, but maybe I should have been.\"<p><strong>Joseph Ring<br>CEO<br>Ring Marketing</strong>";
  quote[4] = "\"What I can say is that it's an incredible 'Swiss Army knife' of a tool that quickly became a part of my everyday work life. It was easy to pick up and apply on the fly to do things like text clean-up, perform columnar search and replace, reformatting output files, etc. You can use it the first minute you have it, but it's also something you'll grow into...\"<p><strong>David Zimmerman<br>Market Data Center</strong>";
  quote[5] = "\"So far it has saved me tons of work! I manage a fairly large website (4500 pages), and was able to completely revamp all pages at the same time, instead of one at a time!\"<p><strong>Vincent Beaulieu<br>SASS Webmaster<br>University of Ottawa</strong>";
  quote[6] = "\"I use TextPipe on a daily basis, for any number of things from conversion of URLs (during the relocation of sites for example) to specialty art projects. Often I use your product to move a site from a test position on the web, where my client can easily view it secretly, to a more public location. I can safely say, however, that your product was indispensable in maintaining my portion of the Ohio University web sites, as well as my other clients, and will remain an indispensable tool on all my computers as long as I can imagine.\"<p><strong>Steven Rutledge<br>TabletPress.net</strong>";
  quote[7] = "\"As we process log files for many corporate sites and purposes, we trawl through GB's of many different kind of different logs. I used to make the tools I needed as I went along in order to normalize and streamline these. Now I use TextPipe as a very flexible tool, that gets the job done many times faster.\"<p><strong>Anders Olsen<br>MediaWise A/S</strong>";
  quote[8] = "\"What a stunning piece of software! I am using it for multiple url changes to multiple files and have not found anything else so comprehensive!\"<p><strong>Simon Cox<br>SimonCox.com</strong>";
  quote[9] = "\"Thanks for the painless purchase procedure. We hold large amounts (many megabytes) of ASCII data which has been dumped from tapes to CD-ROMS. Tape formatted data does not contain record markers and the copied files on CD's are not formatted into regular columns. Your program enables us to read the files with specified record lengths and save in a usable form. Thanks again.\"<p><strong>Garth Bird<br>Rio Tinto</strong>";
  quote[10]= "\"TextPipe is an elegant, comprehensive, well-thought-out program. Technical support is prompt and professional. TextPipe is an indispensable tool for anyone needing to modify text.\"<p><strong>Howard Fineman<br>cultureanimal.com</strong>";
  quote[11]= "\"I am working with an extremely large patient clinical database, approx. 3 Terabytes, in my research. I am extracting clinical records, which are basically ASCII text files, in order to look for certain trends or indicators doctors use to describe the treatments and outcomes for certain classes of cancers. I use TextPipe to make the records anonymous. I use it to strip out all the demographic information that might identify the patient, but keep all the info, age, sex, race, and etc., that describe the patient. Making anonymous medical patient databases is very difficult and your tool really makes it easy to process large numbers of records rather easily. Your tool fits the bill for me, and has save me a lot of time that I might have burned up writing a ton of Perl scripts to do what you tool does so well.\"<p><strong>Clifton Slater</strong>";
  quote[12]= "\"I really love TextPipe! It has saved me countless hours of massaging and converting UNIX-generated text files into structured text files for importation into NT-based Excel spreadsheets.\"<p><strong>Greg Hall<br>ESM Consulting</strong>";
  quote[13]= "\"TextPipe is shaping up even better than I had hoped. I've been using a myriad of PERL scripts to manipulate these things with varying degrees of success. Sometimes I'd forget to run one and then everything got kind of weird. This one tool now does about 90% of the manual steps that used to take me hours.\"<p><strong></strong>";
  quote[14]= "\"What a great tool. I use it all the time in my work; sometimes even to generate source code. It takes care of many tedious editing tasks. I wish more people could understand its potential, but it's so different from any other software that most have a hard time grasping it.\"<p><strong>David Johnson<br>President<br>LeapFrog Consulting</strong>";
  quote[15]= "\"When we first began our web site, we thought it would never exceed more than twenty or thirty pages. Well, after three years, and three different versions of FrontPage, we found ourselves administering a 1,000+ web site. Since our skills had grown, there were aspects of web pages that we needed to update. For example, we had a number of different non-standard page designs that we wanted to bring in-line with a standard page design. However, FrontPage's Search and Replace functions weren't up to the task. We were fortunate to discover TextPipe, and used the program to make multiple passes through our code. We were able to use TextPipe to clean our entire site.\"<p><strong>Kirk VandenBerghe<br>HeartCore Corporation</strong>";
  quote[16]= "\"In a recent speed trial, TextPipe made 17 million replacements in a 250,000 record, 75 MB file in 1:45 seconds. Other 'popular' text applications took 35 minutes and 72 minutes, and MS Word took over 3 hours.\"<p><strong>DataMystic Staff</strong>";
  quote[17]= "\"It's hard to introduce TextPipe because nobody's ever seen anything like " +
"it before. When I saw a spreadsheet for the first time back in the 80's " +
"(Lotus 1-2-3 on DOS), I thought, wow, that's different and extremely " +
"useful. It's a eureka moment when you realize there's a new way to " +
"handle problems you deal with frequently. I had the same kind of moment " +
"when I discovered TextPipe. It's a whole new kind of software. It's " +
"not word processing; it's text processing.<br><br> " +
"It's more like a workbench than a toolbox, because it provides not only " +
"the tools you need to work with text, but also a work area that helps " +
"you try different things to zero in on a solution as quickly and with as " +
"little effort as possible.<br><br> " +
"Before TextPipe, I would be doing something tedious, usually with " +
"program code or a database, and I would think \"this is a waste of time, " +
"but I'm too lazy to write a program to do this, or it would take longer " +
"to write the program than to do this tedious thing manually.\" Now I use " +
"TextPipe because it makes those tedious tasks easy to take care of, and " +
"I can make the most of my time.<br><br> " +
"TextPipe is for people who want to work smarter, not harder.\"<p><strong>David Johnson, Consultant</strong>";
  quote[18]= "\"Unbelievably, TextPipe manipulated 93 million lines of CSV data (held across different files) and lumped them into one big 11Gb " +
    "file in less than 20 minutes. Awesome!\"<p><strong>Dr James Garcia, Advanced Forensic Solutions</strong>";
  quote[19]= "\"5GB sort/undupe just finished accurately. 63 minutes. Wow!\"<p><strong>Steve Robbins</strong>";

  //calculate a random index
  currentQuote = Math.floor(Math.random() * quote.length);

  return (quote[currentQuote]);
}


function showTestimonial()
{
  return (
"<div class=\"sideblock\"> " +
"<h4>What People Are Saying About TextPipe</h4> " +
"<div class=\"quote\"><div> " +
getQuote() +
"</strong></div></div> " +
"<p style=\"text-align: right\"><a href=\"http://www.datamystic.com/textpipe/case_studies/testimonials.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() );
  else
    document.write(
'<p align="center"><br>' +
//'<a title="Click here for an evluation key" href="downloads/evalkey.php?product=TextPipe+Pro&source=DataMysticHomePage"><img src="images/btn_evaluation.gif" width="164" height="50" alt="Click here for an evaluation key"></a>'+
'<a href="buy/evalcd.html">'+
'<img border="0" src="images/cd.gif" width="32" height="32" align="left"> New! Buy an<br>Evaluation CD</a></p>'
      );
}


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 );

