////////////////////////////////////////
var kaizenwebsite = "http://www.protekks.com/kaizentrack";
////////////////////////////////////////
function goHelp(aid,aa) {
	if(aid==null || aid.length==0) {
		return;
	}
	window.location="help.php?action_id="+aid+"&taguchi_test_id="+aa;
}

function goReminder(obj,sid) {
		reminder_text = '';
		text = null;
		switch(sid) {
			case 'campaign_1':	
				text = "This is the name of your campaign. It is recommended that you name your campaign to best describe the response you want to track. If this is the \'thank you\' page you may name it \'sales\'. If this is the \'order page\' you may name it \'order\'.";
				break;
			case 'campaign_2':
				text = "This is the website URL where your visitors will be sent after clicking the tracking link.";
				break;
			case 'campaign_3':
				text = "This box is optional. If you want, you can enter personal description of this campaign for your own records. It will appear when you edit your campaign.";
				break;
			case 'campaign_4':
				text = "Check this box to disable url-tracking for this page (to protect your sale page, i.e.).";
				break;
			case 'splittest_1':
				text = "This is the name of your split-test. It is recommended that you name your split-test to best describe the response you want to track. If this split-test compares different versions of a \'thank you\' page you may name it \'thankyou\'";
				break;
			case 'splittest_2':
				text = "This box is optional. If you want, you can enter personal description of this standard split-test for your own records. It will appear when you edit your split-test";
				break;
			case 'splittest_3':
				text = "Please select at least two campaigns in order to conduct a split-test that compares their efficiency";
				break;
			case 'taguchi_1':
				text = "Browse on your hard disk and select the html page that you want to use for the Taguchi test.";
				break;
			case 'taguchi_2':
				text = "It is recommended that you name your PHP split-test to best describe the response you want to track. If this is the “thank you” page you may name it “sales”. If this is the “order page” you may name it “order”.";
				break;
			case 'taguchi_3':
				text = "This is the website URL where your visitors will be sent after clicking the tracking link.";
				break;
			case 'taguchi_4':
				text = "Please select first your variable html code that you want to test from the box below. Or if you haven’t imported the html code yet, you can do that by clicking by going to the “Import the website for this split-test” zone.";
				break;
			case 'taguchi_5':
				text = "First download the file on your hard drive, after that upload it on your server.";
				break;
		}
		if(text!=null)
			alert(text);
}

function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  params='left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str;
  window.open(url, name, params);
}

function ac(object,color){object.style.backgroundColor=color}
function go(page){window.location=page}
function su(){return confirm('Are you sure you want to delete this item?')}
function si(){return confirm('Are you sure you want to delete this image?')}
function sm(msg){return confirm(msg)}
function s(){window.status=document.title;return true};
if(document.layers)document.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
document.onload=s;
document.onmouseover=s;
document.onmouseout=s;
document.onclick=s;


function trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
}
function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
} 
function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} 
	return strTemp;
} 

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

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
  */
  k = s.indexOf(t);
  r = "";
  if (k == -1) return s;
  r += s.substring(0,k) + u;
  if ( k + t.length < s.length)
    r += replace(s.substring(k + t.length, s.length), t, u);
  return r;
  }
 
function URLEncode(plaintext)
{
	var SAFECHARS = "0123456789" +			
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	
					"abcdefghijklmnopqrstuvwxyz";					
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";			
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
};

function URLDecode(encoded)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var i = 0;
   var plaintext = "";
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} 
   return plaintext;
}; 

function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}


function AddToOptionList(OptionList, OptionValue, OptionText) {
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function strpos(str, ch) {
	for (var i = 0; i < str.length; i++)
		if (str.substring(i, i+1) == ch) return i;
	return -1;
}

function trackCampaign(cid) {
	var oimg = document.createElement("img");
	document.write("<img width='1' height='1' src='"+kaizenwebsite+"/track.php?campaign_id="+cid+"&referer=");
	if(document.referrer !=undefined) {
		document.write(URLEncode(document.referrer));
	}		
	document.write("'/>");				   
}

