function goTo(obj) {
	location.href = obj.value();	
}

function ToLink(str) {
	var fs = str;
	fs = fs.replace("/", "_slsig_") 
	fs = fs.replace("&","_ampsig_")
	fs = fs.replace("™","_tm_")
	fs = fs.replace(" ", "_" ) 
	return fs;
}

function EL(id) {
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
	else if (document.layers)
		return document.layers[id];
}

var currentTab = 1;
function showTab(id) {
	EL('div_tab' + currentTab).className = 'hideGrp';
	EL('id_tab' + currentTab).className = '';
	EL('div_tab' + id).className = 'showGrp';
	EL('id_tab' + id).className = 'on';
	currentTab = id;
}

function goToCrPage() {
	if (EL('country_hidden').value.length > 0) {
		location.href = EL('country_hidden').value;
	}
	else {
		alert('Please type in keywords');
	}
}


function checkTypeBrand(obj) {
	if (obj.value == 'Type Brand') {
		obj.value = '';
	}
}

function productImg(str, num) {
	for (var i = 0; i <=num; i++) {
		if (i == str) {
			EL('div_image_' + i).className = 'showGrp';
			EL('id_product_tm_' + i).className = 'img_tm_1';
		}
		else {
			EL('div_image_' + i).className = 'hideGrp';
			EL('id_product_tm_' + i).className = 'img_tm';
		}		
	}
}




function capacitytypes(t, url) {
	var ret = getPageData('/func/bst_capacitytypes.aspx', 'c_t=' + encodeURI(t) );
	var arr_ret = ret.split(',');
	EL('id_chem_x').length = 0;
	EL('id_chem_n').length = 0;
	EL('id_chem_n').options[0] = new Option('--min--', url);
	EL('id_chem_x').options[0] = new Option('--max--', url);

	for (var i = 0; i < arr_ret.length; i++) {
		EL('id_chem_n').options[i+1] = new Option(arr_ret[i], url + '?cn=' + arr_ret[i]);
		EL('id_chem_x').options[i+1] = new Option(arr_ret[i], url + '?cx=' + arr_ret[i]);
	}
}



