// JavaScript Document

function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

function loginGuest(){
	var cStr = 'u=guestUser&p=guestPass';
	var sc = new SecureContext(cStr);
	sc.secure('Password');
	cQStr = sc.strText;
	cQStr = cQStr.replaceAll(' ', '~\~');

	window.location.href='its_encrypt.asp?' + cQStr;
}

function loginUser(){
	var cUser = document.getElementById('U').value;
	document.getElementById('U').value = '';
	cUser = cUser.trim();
	var cPw = document.getElementById('P').value;
	document.getElementById('P').value = '';
	cPw = cPw.trim();
	
	if (cUser == '' || cPw == ''){ alert('To log in, please enter username and password.'); return }
	
	var cStr = 'u='+cUser+'&p='+cPw;
	var sc = new SecureContext(cStr);
	sc.secure('Password');
	cQStr = sc.strText;
	cQStr = cQStr.replaceAll(' ', '~\~');

	window.location.href='its_encrypt.asp?' + cQStr;
}



function searchProduct(){
	var cSearch = document.getElementById('S').value;
	cSearch = cSearch.trim();
	if (cSearch == '' ){ alert('Please enter a search expression.'); return }
	window.location.href='../its_product_search.asp?exp=' + cSearch;
}


function searchProductCompat(){
	var cSearch = document.getElementById('S').value;
//	cSearch = cSearch.trim();
	if (cSearch == '' ){ alert('Please enter a search expression.'); return }
	if (wordCnt(cSearch) < 2){ alert('At least two terms are required, separated by space.\nMore (or more specific) are better.'); return }
	window.location.href='../its_product_compat_search.asp?exp=' + cSearch;
}


function wordCnt(str) {

var char_count = str.length;
var fullStr = str + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {word_count = 0;}
return word_count;
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.replaceAll = function(pcFrom, pcTo){
   var i = this.indexOf(pcFrom);
   var c = this;
   while (i > -1){
     c = c.replace(pcFrom, pcTo);
     i = c.indexOf(pcFrom);
   }
   return c;
}