﻿//signup stuff

function clickclear(thisfield, defaulttext) {
   if (thisfield.value == defaulttext) {
	thisfield.value = "";
   }
}

function validate_email(field,alerttxt)
{
  apos=document.forms['signup'].signUp.value.indexOf("@");
  dotpos=document.forms['signup'].signUp.value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2) 
    {
    alert(alerttxt);
    return false;
    }
  else
    {
    return true;
  }
}

function validate_form(thisform,msg)
{
  apos=document.forms['signup'].signUp.value.indexOf("@");
  dotpos=document.forms['signup'].signUp.value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2) 
    {
	alert(msg);
	}
  else
    {
    document.forms['signup'].submit(); 
	}
}

//prosearch stuff

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

//Keyword Stuff

var SearchBoxTb,SearchBoxTb2;
var txtSearch;
var strSearchBk = "";
var SearchBoxI = -1;
function Trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
document.onclick = function(){
	strSearchBk = "";
	SearchBoxTb.parentNode.parentNode.style.display = 'none';
	SearchBoxTb2.parentNode.parentNode.style.display = 'none';
	ProdLineI = -1;
	if (SearchBoxI > -1)
	{
		SearchBoxTb.childNodes[SearchBoxI].childNodes[0].className = 'SearchBoxTd';
		SearchBoxI = -1;
	}
}
function SearchBoxInit()
{
	if(!txtSearch)
	{
		document.getElementById('searchLineId').value = '';
		SearchBoxTb = document.getElementById('SearchBoxTb').childNodes[0];
		SearchBoxTb2 = document.getElementById('SearchBoxTb2').childNodes[0];
		txtSearch = document.getElementById('txtSearch');
		if (window.location.href.indexOf('searchField=') < 0 && window.location.href.indexOf('prosearch.aspx') > 0)
			txtSearch.focus();
		var txtPos = findPos(txtSearch);
		SearchBoxTb2Top = txtPos[1];
		SearchBoxTb2.parentNode.parentNode.style.left = (txtPos[0] + 306) + 'px';
		SearchBoxTb2.parentNode.parentNode.style.top = txtPos[1] + 'px';
		SearchBoxTb.parentNode.parentNode.style.left = txtPos[0] + 'px';
		SearchBoxTb.parentNode.parentNode.style.top = txtPos[1] + 'px';
		if (BrowserDetect.browser != 'Explorer')
		{
			SearchBoxTb2TopSeed = '19'
		}
		else
		{
			SearchBoxTb2TopSeed = '18'
		}
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop + 21];
	}
}
function SearchKeyCheck(e)
{
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID)
   {  
		case 37:
   	   //document.getElementById('KeyName').value = "Arrow Left";
			if (ProdLineActive)
			{
				ProdLineActive = false;
				SearchBoxTb2.childNodes[ProdLineI].childNodes[0].className = 'SearchBoxTd';
				ProdLineI = -1;
			}
      break;
		case 38:
   	   //document.getElementById('KeyName').value = "Arrow Up";
			if (ProdLineActive)
		  		ProdLineMove(-1);
		  	else
				SearchBoxTdMove(-1);
      break;
		case 39:
   	   //document.getElementById('KeyName').value = "Arrow Right";
			if (SearchBoxTb2.parentNode.parentNode.style.display == '')
			{
				ProdLineActive = true;
		  		ProdLineMove(1);
			}
      break;
		case 40:
	     // document.getElementById('KeyName').value = "Arrow Down";
		  if (ProdLineActive)
		  	ProdLineMove(1);
		  else
			SearchBoxTdMove(1);
      break;
		case 13:
			if (ProdLineActive)
				ProdLineClick(SearchBoxTb2.childNodes[ProdLineI].childNodes[0]);
			else
				SearchBoxTdClick(SearchBoxTb.childNodes[SearchBoxI].childNodes[0])
	      	//document.searchForm.submit();
			return false;
      break;
		case 27:
	      //document.getElementById('KeyName').value = "Escape";
			SearchBoxExcape();
		break;
		default:
			ProdLineActive = false;
			SearchBoxTb2.parentNode.parentNode.style.display = 'none';
			ProdLineI = -1;
			SearchBoxPop();
      break;
		}
}
function SearchBoxExcape()
{
	txtSearch.value = strSearchBk;
	strSearchBk = "";
	if (SearchBoxI > -1)
	{
		SearchBoxTb.childNodes[SearchBoxI].childNodes[0].className = 'SearchBoxTd';
		SearchBoxI = -1;
	}
	SearchBoxClose();
}
function SearchBoxPop()
{
	if (SearchBoxI > -1)
	{
		SearchBoxTb.childNodes[SearchBoxI].childNodes[0].className = 'SearchBoxTd';
		SearchBoxI = -1;
	}
	strSearchBk = txtSearch.value;
	strSearch = Trim(strSearchBk.toLowerCase());
	if (strSearch == '')
	{
		SearchBoxTb.parentNode.parentNode.style.display = 'none';
		return;
	}
	try
	{
		if(eval('typeof ' + strSearch.substring(0,1) + '_arr')!='undefined')
		{	
			var arr = eval(strSearch.substring(0,1) + '_arr');
			for (i=0;i<SearchBoxTb.childNodes.length;i++)
				SearchBoxTb.childNodes[i].childNodes[0].style.display = 'none';
			var k = 0;
			for (i=0;i<arr.length;i++)
			{
				if (arr[i].indexOf(strSearch) == 0)
				{
					tmpI = arr[i].indexOf('`');
					SearchBoxTb.childNodes[k].childNodes[0].setAttribute('BrandId',arr[i].substring(tmpI+1));
					tmpS = arr[i].substring(0,tmpI);
					SearchBoxTb.childNodes[k].childNodes[0].innerHTML = tmpS;
					SearchBoxTb.childNodes[k].childNodes[0].className = 'SearchBoxTd';
					if (tmpS == strSearch)
						SearchBoxTdActivate(SearchBoxTb.childNodes[k].childNodes[0]);
					SearchBoxTb.childNodes[k].childNodes[0].style.display = '';
					k++;
				}
				if (k==10)
					break;
			}
			
			if (k > 0)
				SearchBoxTb.parentNode.parentNode.style.display = '';
			else
				SearchBoxTb.parentNode.parentNode.style.display = 'none';
		}
	}
	catch(err)
	{
	
	}
}
function SearchBoxTdMove(i)
{
	if (SearchBoxTb.parentNode.parentNode.style.display == 'none')
		return;
	var tmpI = SearchBoxI + i
	if (tmpI < 0 || tmpI > SearchBoxTb.childNodes.length - 1 || SearchBoxTb.childNodes[tmpI].childNodes[0].style.display == 'none')
		return;
	else
	{
		txtSearch.value = SearchBoxTb.childNodes[tmpI].childNodes[0].innerHTML;
		SearchBoxTdActivate(SearchBoxTb.childNodes[tmpI].childNodes[0])
	}
}
function SearchBoxTdOver(td)
{
	ProdLineActive = false;
	SearchBoxTdActivate(td)
	//alert(td.getAttribute('IsBrand'));
}
function SearchBoxTdClick(td)
{
	txtSearch.value = td.innerHTML;
	activeBrand = td.getAttribute('BrandId');
	if (activeBrand != '0')
		document.getElementById('searchLineId').value = 'B' + activeBrand;
	document.searchForm.submit();
}
function SearchBoxTdActivate(td)
{
	if (SearchBoxI > -1)
		SearchBoxTb.childNodes[SearchBoxI].childNodes[0].className = 'SearchBoxTd';
	SearchBoxI = parseInt(td.getAttribute('childI'));
	td.className = 'SearchTdActive';
	SearchBoxTb2.parentNode.parentNode.style.display = 'none';
	ProdLineI = -1;
	activeBrand = td.getAttribute('BrandId');
	if (!ajLocked)
		AjGetLine(activeBrand, langId);
}
function SearchBoxClose()
{
	SearchBoxTb.parentNode.parentNode.style.display = 'none';
	SearchBoxTb2.parentNode.parentNode.style.display = 'none';
	ProdLineI = -1;
}
//alert(BrowserDetect.browser + " -- " + BrowserDetect.version + " -- " + BrowserDetect.OS);
function WinResize()
{
		var txtPos = findPos(txtSearch);
		SearchBoxTb2Top = txtPos[1];
		SearchBoxTb2.parentNode.parentNode.style.left = (txtPos[0] + 306) + 'px';
		SearchBoxTb2.parentNode.parentNode.style.top = txtPos[1] + 'px';
		SearchBoxTb.parentNode.parentNode.style.left = txtPos[0] + 'px';
		SearchBoxTb.parentNode.parentNode.style.top = txtPos[1] + 'px';
}
function QuickSearchClick(a)
{
	if (a.childNodes[0].src.indexOf('plus.gif') > 0)
	{
		a.childNodes[0].src = '/images/common/minus.gif';
		document.getElementById('divQuick').style.display = '';
		document.getElementById('divQuickTopSpace').style.display = '';
	}
	else
	{
		a.childNodes[0].src = '/images/common/plus.gif';
		document.getElementById('divQuick').style.display = 'none';
		document.getElementById('divQuickTopSpace').style.display = 'none';
	}
}
function rejectEnter(event) {
  if (event && event.which == 13)
    return false;
  else
    return true;
}