function DD(str, c, b, m, s) {
	if (c == undefined)
		c = '';
	if (b == undefined)
		b = '';
	if (m == undefined)
		m = '';
	if (s == undefined)
		s = '';	
	// dd indexes and values //
	var catIndex = document.configurator.C.selectedIndex;
	var catName = document.configurator.C.value;
	var brandIndex = document.configurator.B.selectedIndex;
	var brandName = document.configurator.B.value;
	var modelIndex = document.configurator.M.selectedIndex;
	var modelName = document.configurator.M.value;
	var oemIndex = document.configurator.O.selectedIndex;
	var oemName = document.configurator.O.value;
	var kw = document.configurator_search.kw.value;

	var crData;
	var oemData;
	var modelData;
	var xmlHttp;
  try {    // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
  catch (e) {    // Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
      catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
  xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==3 && str == 'K') {
			EL('div_cr').innerHTML = '<table><tr><td class="sm">SEARCHING</td><td><img src="/pics/progress_indicator.gif" width="16" height="16" /></td></tr></table>';
			document.configurator_search.kw.disabled = true;
			document.configurator_search.btnSearch.disabled = true;
		}
		else if (xmlHttp.readyState==3 && (str == 'M' || str == 'L')) {
			EL('div_cr').innerHTML = '<table><tr><td class="sm">LOADING</td><td><img src="/pics/progress_indicator.gif" width="16" height="16" /></td></tr></table>';
		}
  	else if (xmlHttp.readyState==4) {
			//alert(str);
			if (str == 'C') {
				crData = xmlHttp.responseText.split("//");
				if (catIndex > 0) {
					EL('div_brand_0').className = 'hideGrp';
					EL('div_brand').className = 'hiliteGrp';
					EL('div_cat').className = 'showGrp';
					EL('B').focus();
				}
				else {
					EL('div_brand_0').className = 'showGrp';
					EL('div_brand').className = 'hideGrp';
					EL('div_cat').className = 'hiliteGrp';
				}
				EL('div_model_0').className = 'showGrp';
				EL('div_model').className = 'hideGrp';
				EL('div_oem_0').className = 'showGrp';
				EL('div_oem').className = 'hideGrp';
				document.configurator.M.length = 0;
				document.configurator.M.options[0] = new Option('[ Select Model ... ]');
				document.configurator.B.length = 0;
				document.configurator.B.options[0] = new Option('[ Select Brand ... ]');
				for (var i = 0; i < crData.length; i++) {
					document.configurator.B.options[i+1] = new Option(crData[i],crData[i]);
				}
	    }
			else if (str == 'B') {
				crData = xmlHttp.responseText.split("///");
				modelData = crData[0].split("//");
				if (brandIndex > 0) {
					EL('div_model_0').className = 'hideGrp';
					EL('div_model').className = 'hiliteGrp';
					//EL('div_oem_0').className = 'hideGrp';
					//EL('div_oem').className = 'hiliteGrp';
					EL('div_brand').className = 'showGrp';
					EL('M').focus();
				}
				else {
					EL('div_model_0').className = 'showGrp';
					EL('div_model').className = 'hideGrp';
					EL('div_oem_0').className = 'showGrp';
					EL('div_oem').className = 'hideGrp';
				}
				document.configurator.M.length = 0;
				document.configurator.M.options[0] = new Option('[ Select Model ... ]');
				for (var i = 0; i < modelData.length; i++) {
					document.configurator.M.options[i+1] = new Option(modelData[i],modelData[i]);
		    }
				if (crData.length == 2) {			
					if (brandIndex > 0) {
						EL('div_oem_0').className = 'hideGrp';
						EL('div_oem').className = 'hiliteGrp';
					}
					oemData = crData[1].split("//");
					document.configurator.O.length = 0;
					document.configurator.O.options[0] = new Option('[ Select Partnumber ... ]');
					for (var i = 0; i < oemData.length; i++) {
						document.configurator.O.options[i+1] = new Option(oemData[i],oemData[i]);
		    	}
				}
				else {
					EL('div_oem_0').className = 'showGrp';
					EL('div_oem').className = 'hideGrp';
				}
			}
			else if (str == 'M' || str == 'O' || str == 'K' || str == 'L') {
				crData = xmlHttp.responseText;
				location.href=crData;
				if (str == 'M') {
					if (modelIndex > 0) {
						EL('div_cr').innerHTML = crData;
					}
					else {
						EL('div_cr').innerHTML = '';
					}
					document.configurator.O.selectedIndex = 0;
				}
				else if (str == 'O') {
					if (oemIndex > 0) {
						EL('div_cr').innerHTML = crData;
					}
					else {
						EL('div_cr').innerHTML = '';
					}
					document.configurator.M.selectedIndex = 0;
				}
				else if (str == 'K') {
					EL('div_cr').innerHTML = crData;
				}
				else if (str == 'L') {
					EL('div_cr').innerHTML = crData;
				}
				document.configurator_search.kw.disabled = false;
				document.configurator_search.btnSearch.disabled = false;
			}
    }
  }
	// clear keyword
	if (str != 'K') {
		document.configurator_search.kw.value = '';
	}
	
	if (str == 'C') {
	  xmlHttp.open("GET","/crossreference.aspx?c=" + ToLink(catName),true);
	}
  else if (str == 'B') {
		xmlHttp.open("GET","/crossreference.aspx?c=" + ToLink(catName) + "&b=" + ToLink(brandName),true);
	}
  else if (str == 'M') {
		xmlHttp.open("GET","/crossreference.aspx?c=" + ToLink(catName) + "&b=" + ToLink(brandName) + "&m=" + ToLink(modelName),true);
	}
  else if (str == 'O') {
		xmlHttp.open("GET","/crossreference.aspx?c=" + ToLink(catName) + "&b=" + ToLink(brandName) + "&m=" + ToLink(oemName),true);
	}
  else if (str == 'K') {
		xmlHttp.open("GET","/crossreference.aspx?kw=" + kw,true);
	}
  else if (str == 'L') {
		xmlHttp.open("GET","/crossreference.aspx?c=" + ToLink(c) + "&b=" + ToLink(b) + "&m=" + ToLink(m) + "&s=" + ToLink(s),true);
	}
 	xmlHttp.send(null);
}


