<!--
//
// The primary source of client-side Javascript functions.
// 
// $Id: allFunction.js,v 1.15.6.5 2011/05/28 01:29:32 sayhong Exp $
//
// detect the version of browser
function detect(){
	
	var ns = (navigator.appName =="Netscape")? true:false;
	var ie = (navigator.appName == "Microsoft Internet Explorer")? true:false;
	if(ie){
		return true;
	}else if(ns){
		return false;
	}
}
function detectBrowser(){
	
	var ns = (navigator.appName =="Netscape")? true:false;
	var ie = (navigator.appName == "Microsoft Internet Explorer")? true:false;
	if(ie){
		
		if (navigator.appVersion.charAt(0) >= '4')
		{
			return "ie";
		}
	}else if(ns){
		if ((navigator.appVersion.charAt(0) >= '5') || 
        ((navigator.appVersion.charAt(0) == '4') && (navigator.appVersion.charAt(2) >= '1')) ||
        ((navigator.appVersion.charAt(0) == '4') && (navigator.appVersion.charAt(2) == '0') && (navigator.appVersion.charAt(3) >= '7')))
		{
			return "ns";
		}
	}

	return "";
}

function checkIt(string)
{   
	var userAgentOS = navigator.userAgent.toLowerCase();
	var place = userAgentOS.indexOf(string) + 1;
	return place;
}

function isWindowsOS() {
	return ((checkIt('windows nt 6.0')) || (checkIt('windows nt 5.1')) || (checkIt('windows nt 5.0')) || (checkIt('windows nt 4.0')) || (checkIt('win')));
}

function detectNetscape6() {
	// helper function to differentiate between Netscape 6 (Mozilla) and previous versions, since Mozilla
	// is entirely different
	if (!detect() && navigator.appVersion.charAt(0) == '5') {
		return true;
	}
	return false;
}

function loadApplet(){
	if(detect()){
	}else{
		document.write("<applet name='allApplet' codebase='http://download.infotriever.com/bin/' archive='allApplet.jar' code='allApplet.class' width=1 height=1></applet>");
	}
}
var dir;
<!-- get the sysdrive and following dir -->
function getDir(){ 
	dir = (document.allApplet.getDrive()).toString() +"/Program Files/Inforbit/InfoClient/";
}

//download or not judging by MIME type 
function check(str){
 	var flg = 0;
 	var agree = false;
 	for (i=0; i < navigator.mimeTypes.length; i++) {   
 		<!-- this mimeType exists -->
		if(navigator.mimeTypes[i].type == str){
			flg = 1;
		}
	}
	
	if(flg != 1){
		return false;
	}else{	
		return true;
	}
}	

function run(flg){

	if(flg){
		document.allApplet.runit(dir.toString()+"infoclient.exe");		
	}else{	
		var exe = "http://download.infotriever.com/bin/infoclientinstaller.exe";
		document.allApplet.download(exe.toString(), "infoclientinstaller.exe");
		document.allApplet.runit((document.allApplet.getDrive()).toString() + "/infoclientinstaller.exe");

	}
}	
	
// save str to file name
function save(str, name){
	document.allApplet.save(dir.toString(), name.toString(), str.toString());
}

//parse the content, save Object info to a file
function parseFormObjectArray(formObjectArray){

    if(formObjectArray==null){
       	return;
    }
	var str = "";

	// for loop through each of the form objects in the form object array.
    for(var i = 0; i<formObjectArray.length; i++){

       	if(typeof(formObjectArray[i])=="object" && formObjectArray[i]!=null){

		   	var formObject = formObjectArray[i];
	
	            	//for loop through the properties of each individual form object.
	       	for(var j = 0; j < formObject.length; j++){
	
	    	   	if(formObject[j]!=null){
	           		str +=  new String(formObject[j]) ;
	           		str += "\r\n";
	           	}
	        }//for
        }
    }//for
    str = str + "<INPUT TYPE=HIDDEN NAME=IFB_PARTNER_URL VALUE=" + (window.opener.location).toString() + ">";
	save(str, "partner.html");
}

