// WebWiz Core WebWiz - Version 1.0.012

function fieldblur(field){
	if(field.value==''){
		field.value=field.defaultValue;
		field.className+=' defaultvalue';
	}
}

function fieldfocus(field){
	field.className=field.className.replace('defaultvalue','');
	
	if(field.value==field.defaultValue){
		field.value='';
	}
}

function exec_function(strFunctionName){
	if(eval('typeof('+strFunctionName+')==\'function\'')){
		eval(strFunctionName+'()');
	}
}

function popup(strQueryString,strName,intWidth,intHeight){
	var popup_window=window.open('/popup.asp'+strQueryString,strName,'width='+intWidth+',height='+intHeight);
	popup_window.focus();
}

var objTimers=new Object;

function dropdown(menuItem,blnShow){
	if(typeof(menuItem)!='object'){
		menuItem=document.getElementById(menuItem);
	}
	
	if(menuItem){
		if(blnShow){
			if(objTimers[menuItem.id]){
				window.clearTimeout(objTimers[menuItem.id]);
				objTimers[menuItem.id]=undefined;
			}
			
			menuItem.style.visibility='visible';
		}else{
			objTimers[menuItem.id]=window.setTimeout('document.getElementById(\''+menuItem.id+'\').style.visibility=\'hidden\';',150);
		}
	}
}

function gedit(strTagID){
	return document.getElementById(strTagID);
}

function notempty(strTagID){
	var arrTagID=strTagID.split(' ');
	
	for(var n=0;n<arrTagID.length;n++){
		if(gedit(arrTagID[n])){
			if(gedit(arrTagID[n]).value==''){
				return false;
			}
		}else{
			return false;
		}
	}
	
	return true;
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie(name,value){
	document.cookie=name+"="+escape(value);
}

function createAJAX(){
	try{ //IE7 + Firefox + Opera + Safari
		return (new XMLHttpRequest());
	}catch (e){
		try{ //IE6
			return (new ActiveXObject("Msxml2.XMLHTTP"));
		}catch (e){ //IE5.5
			return (new ActiveXObject("Microsoft.XMLHTTP"));
		}
	}
}

/*
		PROBLEM -  xmlQuickSearchDataHttp=new Object() 
				MEANS IE6 SEES  xmlQuickSearchDataHttp[x] AS [OBJECT]
				WE NEED TO CREATE A STATIC ARRAY AND WRITE AN ALGO
				TO STORE THE XML OBJS IN THE ARRAY
*/

var xmlQuickSearchDataHttp=new Object();
var strAttributeRefs=new Object();
var strItemType;
var strRefreshingText='';

function setupQuickSearchAJAX(strNewItemType,strNewAttributeRefs,strNewRefreshingText,attribAppendString,defaultAttribData){
	strItemType=strNewItemType;
	//strAttributeRefs=strNewAttributeRefs;
	strRefreshingText=strNewRefreshingText;
	
	if (attribAppendString==undefined)
		attribAppendString='';

	if (defaultAttribData!=''&&defaultAttribData!=undefined) {
		var arrDefaultAttribData=defaultAttribData.split('|');
		var arrDefaultAttribRefs;

		for(var n in arrDefaultAttribData){
			arrDefaultAttribRefs=arrDefaultAttribData[n].split('=');
			strNewAttributeRefs=strNewAttributeRefs+'|'+arrDefaultAttribRefs[0];
		}
	} 

	xmlQuickSearchDataHttp['_'+attribAppendString]=createAJAX();
	strAttributeRefs['_'+attribAppendString]=new Object();
	strAttributeRefs['_'+attribAppendString].value=strNewAttributeRefs;
	
	updateQuickSearchAJAX(attribAppendString);
}

function processReadyStateChange(){
	
	if(this.readyState==4){
		
		var strData=this.responseText;
		var attribSuffix='';
				
		var arrData=strData.split('\r\n');

		//for(var n in arrData){
		for(var n=0;n<arrData.length;n++){
			arrPair=arrData[n].split('\t')
			
			switch(arrPair[0]) {
			
				case 'suffix':
			 		attribSuffix=arrPair[1];
				break;
				
				case 'itemcount':
					if(document.getElementById(arrPair[0]+'_'+attribSuffix)){document.getElementById(arrPair[0]+'_'+attribSuffix).innerHTML=arrPair[1];}
				break;
				
				default:
				var oSelect=document.getElementById('quicksearch_'+arrPair[0]); //suffix already returned in data

				if(oSelect){
					if(oSelect.type!='hidden'&&oSelect.type!='Hidden'){
						oSelect.innerHTML='';

						if(oSelect.outerHTML){
							oSelect.outerHTML='<select onchange="updateQuickSearchAJAX(\''+attribSuffix+'\');" name="'+oSelect.name+'" id="'+oSelect.id+'">'+arrPair[1]+'</select>';
						}else{
							oSelect.innerHTML=arrPair[1];
						}
					}
				}
			}	
			
		}
		
	}
}	

	
function updateQuickSearchAJAX(attribSuffix){
	//go through "strAttributeList"

	var strAttributeValues='';
	var arrAttributeRefs=strAttributeRefs['_'+attribSuffix].value.split('|');
	
	//for(var n in arrAttributeRefs){
	for(var n=0;n<arrAttributeRefs.length;n++){
		//alert(arrAttributeRefs[n].toLowerCase());
		//alert('quicksearch_'+arrAttributeRefs[n].toLowerCase().replace(/\s/g,'')+'_'+attribSuffix);
		var oSelect=document.getElementById('quicksearch_'+arrAttributeRefs[n].toLowerCase().replace(/\s/g,'')+'_'+attribSuffix);
		
		if(oSelect){
			if(oSelect.value!=''){
				strAttributeValues+=arrAttributeRefs[n]+':'+oSelect.value+'@';
			}
		}
	}
	
	if(strAttributeValues){
		if(document.getElementById('resultrow_'+attribSuffix)){
			document.getElementById('resultrow_'+attribSuffix).className='';
		}
		if(document.getElementById('itemcount_'+attribSuffix)){
			if(strRefreshingText.substring(0,1)=='/'){
				document.getElementById('itemcount_'+attribSuffix).innerHTML='<img src="'+strRefreshingText+'" alt="" />';
			}else{
				document.getElementById('itemcount_'+attribSuffix).innerHTML=strRefreshingText;
			}
		}
	}else{
		if(document.getElementById('resultrow_'+attribSuffix)){
			document.getElementById('resultrow_'+attribSuffix).className='hide';
		}
	}
	
	strAttributeRefs['_'+attribSuffix].value=strAttributeRefs['_'+attribSuffix].value.replace('&','%26');
	strAttributeValues=strAttributeValues.replace('&','%26');
	
	var strURL='/quicksearch.asp?itemtyperef='+strItemType+'&attributerefs='+strAttributeRefs['_'+attribSuffix].value+'&attribsuffix='+attribSuffix+'&attributevalues='+strAttributeValues+'&10';

	if(xmlQuickSearchDataHttp['_'+attribSuffix].readyState>0){xmlQuickSearchDataHttp['_'+attribSuffix].abort();}
	xmlQuickSearchDataHttp['_'+attribSuffix].onreadystatechange=processReadyStateChange;
	
	xmlQuickSearchDataHttp['_'+attribSuffix].open('get',strURL,true);
	xmlQuickSearchDataHttp['_'+attribSuffix].send(null);
	defaultValues='';
}