function cart_AddItem(id, qty) {
	if (id == undefined) {
		id = '0';
	}
	if (qty == undefined) {
		qty = '1';
	}
	
  try {    // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
  catch (e) {    // Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
      catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	var xmlData;
  xmlHttp.onreadystatechange=function() {
  	if (xmlHttp.readyState==4) {
			xmlData = xmlHttp.responseText.split("///");
			if (xmlData.length == 2) {
				if (xmlData[0] = 'add') { //success
					EL('div_cart').innerHTML = xmlData[1];
					EL('div_addnoteshd').className = "showAddNoteShd";
					EL('div_addnote').className = "showAddNote";
				}
				else if (xmlData[0] = 'remove') { //success
					EL('div_cart').innerHTML = xmlData[1];
					EL('div_addnoteshd').className = "hideAddNote";
					EL('div_addnote').className = "hideAddNote";
				}
			}
		}
	}
  xmlHttp.open("GET","/cart_AddItem.aspx?ItemID=" + id + "&Qty=" + qty,true);
 	xmlHttp.send(null);
}

function closeCartNote() {
	EL('div_addnoteshd').className = "hideAddNote";
	EL('div_addnote').className = "hideAddNote";
}

function kw_focus() {
	var f_obj = EL('id_kw_search');
	f_obj.focus();
	f_obj.select();
}

function clear_kw() {
	var f_obj = EL('id_kw_search');
	if (f_obj.value == 'Enter Search Keyword') {
		f_obj.value = '';
	}
}


function cr_model(str) {
	if (str == 0) {
	document.getElementById('div_cr_model_1').className = 'showGrp';
	document.getElementById('div_cr_model_2').className = 'showGrp';
	document.getElementById('div_cr_oem_1').className = 'hideGrp';
	document.getElementById('div_cr_oem_2').className = 'hideGrp';
	}
	else {
	document.getElementById('div_cr_model_1').className = 'hideGrp';
	document.getElementById('div_cr_model_2').className = 'hideGrp';
	document.getElementById('div_cr_oem_1').className = 'showGrp';
	document.getElementById('div_cr_oem_2').className = 'showGrp';	
	}
}

function allowBuy() {
	document.getElementById('div_cr').className = 'hideGrp';
	document.getElementById('div_buy').className = 'showGrp';
}

function loadBrands() {
	var ind = document.configurator.CatName.selectedIndex;	
	if (ind > 0) {
		document.getElementById('div_brand_0').className = 'hideGrp';
		document.getElementById('div_brand').className = 'showGrp';
		document.getElementById('B').focus();
	}
	else {
		document.getElementById('div_brand_0').className = 'showGrp';
		document.getElementById('div_brand').className = 'hideGrp';
	}
	document.getElementById('div_model_0').className = 'showGrp';
	document.getElementById('div_model').className = 'hideGrp';
	document.configurator.M.length = 0;
	document.configurator.M.options[0] = new Option('select model ...');
	document.configurator.B.length = 0;
	document.configurator.B.options[0] = new Option('select brand ...');
	if (ind == 1) {
		for (var i = 0; i < camcorder_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(camcorder_brands[i]);
		}
	}
	else if (ind == 2) {
		for (var i = 0; i < cellular_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(cellular_brands[i]);
		}	
	}
	else if (ind == 3) {
		for (var i = 0; i < cordless_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(cordless_brands[i]);
		}	
	}
	else if (ind == 4) {
		for (var i = 0; i < digitalcamera_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(digitalcamera_brands[i]);
		}	
	}
	else if (ind == 5) {
		for (var i = 0; i < laptop_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(laptop_brands[i]);
		}	
	}
	else if (ind == 6) {
		for (var i = 0; i < pda_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(pda_brands[i]);
		}	
	}
	else if (ind == 7) {
		for (var i = 0; i < ups_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(ups_brands[i]);
		}	
	}
	else if (ind == 8) {
		for (var i = 0; i < powertools_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(powertools_brands[i]);
		}	
	}
	else if (ind == 9) {
		for (var i = 0; i < scanner_brands.length; i++) {
			document.configurator.B.options[i+1] = new Option(scanner_brands[i]);
		}	
	}	
}

function loadModels() {
	var cat = document.configurator.CatName.selectedIndex;
	var ind = document.configurator.B.selectedIndex;
	if (ind > 0) {
		document.getElementById('div_model_0').className = 'hideGrp';
		document.getElementById('div_model').className = 'showGrp';
		document.getElementById('M').focus();
	}
	else {
		document.getElementById('div_model_0').className = 'showGrp';
		document.getElementById('div_model').className = 'hideGrp';
	}
	ind = ind - 1
	if (ind >= 0) {
		document.configurator.M.length = 0;
		document.configurator.M.options[0] = new Option('select model ...');
		if (cat == 1) {
			for (var i = 0; i < camcorder_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(camcorder_models[ind][i]);
			}
		}
		else if (cat == 2) {
			for (var i = 0; i < cellular_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(cellular_models[ind][i]);
			}	
		}
		else if (cat == 3) {
			for (var i = 0; i < cordless_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(cordless_models[ind][i]);
			}	
		}
		else if (cat == 4) {
			for (var i = 0; i < digitalcamera_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(digitalcamera_models[ind][i]);
			}	
		}
		else if (cat == 5) {
			for (var i = 0; i < laptop_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(laptop_models[ind][i]);
			}	
		}
		else if (cat == 6) {
			for (var i = 0; i < pda_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(pda_models[ind][i]);
			}	
		}
		else if (cat == 7) {
			for (var i = 0; i < ups_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(ups_models[ind][i]);
			}	
		}
		else if (cat == 8) {
			for (var i = 0; i < powertools_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(powertools_models[ind][i]);
			}	
		}
		else if (cat == 9) {
			for (var i = 0; i < scanner_models[ind].length; i++) {
				document.configurator.M.options[i+1] = new Option(scanner_models[ind][i]);
			}	
		}
	}
}	

function goTo(pagename) {
	if (pagename.options[pagename.selectedIndex].value != 'null') {
		location.href=pagename.options[pagename.selectedIndex].value;
	}
	else {
		alert('Please make a selection ...');
	}
	return true;
}

function exactMatch(obj) {
	obj.findMatch.value = '1';
	//alert(obj.findMatch.value);
	obj.submit();
	//return true;
}

function SendPass() { //v2.0
  window.open('/sendpass.asp','sendpass','width=400,height=200,scrollbar=no,menubar=no');
}

function product_image(url, h) { //v2.0
  window.open('/product_image.asp?ItemID=' + url,'product_image','width=400,height=' + h + ',scrollbar=yes,menubar=no');
}

var cStatus = window.status;
function hilite1(obj,url) {
	obj.className = 'le_over';
	window.status = url;
}
function hilite2(obj) {
	obj.className = 'le';
	window.status = cStatus;
}	

function warnAction(q,p) { //df
	if (confirm(q)) {
		location.href = p;
	}
}

function checkRMA(str) {
	if (document.getElementById('cb_Sku_' + str).checked)
		document.getElementById('div_Sku_' + str).className = 'showGrp';
	else
		document.getElementById('div_Sku_' + str).className = 'hideGrp';
}

function showModelMsg(obj, str) {
	if (obj.selectedIndex > 0) {
		document.getElementById('div_ModelMsg_' + str).className = 'showGrp';
	}
	else {
		document.getElementById('div_ModelMsg_' + str).className = 'hideGrp';
	}
}

function clearTxt(obj) {
  var f = document.getElementById(obj)
  var v = f.value;
  if (v == 'Enter Keyword') { //(v.substring(0,1) == 'Enter Keyword') {
    f.value = '';
  }
}

function menu(str) {
	if (str == 0) {
		document.getElementById('div_menu_0').className = 'showGrp';
		document.getElementById('div_menu_1').className = 'hideGrp';
		document.getElementById('div_menu_2').className = 'hideGrp';
		document.getElementById('div_nav_0').className = 'showGrp';
		document.getElementById('div_nav_1').className = 'hideGrp';
		document.getElementById('div_nav_2').className = 'hideGrp';
	}
	else if (str == 1) {
		document.getElementById('div_menu_0').className = 'hideGrp';
		document.getElementById('div_menu_1').className = 'showGrp';
		document.getElementById('div_menu_2').className = 'hideGrp';
		document.getElementById('div_nav_0').className = 'hideGrp';
		document.getElementById('div_nav_1').className = 'showGrp';
		document.getElementById('div_nav_2').className = 'hideGrp';
	}
	else if (str == 2) {
		document.getElementById('div_menu_0').className = 'hideGrp';
		document.getElementById('div_menu_1').className = 'hideGrp';
		document.getElementById('div_menu_2').className = 'showGrp';
		document.getElementById('div_nav_0').className = 'hideGrp';
		document.getElementById('div_nav_1').className = 'hideGrp';
		document.getElementById('div_nav_2').className = 'showGrp';
	}
}

function acc_view(str) {
	if (str == 0) {
	document.getElementById('div_acc_0').className = 'showGrp';
	document.getElementById('div_acc_1').className = 'hideGrp';
	document.getElementById('div_acc_2').className = 'hideGrp';
	document.getElementById('div_acc_tbl_0').className = 'showGrp';
	document.getElementById('div_acc_tbl_1').className = 'hideGrp';
	document.getElementById('div_acc_tbl_2').className = 'hideGrp';
	}
	else if (str == 1) {
	document.getElementById('div_acc_0').className = 'hideGrp';
	document.getElementById('div_acc_1').className = 'showGrp';
	document.getElementById('div_acc_2').className = 'hideGrp';
	document.getElementById('div_acc_tbl_0').className = 'hideGrp';
	document.getElementById('div_acc_tbl_1').className = 'showGrp';
	document.getElementById('div_acc_tbl_2').className = 'hideGrp';
	}
	else if (str == 2) {
	document.getElementById('div_acc_0').className = 'hideGrp';
	document.getElementById('div_acc_1').className = 'hideGrp';
	document.getElementById('div_acc_2').className = 'showGrp';
	document.getElementById('div_acc_tbl_0').className = 'hideGrp';
	document.getElementById('div_acc_tbl_1').className = 'hideGrp';
	document.getElementById('div_acc_tbl_2').className = 'showGrp';
	}
	else if (str == 3) {
	document.getElementById('div_acc_0').className = 'hideGrp';
	document.getElementById('div_acc_1').className = 'hideGrp';
	document.getElementById('div_acc_2').className = 'hideGrp';
	document.getElementById('div_acc_3').className = 'showGrp';
	document.getElementById('div_acc_tbl_0').className = 'hideGrp';
	document.getElementById('div_acc_tbl_1').className = 'hideGrp';
	document.getElementById('div_acc_tbl_2').className = 'hideGrp';
	document.getElementById('div_acc_tbl_3').className = 'showGrp';
	}
}


var http_request = false;
var responseData = '';

/*post functions */

function makePOSTRequest(url, parameters) {
		  http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

  http_request.onreadystatechange=function() {
  	if (http_request.readyState==4) {
			responseData = http_request.responseText;
			EL("div_newcomment").innerHTML = responseData;
		}
	}
      
      //http_request.onreadystatechange = alertContents();
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
	 		if (http_request.readyState) {
				if (http_request.readyState == 4) {
            //responseData = http_request.responseText;
            //EL("id_contact").innerHTML = responseData;
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            responseData = http_request.responseText;
            EL(div_id).innerHTML = responseData;
         }
				 else {
            alert('There was a problem with the request.');
         }
  		}
			else {
				alert("Error!");
			}
		}
  }
   
function saveComments() {
	var poststr = "ItemID=" + encodeURI(EL("id_ItemID").value ) +										
		"&Rating=" + encodeURI(EL("id_Rating").value ) +
		"&Name=" + encodeURI(EL("id_Name").value ) +
		"&Email=" + encodeURI(EL("id_Email").value ) +
		"&Comments=" + encodeURI(EL("id_Comments").value );
	makePOSTRequest("/func/savereview.aspx", poststr);
}
   
function saveVideoComments() {
	var poststr = "VideoID=" + encodeURI(EL("id_VideoID").value ) +										
		"&Rating=" + encodeURI(EL("id_Rating").value ) +
		"&Name=" + encodeURI(EL("id_Name").value ) +
		"&Email=" + encodeURI(EL("id_Email").value ) +
		"&Comments=" + encodeURI(EL("id_Comments").value );
	makePOSTRequest("/func/savevideoreview.aspx", poststr);
}

function saveBlogComments() {
	var poststr = "BlogID=" + encodeURI(EL("id_BlogID").value ) +										
		"&Name=" + encodeURI(EL("id_Name").value ) +
		"&Email=" + encodeURI(EL("id_Email").value ) +
		"&Url=" + encodeURI(EL("id_Url").value ) +
		"&Comments=" + encodeURI(EL("id_Comments").value );
	makePOSTRequest("/func/saveblogcomments.aspx", poststr);
}

function updateWR(obj) {
	var word_count = CountWords(obj.value);	
	while (word_count > 1000) {
		obj.value = obj.value.substr(0, obj.value.length-2)
		word_count = CountWords(obj.value);
	}
	if ((1000 - word_count) != 1) {
		document.getElementById('div_wr').innerHTML = 1000 - word_count + ' characters left';
	}
	else {
		document.getElementById('div_wr').innerHTML = 1000 - word_count + ' character left';	
	}
}

function CountWords (obj) {
	return obj.length;
	var char_count = obj.length;
	var fullStr = obj + " ";
	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;
}

function fnPaste(vEl) {
	var intMaxLength, intCurrLength, strClip ;
  var intClipLength, intAvailLength ;
  var blnReturn = true ;
  intMaxLength = 1000; //vEl.getAttribute("maxlength") ;
  intCurrLength = CountWords(vEl.value);
  strClip = window.clipboardData.getData("Text") ;
  intClipLength = CountWords(strClip);
  intAvailLength = intMaxLength - intCurrLength;
	intTotalLength = intCurrLength + intClipLength;
	if ((intTotalLength) > intMaxLength) {
		if (confirm("You are trying to paste " + intClipLength + " words, which will bring the total # words to " + intTotalLength + "\nWould you like to truncate essay to fit this field?")) {
     	while (CountWords(strClip) > intAvailLength) {
				strClip = strClip.substr(0, strClip.length-2);
			}
    	window.clipboardData.setData("Text",strClip);
			document.getElementById('div_wr').innerHTML = '0 characters left';
		}
		else {
			blnReturn = false;
		}
  }
	else {
		document.getElementById('div_wr').innerHTML = intMaxLength - intTotalLength  + ' characters left';
	}
	return blnReturn ;
}


/***
	BEGIN: Helpers
***/

function resizeImage(h) {
	//if (document.getElementsByName) {
	//	alert(document.getElementsByName('id_image').style.height);
	//	document.getElementsByName('id_image').style.height = String(h) + 'px';
	//}
	//else
	if (document.all && !document.getElementById) {
		//document.all['ps_widget'].style.pixelWidth = x;
		document.all['id_image'].style.pixelHeight = h;	
		//alert('all: ' + h);		
	}
	else {
		//document.getElementById('ps_widget').style.width = x;
		document.getElementById('id_image').style.height = String(h) + 'px';
		//alert('el: ' + h + document.getElementById('id_image').offsetHeight);
	}

}

function getFlashObj(movie){
   if (window.document[movie]) {
      return window.document[movie];
   }
   if (navigator.appName.indexOf("Microsoft Internet")==-1) {
      if (document.embeds && document.embeds[movie]) {
         return document.embeds[movie]; 
      }
   } else {
      return document.getElementById(movie);
   }
}
function resizeImage2(h) {
   var movieObj = getFlashObj('id_image');
   var width = movieObj.TGetProperty("/", 8);
   var height= movieObj.TGetProperty("/", 9);
   //alert("The current dimensions for the Flash Object ("+h+") are "+width+" in width and "+height+" in height.");
	 movieObj.TSetProperty("/", 9, h);
}


/***
	BEGIN: XML post functions
***/
function getproducts( obj, c, b, m ) {
	//obj.href = '#';
	cr( 'div_products', c, b, m );
	//return false;
}
function getmodels( obj, c, b ) {
	obj.src = '/pics/checkbox_1.gif';
	cr_dd( c, b );
	//return false;
}
function getbrands( obj, c ) {
	//obj.href = '#';
	cr( 'div_brands', c );
	//return false;
}
function cr( div, c, b, m ) {
	if ( !c )
		c = '';
	if ( !b )
		b = '';
	if ( !m )
		m = '';
	var poststr = 'c=' + encodeURI( c ) +		
		'&b=' + encodeURI( b ) +
		'&m=' + encodeURI( m );
	getHtmlData(div, '/func/cr.aspx', poststr);

}
function cr_dd( c, b ) {
	var poststr = 'c=' + encodeURI( c ) +
		'&b=' + encodeURI( b );
	getHtmlData_DD('/func/cr_dd.aspx', poststr);	
}

/****
	BEGIN: XML handlers
***/

function createXmlHttpObj() {
	var http_request;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
  	http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    	http_request.overrideMimeType('text/html');
		}
	}
	else if (window.ActiveXObject) { // IE
  	try {
    	http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
		catch (e) {
 	   try {
  	  	http_request = new ActiveXObject("Microsoft.XMLHTTP");
    	}
			catch (e) {}
  	}
	}
  if (!http_request) {
  	alert('Cannot create XMLHTTP instance');
    return false;
  }
	else {
		return http_request;
	}
}