//ProdLine Stuff

		
		function ProdLineClick(td)
		{
			txtSearch.value = SearchBoxTb.childNodes[SearchBoxI].childNodes[0].innerHTML + " " + td.innerHTML;
			document.getElementById('searchLineId').value = td.getAttribute('ProdLineId');
			document.searchForm.submit();
		}
		function ProdLineOver(td)
		{
			ProdLineActivate(td);
		}
		function ProdLineActivate(td)
		{
			ProdLineActive = true;
			if (ProdLineI > -1)
				SearchBoxTb2.childNodes[ProdLineI].childNodes[0].className = 'SearchBoxTd';
			ProdLineI = parseInt(td.getAttribute('childI'));
			td.className = 'SearchTdActive';
		}
		function ProdLineMove(i)
		{
			if (SearchBoxTb2.parentNode.parentNode.style.display == 'none')
				return;
			var tmpI = ProdLineI + i;
			if (tmpI < 0 || tmpI > SearchBoxTb2.childNodes.length - 1)
				return;
			else
			{
				ProdLineActivate(SearchBoxTb2.childNodes[tmpI].childNodes[0]);
			}
		}	
		
//ajax stuff
var ajLocked = false;
var ProdLineActive = false;
var SearchBoxTb2Top, SearchBoxTb2TopSeed;
var ajBrand, activeBrand;
var langId = '1' //'<%=session("LangId").ToString%>';
var ProdLineI = -1;
function AjGetLine(brandId, langId){
	if(brandId == '0')
	{
	}
	else
	{
		ajLocked = true;
		ajBrand = brandId;
		GetBrandLine.GetLine(brandId,langId, GetLine_CallBack);
	}
}
function GetLine_CallBack(response){
	if (ajBrand != activeBrand)
	{
		
	}
	if (response.error == null){
		if (response.value != '')
		{
			SearchBoxTb2.parentNode.parentNode.innerHTML = response.value;
			SearchBoxTb2 = document.getElementById('SearchBoxTb2').childNodes[0];
			SearchBoxTb2.parentNode.parentNode.style.top = SearchBoxTb2Top + (SearchBoxI*SearchBoxTb2TopSeed) + 'px';
			SearchBoxTb2.parentNode.parentNode.style.display = '';
		}
		ajLocked = false;	
	 }
}