//add 00/06/27
// parse the content, save Object info to a str
function getParseFormObjectArray(formObjectArray){

    if(formObjectArray==null){
       	return;
    }
	var str = "";

	// for loop through each of the form objects in the form object array.
    for(var i = 0; i<formObjectArray.length; i++){

       	if(typeof(formObjectArray[i])=="object" && formObjectArray[i]!=null){

		   	var formObject = formObjectArray[i];
	
	            	//for loop through the properties of each individual form object.
	       	for(var j = 0; j < formObject.length; j++){
	
	    	   	if(formObject[j]!=null){
	           		str +=  new String(formObject[j]) ;
	           		str += "\r\n";
	           	}
	        }//for
        }
    }//for
    str = str + "<INPUT TYPE=HIDDEN NAME=IFB_PARTNER_URL VALUE=" + (window.opener.location).toString() + ">";
	return str;
}

// add 08/03
//   this function fit for ie and ns 
function getCurrentFormObjectArray(formObject){
    if(formObject==null){
       	return;
    }
	var str = "";
    	       	for(var j = 0; j < formObject.length; j++){
	    	   	if(formObject[j]!=null){
					str += new String;
					str += "<INPUT TYPE=\"" +  formObject[j].type + "\" ";
					str += "NAME=\"" + formObject[j].name + "\" ";
					str += "VALUE=\"" + formObject[j].value + "\">";
	           		str += "\r\n";
	           	}
        }
	return str;
}

// refreshNSPlugins()
//		This funciton will refresh the plugin list in netscape 4
function refreshNSPlugins() {
	if (!detect()) {
	    //navigator.plugins.refresh(true);
	}
}

//This function check if it is IE4
function isIE4() {
    var runningIE4=0;
	var ua = window.navigator.userAgent
	var msie = ua.indexOf ( "MSIE " )
	if ( msie > 0 )		// is Internet Explorer; return version number
	 	runningIE4= parseInt ( ua.substring ( msie+5, ua.indexOf ( ".", msie ) ) )
	else
		runningIE4= 0	// is other browser
     return (runningIE4==4); // return true if version is 4
}

// Request for the client to do an update
function requestupdate()
{
    if(detect())
    {
        Inforbit.RequestUpdate();
    }
    else
    {
        window.open('http://my.infotriever.com/download/nsrequpdate.html?','addsigWin','width=10,height=10,left=3000,top=0,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=0,copyhistory=0');
    }
}

function loadClickJS()
{
    // alert("loadClick - begining");
    if (isWindowsOS()) {
		if(detectBrowser() == "ie") {
			var browserVersion = navigator.appVersion;
			var versionIndex = browserVersion.indexOf("MSIE 4");
			var aolIndex = browserVersion.indexOf("AOL");
	
			if ((versionIndex <= 0) && (aolIndex <= 0)) {
				version=0
				if (navigator.appVersion.indexOf("MSIE")!=-1) {
					temp=navigator.appVersion.split("MSIE")
					version=parseFloat(temp[1])
				
				}
				if (version >= 6) 
					document.write("<SCRIPT SRC='/javascript/ie6click.js'><\/SCRIPT>");
				else 
					document.write("<SCRIPT SRC='/javascript/ieclick.js'><\/SCRIPT>");
	        } else {
				// alert("loadClick - ie4");
	            document.write("<SCRIPT SRC='/javascript/ie4click.js'><\/SCRIPT>");
	        }
	    } else if (detectBrowser() == "ns") {
			// alert("loadClick - ns");
	        document.write("<SCRIPT SRC='/javascript/nsclick.js'><\/SCRIPT>"); 
	    } else {
			// alert("loadClick - failclick");
	        document.write("<SCRIPT SRC='/javascript/failclick.js'><\/SCRIPT>"); 
	    }
    } else {
	    document.write("<SCRIPT SRC='/javascript/unsupportOSclick.js'><\/SCRIPT>"); 
    }
}

loadClickJS();

function autoSubmit()
{
  onClick();
}

function onClickWebPost()
{
	if(detect()){
    	window.document.forms[0].link.value = document.body.outerHTML;
    }else{
    	window.document.forms[0].elements[1].value = getParseFormObjectArray(document.forms).toString();
	}
    setTimeout ("document.forms[0].submit ();", 2000);
}