function getHtmlData( elemID, url, parameters, loading ) {
	//alert('ajax');
	if (!parameters) {
		type = 'GET';
		parameters = '';
	}
	else {
		type = 'POST';
	}
		
	if( !url )
		return false;
	
	var url = url + '?r=' + Math.random();
	
	
	var oXMLHttpReq = createXmlHttpObj();
	
	if( !oXMLHttpReq )
		return false;
	
	if ( elemID ) {
		var elem = EL( elemID );
		if ( loading ) {
			elem.innerHTML = '<table class=t_loading><tr><td><span style="padding:0px"><img src="/pics/icon_loading.gif" width="16" height="16" /></span><span style="line-height:16px">' + loading + '</span></td></tr></table>';
		}
		else if (elemID == 'div_products') {
			EL('div_loading').className = 'showLoading';
		}
		else if ( elemID == 'div_models' ) {
			elem.innerHTML = 'Loading Models ...';
		}
		//else
			
			//elem_loading.innerHTML = 'Loading Products ...';
	}
	
	oXMLHttpReq.onreadystatechange = function() {
		if ( oXMLHttpReq.readyState == 4 ) { //&& oXMLHttpReq.status == 200 ) {
			var responseText = oXMLHttpReq.responseText;
			if ( elemID.length > 0 ) {
				elem.innerHTML = responseText;
				if (elemID == 'div_products') {
					EL('div_loading').className = 'hideLoading';
				}
			}
		}
	}

	if (type == 'GET') {
		oXMLHttpReq.open( 'GET', url );
		oXMLHttpReq.send( null );
	}
	else {
		oXMLHttpReq.open( 'POST', url, true );
		oXMLHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		oXMLHttpReq.setRequestHeader("Content-length", parameters.length);
		oXMLHttpReq.setRequestHeader("Connection", "close");
		oXMLHttpReq.send(parameters);
	}

}