//AJAX common.ashx

var requests = new Array();

if(typeof(XMLHttpRequest) == 'undefined')
var XMLHttpRequest = function()
{
	var request = null;
	try
	{
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e)
	{
		try
		{
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(ee)
		{}
	}
	return request;
}

function ajax_stop()
{
	for(var i=0; i<requests.length; i++)
	{
		if(requests[i] != null)
			requests[i].abort();
	}
}

function ajax_create_request(context)
{
	for(var i=0; i<requests.length; i++)
	{
		if(requests[i].readyState == 4)
		{
			requests[i].abort();
			requests[i].context = null;
			return requests[i];
		}
	}

	var pos = requests.length;
	
	requests[pos] = Object();
	requests[pos].obj = new XMLHttpRequest();
	requests[pos].context = context;
	
	return requests[pos];
}

function ajax_request(url, data, callback, context)
{
	var request = ajax_create_request(context);
	var async = typeof(callback) == 'function';

	if(async) request.obj.onreadystatechange = function()
	{
		if(request.obj.readyState == 4)
			callback(new ajax_response(request));
	}
	
	request.obj.open('POST', url, async);
	request.obj.send(data);
	
	if(!async)
		return new ajax_response(request);
}

function ajax_response(request)
{
	this.request = request.obj;
	this.error = null;
	this.value = null;
	this.context = request.context;
	
	if(request.obj.status == 200)
	{
		try
		{
			this.value = object_from_json(request);
			
			if(this.value && this.value.error)
			{
				this.error = this.value.error;
				this.value = null;
			}
		}
		catch(e)
		{
			this.error = new ajax_error(e.name, e.description, e.number);
		}
	}
	else
	{
		this.error = new ajax_error('HTTP request failed with status: ' + request.obj.status, request.obj.status);
	}
	
	return this;
}

function enc(s)
{
	return s.toString().replace(/\%/g, "%26").replace(/=/g, "%3D");
}

function object_from_json(request)
{
	if(request.obj.responseXML != null && request.obj.responseXML.xml != null && request.obj.responseXML.xml != '')
		return request.obj.responseXML;
	
	var r = null;	
	eval('r=' + request.obj.responseText + ';');
	return r;
}

function ajax_error(name, description, number)
{
	this.name = name;
	this.description = description;
	this.number = number;

	return this;
}

ajax_error.prototype.toString = function()
{
	return this.name + " " + this.description;
}

function json_from_object(o)
{
	if(o == null)
		return 'null';

	switch(typeof(o))
	{
		case 'object':
			if(o.constructor == Array)		// checks if it is an array [,,,]
			{
				var s = '';
				for(var i=0; i<o.length; ++i)
				{
					s += json_from_object(o[i]);

					if(i < o.length -1)
						s += ',';
				}

				return '[' + s + ']';
			}
			break;
		case 'string':
			return '"' + o.replace(/(["\\])/g, '\\$1') + '"';
		default:
			return String(o);
	}
}var ajaxVersion = '5.6.3.4'

//AJAX GetBrandLine,GetBrandLine.ashx
// cached javascript
var GetBrandLine = {
GetLine:function(BrandId,LangId,callback,context){return new ajax_request(this.url + '?_method=GetLine&_session=no','BrandId=' + enc(BrandId)+ '\r\nLangId=' + enc(LangId),callback, context);},
url:'/ajax/GetBrandLine,GetBrandLine.ashx'
}
function HtmlControl(id) {
	var ele = null;
	if(typeof(id) == 'object') ele = id; else ele = document.getElementById(id);
	if(ele == null) return null;
	var _o = ele.cloneNode(true);
	var _op = document.createElement('SPAN');
	_op.appendChild(_o);	
	this._source = _op.innerHTML;
}
HtmlControl.prototype.toString = function(){ return this._source; }

function HtmlControlUpdate(func, parentId) {
var f,i,ff,fa='';
var ele = document.getElementById(parentId);
if(ele == null) return;
var args = [];
for(i=0; i<HtmlControlUpdate.arguments.length; i++)
	args[args.length] = HtmlControlUpdate.arguments[i];
if(args.length > 2)
	for(i=2; i<args.length; i++){fa += 'args[' + i + ']';if(i < args.length -1){ fa += ','; }}
f = '{"invoke":function(args){return ' + func + '(' + fa + ');}}';
ff = null;eval('ff=' + f + ';');
if(ff != null && typeof(ff.invoke) == 'function')
{
	var res = ff.invoke(args);
	if(res.error != null){alert(res.error);return;}
	ele.innerHTML = res.value;
}
}
function TimeSpan(){this.Days=0;this.Hours=0;this.Minutes=0;this.Seconds=0;this.Milliseconds=0;}
TimeSpan.prototype.toString = function(){return this.Days+'.'+this.Hours+':'+this.Minutes+':'+this.Seconds+'.'+this.Milliseconds;}
function digi(v, c){v = v + "";var n = "0000";if(v.length < c) return n.substr(0, c-v.length) + v;return v;}
function DateTime(year,month,day,hours,minutes,seconds){if(year>9999||year<1970||month<1||month>12||day<0||day>31||hours<0||hours>23||minutes<0||minutes>59||seconds<0||seconds>59)throw("ArgumentException");this.Year = year;this.Month = month;this.Day = day;this.Hours = hours;this.Minutes = minutes;this.Seconds = seconds;}
DateTime.prototype.toString = function(){return digi(this.Year,4) + digi(this.Month,2) + digi(this.Day,2) + digi(this.Hours,2) + digi(this.Minutes,2) + digi(this.Seconds,2);}
function _getTable(n,e){for(var i=0; i<e.Tables.length; i++){if(e.Tables[i].Name == n)return e.Tables[i];}return null;}
function AjaxImage(url){var img=new Image();img.src=url;return img;}