function onClickForward()
{
	//window.document.forms[1].html.value = getCurrentFormObjectArray( document.forms[0] ).toString();
	//window.document.forms[1].link.value = document.URL;
	window.document.forms[1].action=window.document.forms[1].action + "&html="+ getCurrentFormObjectArray( document.forms[0] ).toString()  + "&link="+document.URL;	
	setTimeout( "document.forms[1].submit();", 2000 );
}

function onClickWebPIM()
{
	//window.document.forms[2].html.value = getCurrentFormObjectArray( document.forms[0] ).toString();
	//window.document.forms[2].link.value = document.URL;
	window.document.forms[2].action=window.document.forms[2].action + "&html="+ getCurrentFormObjectArray( document.forms[0] ).toString()  + "&link="+document.URL;		
	setTimeout( "document.forms[2].submit();", 2000 );
}

function wrapText( theText, lineLength )
{

	// Make sure we're working with a number
	lineLength = parseInt( lineLength, 10);
	textLength = parseInt( theText.length, 10);
	// Only wrap if we need to
	if( textLength > lineLength )
	{
		var charNum = 0;
		var iterate = textLength / lineLength;
		for( counter = 0; counter <= iterate; counter++ )
		{
			document.write( theText.substr( charNum, lineLength ) + "<BR>" );
			charNum += lineLength;
		}
	}
	else
	{
		document.write(theText);
	}
}

function onLoadCloseActiveX()
{
  self.focus();

  var browserVersion = navigator.appVersion;
  var versionIndex = browserVersion.indexOf("MSIE 4");
  var aolIndex = browserVersion.indexOf("AOL");
  if (!(navigator.appName =="Netscape")) {
	  if ((versionIndex <= 0) && (aolIndex <= 0)) {
    		var activexWindow = open( '', 'activexpopWin','left=3000,top=3000');
	   	 	activexWindow.close();
  		}
   }
}

function onLoadResizeCloseActiveX(width, height) {
	self.focus();
	window.resizeTo(width, height);
	onLoadCloseActiveX();
}

function changeHelp(target) {
	document.help.src = "/images/linkpages/help_" + target + ".gif"
}


function hasCookies(aDocument) {
	if (aDocument == null) return false;
	var _hasCookies =  ((aDocument.cookie != null) && (aDocument.cookie != ""));
	return _hasCookies;
}

function hasCookie(aDocument,name) {
	if (!hasCookies(aDocument)) return false;
	var start = 0;
	var end = 0;
	var CookieString = aDocument.cookie;
	var i =0;
	while (i <= CookieString.length) {
		start = i;
		end = start + name.length + 1;
		if (CookieString.substring(start,end) == (name + "=")) {
			return true;
		}
		i++;
	}
	return false;
}

function getCookie(aDocument,name) {
	if (!hasCookies(aDocument)) return "";
	var cookieFound = 0;
	var start = 0;
	var end = 0;
	var CookieString = aDocument.cookie;

	var i =0;
	while (i <= CookieString.length) {
		start = i;
		end = start + name.length + 1;
		if (CookieString.substring(start,end) == (name + "=")) {
			cookieFound = true;
			end = end - 1;
			break;
		}
		i++;
	}
	if (cookieFound) {
		start = end + 1;
		end = aDocument.cookie.indexOf(";",start);
		if (end < start) end = aDocument.cookie.length;
		return aDocument.cookie.substring(start,end);
	}
	return "";
}

function getSchemeFromURL(aURL) {
	if (aURL == null) {
		return null;
	}
	var scheme = (aURL.indexOf("https") >= 0) ? "https" : "http";
	return scheme;
}
 
function getParameter ( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
} 

function maxWindow()
{
	window.moveTo(0,0);
	if (document.all) {
  	top.window.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
  	if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
    	top.window.outerHeight = screen.availHeight;
    	top.window.outerWidth = screen.availWidth;
  	}
	}
}


function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}
function isNotInfotrieverPluginInstalled() {
	if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
		return (navigator.mimeTypes["application/x-inforbit-infotriever-plugin"] == null);
	} else {
		return (navigator.mimeTypes["application/x-Inforbit-Infotriever-Plugin"] == null);
	}
}


//-->