function getPageData( url, parameters ) {
	var ret = '';
	if( !url )
		return ret;
	
	url = url + '?r=' + Math.random();
	
	
	var oXMLHttpReq = createXmlHttpObj();
	
	if( !oXMLHttpReq )
		return ret;
	
	oXMLHttpReq.open( 'POST', url, false );
	oXMLHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	oXMLHttpReq.setRequestHeader("Content-length", parameters.length);
	oXMLHttpReq.setRequestHeader("Connection", "close");
	oXMLHttpReq.send(parameters);
	var sNewText = oXMLHttpReq.responseText;
	//elem.innerHTML = sNewText;
	if (sNewText.length > 2) {
		ret = sNewText;
	}
	return ret;
}


function getHtmlData_DD( url, parameters ) {
	
	if( !url )
		return false;
	
	var url = url + '?r=' + Math.random();
	
	
	var oXMLHttpReq = createXmlHttpObj();
	
	if( !oXMLHttpReq )
		return false;
	
	
	oXMLHttpReq.onreadystatechange = function() {
		if ( oXMLHttpReq.readyState == 4 ) { //&& oXMLHttpReq.status == 200 ) {
			var responseText = oXMLHttpReq.responseText;
			var arr_resp = responseText.split("//////////");
			for (var k = 0; k < arr_resp.length; k++) {
				var arr_dd = arr_resp[k].split("/////");
				if (arr_dd[0] == "{{{MODEL}}}") {
					EL('id_model').length = 0;
					EL('id_model').options[0] = new Option('--- select model ---');
					for (var i = 1; i < arr_dd.length; i++) {
						var arr_m =  arr_dd[i].split("///");
						EL('id_model').options[i] = new Option(arr_m[1], arr_m[0]);
					}			
				}
				else if (arr_dd[0] == "{{{OEM}}}") {
					EL('id_partnumber').length = 0;
					EL('id_partnumber').options[0] = new Option('--- select partnumber ---');
					for (var i = 1; i < arr_dd.length; i++) {
						var arr_m =  arr_dd[i].split("///");
						EL('id_partnumber').options[i] = new Option(arr_m[1], "/" + arr_m[0]);
					}	
					
				}
				else {
					EL('div_products').innerHTML = arr_resp[k];
				}
			}
		}
	}

	oXMLHttpReq.open( 'POST', url, true );
	oXMLHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	oXMLHttpReq.setRequestHeader("Content-length", parameters.length);
	oXMLHttpReq.setRequestHeader("Connection", "close");
	oXMLHttpReq.send(parameters);
}


function scrollDown(div, id) {
		var p = EL(id).offsetTop;
		var h = EL(div).style.height;
		h = String(h).substring(0,h.length - 2);
		//alert(div + ' ... ' + h);
		EL(div).scrollTop = p;// - 20; //(h / 2);
}


function includeJs(libraryName) {
	document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
}

includeJs("/js/accordion.js");
includeJs("/js/form.js");
includeJs("/js/checkout.js");
includeJs("/js/ac_runactivecontent.js");
includeJs("/js/menu.js");
includeJs("/js/ajax.js");
includeJs("/js/ajax-dynamic-list.js");
includeJs("/js/tooltip_n.js");
