var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
if(location.href.indexOf('/dascosales.com/') != -1 ){
	var rootdomain="http://"+window.location.hostname+"/dascosales.com/";
	var cgi = "http://"+window.location.hostname+"/dascosales.com/cgi-bin/";
}else{
	var rootdomain="http://"+window.location.hostname+"/";
	var cgi = "http://"+window.location.hostname+"/cgi-bin/";	
}

function getElementObject (elementId) {
if (document.all)
return document.all[elementId];
else if (document.getElementById)
return document.getElementById(elementId);
else
return null;
}

var bustcacheparameter=""
var xmlHttp
var vertStartPos = 110;
var showErrors = 1;
var lastPageSave = 1;
var startSearch = 'Enter product model number here...';
var showAdvancedSearchOption = 0;
var showAdvancedSearchOptionExclusive = 0;

function $(element){
//  if (arguments.length > 1) {
//    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
//      elements.push($(arguments[i]));
//    return elements;
//  }
//  if (Object.isString(element))
//    element = $(element);
//  return Element.extend(element);
    return document.getElementById(element);
}

function cleanValue(value){
	var cleanValue = value.replace(/&/g,'-,-');
	var cleanValue2 = cleanValue.replace(/#/g,'-,,-');	
	
	return cleanValue2;
}

function clearLoadingDiv(){
	if($('loadingDiv')){loading();}
}

function loading(area,gif,top){
	if($('loadingDiv')){
		$('loadingDiv').parentNode.removeChild($('loadingDiv'));
		if($('bckGroundDim')){$('bckGroundDim').parentNode.removeChild($('bckGroundDim'));}
		return;
	}
	if(area == 'onLoadLogin'){
		var iconArea = $(area);
		//controlPanel.innerHTML = '';
		
		div = document.createElement('div');
		//div.className = 'onLoad';
		div.style.position = 'absolute';
		div.id = 'loadingDiv';
		img = document.createElement('img');
		img.src = rootdomain + 'RootImages/onLoadArrows.gif';
		div.appendChild(img);
		iconArea.appendChild(div);

	}else{
		var iconArea = $(area);
		//controlPanel.innerHTML = '';
		
		div = document.createElement('div');
		//div.className = 'onLoad';
		div.style.position = 'fixed'; //fixed so it will show regardless of scroll
		div.id = 'loadingDiv';
		if(top){
			div.style.top = top;
		}else{
			div.style.top = 50 +'%';
		}
		div.style.left = '50%';
		div.align = 'center';

		img = document.createElement('img');
		if(gif){
			img.src = rootdomain + 'RootImages/'+gif;
		}else{			
			img.src = rootdomain + 'RootImages/onLoad.gif';
			//showBckGroundDim();
		}
		
		div.appendChild(img);
		if($('pageFooter')){$('pageFooter').appendChild(div);}
	}
}

function GetXmlHttpObject(url){
if(lastPageSave == 1 && url && url.indexOf('RootControlpanel/login.php') == -1){lastPage(url);}
var xmlHttp=null;
	try{  // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
  }
return xmlHttp;
}


function loadPage(url,containerid,functionName,page){ //page indicates top which reloads top page after popBoxRemove
if(!$('controlPanel')){location.href = rootdomain+'controlpanel.php';return;}
	if(!$('loadingDiv')){	loading('controlPanel');}
	
	//alert('url: '+url);
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){loadPageRsp(xmlHttp, containerid,functionName,url,page)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadPageRsp(xmlHttp, containerid,functionName,url,page){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){

if($('loadingDiv')){loading();}

$(containerid).style.height = '';
//	window.scroll(0,vertStartPos);

if(url.indexOf('edit_categories') != -1 || url.indexOf('edit_products') != -1){ 
	$(containerid).innerHTML=xmlHttp.responseText;
	
		var tinyMceScript = document.createElement('script');
		tinyMceScript.src = rootdomain + 'RootIncludes/tinymce.js';
		$(containerid).appendChild(tinyMceScript);

}else if(url.indexOf('edit_coupons') != -1 || url.indexOf('examples') != -1){ 
	$(containerid).innerHTML=xmlHttp.responseText;
//	loadScript('edit_coupons',containerid,xmlHttp.responseText,'0');
	return false;
}else if(url.indexOf('login.php?req=1') != -1){ 
	var theGoods = xmlHttp.responseText.split('|');
	$(containerid).innerHTML=xmlHttp.responseText;
	if(page == 'cp0'){controlPanel('id','url',1);}else{controlPanel('id','',1);}
}else{
	if(page == 'top'){
	top.$(containerid).innerHTML=xmlHttp.responseText;
	}else{
	$(containerid).innerHTML=xmlHttp.responseText;
	}
	var pageFooter = top.$('pageFooter');	
	var bckGroundDim = top.$('bckGroundDim');		
	var popBox = top.$('popBox');
//	pageFooter.removeChild(popBox);
//	pageFooter.removeChild(bckGroundDim);

if(functionName){eval(functionName);}

		if(url.indexOf('view_categories.php') != -1){
			if($('categorySearchDiv')){
				smartSearch('category');
				var categorySearchDiv = $('categorySearchDiv');
				$('searchInput').value = categorySearchDiv.innerHTML;
			}
			populateSmartSearch('category');			
		}else if(url.indexOf('view_products.php') != -1){
			if($('productSearchDiv')){
				smartSearch('product');
				var productSearchDiv = $('productSearchDiv');
				$('searchInput').value = productSearchDiv.innerHTML;
			}
			populateSmartSearch('product');			
		}

	
}

}
}

function lastPage(newUrl){
	if(window.location.href.indexOf('/RootControlpanel/') == -1){
			var lastPage = $('lastPage');
			var pageFooter = $('pageFooter');
		if(newUrl.indexOf('phpScript.php') == -1){
			if(!$('lastPage2')){
				var lastPage2 = document.createElement('div');
				lastPage2.id = 'lastPage2';
				lastPage2.style.display = '';
				lastPage2.align = 'center';				
				lastPage2.style.textAlign = 'center';								
				pageFooter.appendChild(lastPage2);
	
			}else{
				var lastPage2 = $('lastPage2');		
			}
			lastPage2.innerHTML = lastPage.innerHTML;
			var saveUrl = newUrl.split('&sid');
			if(saveUrl.length == 1){var saveUrl = newUrl.split('?sid');}
			lastPage.innerHTML = saveUrl[0];
		}
	}

	if($('divId')){
		var id = $('divId').innerHTML;
	}else{
		var id = '';
	}

	var cleanUrl = cleanValue(newUrl);
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=savePage&id='+id+'&url='+cleanUrl;
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	//alert('newUrl: '+newUrl+'\n cleanUrl: '+cleanUrl);
	
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){lastPageRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function lastPageRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
//			alert('id: '+theGoods[1]+'\n Url: '+theGoods[2]);
		}else{
//			if(showErrors == 1){alert('error: ' + xmlHttp.responseText);}
		}
	}
}

function createDivId(id){
	var pageFooter = $('pageFooter');
	var divId = document.createElement('div');
	divId.id = 'divId';
	divId.style.display = 'none';	
	divId.innerHTML = id;
	pageFooter.appendChild(divId);
}

function controlPanel(id,url,step){
	if(!$('controlPanel')){loadPage(rootdomain+'RootControlpanel/login.php','loginDiv','loadPage');return;}
	
	if(id != '' && !$('divId')){createDivId(id);}

	if(id != '' && url != ''){		
		if(url == rootdomain){controlPanel(id,'','');return;}
		if($('lastPage')){
			var lastPage = $('lastPage').innerHTML;
		}else{
			var lastPage = '';			
		}
		loadPage(lastPage,'controlPanel','loadPage','1');
		//alert('1 \n lastPage: '+lastPage+'\n id:'+id);
		return;			
	}else if(id != ''){
		loadPage(rootdomain+'RootControlpanel/view_categories.php','controlPanel','loadPage','1');
		//alert('2 \n lastPage: '+lastPage+'\n id:'+id);
		return;
	}else{
		location.href = rootdomain;
	}

}

function loadScript(type,containerid,pageLoad,step){
//alert('step: '+step);
var nextStep = Number(step) + 1;
//	alert('step: '+ step +' url: '+url+' pageLoad: '+pageLoad);	

	if(type == 'edit_coupons' && step == 3){
		alert('done');
		$(containerid).innerHTML=pageLoad;
		return;
	}else if(type == 'edit_coupons' && step == 2){
		var url = rootdomain + 'RootIncludes/valCalendar/jslib/vlaCal3.js?&sid'+Math.random();
		var head= document.getElementsByTagName('head')[0];
	    var script= document.createElement('script'), loaded = false;
	    script.type= 'text/javascript';
	    script.src= url;
		script.onload = script.onreadystatechange = function() {
			var rs = this.readyState;
			if (rs && rs!='complete' && rs!='loaded') return;
			if (loaded) return;
			loaded = true;
			head.removeChild(script);
			loadScript(type,containerid,pageLoad,nextStep)
		  };
	    head.appendChild(script);
		return;

	}else if(type == 'edit_coupons' && step == 1){
		var url = rootdomain + 'RootIncludes/valCalendar/jslib/vlaCal-v2.1.js?&sid'+Math.random();
		var head= document.getElementsByTagName('head')[0];
	    var script= document.createElement('script'), loaded = false;
	    script.type= 'text/javascript';
	    script.src= url;
		script.onload = script.onreadystatechange = function() {
			var rs = this.readyState;
			if (rs && rs!='complete' && rs!='loaded') return;
			if (loaded) return;
			loaded = true;
			head.removeChild(script);
			loadScript(type,containerid,pageLoad,nextStep)
		  };
	    head.appendChild(script);
		return;
		
	}else if(type == 'edit_coupons' && step == 0){
		var url = rootdomain + 'RootIncludes/valCalendar/jslib/mootools-1.2-core.js?&sid'+Math.random();
		var head= document.getElementsByTagName('head')[0];
	    var script= document.createElement('script'), loaded = false;
	    script.type= 'text/javascript';
	    script.src= url;
		script.onload = script.onreadystatechange = function() {
			var rs = this.readyState;
			if (rs && rs!='complete' && rs!='loaded') return;
			if (loaded) return;
			loaded = true;
			head.removeChild(script);
			loadScript(type,containerid,pageLoad,nextStep)
		  };
	    head.appendChild(script);
		return;
	}

//	url=url+"?sid="+Math.random();


//	xmlHttp=GetXmlHttpObject(url);
//	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
//	xmlHttp.onreadystatechange=function(){loadScriptRsp(type,containerid,pageLoad,nextStep)};
//	xmlHttp.open("GET",url,true);
//	xmlHttp.send(null);
}

function loadScriptRsp(type,containerid,pageLoad,nextStep){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		eval[xmlHttp.responseText];
		loadScript(type,containerid,pageLoad,nextStep);
		return false;
	}
}

function fnValidateLogin(){
	$('loginWarning').style.display = 'none';
	$('loginWarning').innerHTML = '';
	$('loginWarning').style.height = '0px';
	if($('email').value == ''){
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Be sure to enter your email address.';
		return false; 
	}
	if($('email').value == ''){
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Be sure to enter your email address.';
		return false; 
	}
if (validate(Trim($('email').value), "email") == false) {
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Be sure to enter a valid email address.';
		return false;
	}

if($('pswd').value == ''){$('pswd').focus();$('loginWarning').style.height = '25px';$('loginWarning').innerHTML = 'Be sure to enter a password.';return false; }
	
	loading('onLoadLogin');
	if($('loginSubmitTxt').innerHTML == 'Send Email'){
		loginSubmit('emailRequest',$('email').value,$('pswd').value);
	}else{
		loginSubmit('login',$('email').value,$('pswd').value);
	}
}

function keyPress(type,mode,Id,e){
//alert('type: '+type+' mode: '+mode+' Id: '+Id);

var key;
	 if(window.event)
		  key = window.event.keyCode;     //IE
	 else
		  key = e.which;     //firefox
	if (key == 13){
		if(type == 'login'){
			fnValidateLogin();
		}else if(type == 'category'){	
			fnValidateCategory(mode,Id,'0')
		}else if(type == 'product'){	
			fnValidateProduct(mode,Id,'0')
		}else if(type == 'coupon'){	
			fnValidateCoupon(mode,Id,'0')
		}else if(type == 'user'){	
			fnValidateUser(mode,Id,'0')			
		}else if(type.indexOf('upload|') != -1){
			StartUpload(type.split('|')[1],'','xls', $('uploadSelectAction').value);
		}else if(type.indexOf('image|') != -1){
			return StartUpload(type.split('|')[1],Id,'image');
		}else if(type == 'addChar'){
			addChar('saveCharNew');
		}
	}
}

function loginSubmit(mode,email,pswd){ 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/phpScript.php";
	url2=url+"?req=login.php&mode="+mode+"&email="+email;

	var cleanEmail = cleanValue(email);
	var cleanPswd = cleanValue(pswd);
	url=url+"?req=login.php&mode="+mode+"&email="+cleanEmail+"&pswd="+cleanPswd;
	url=url+"&sid="+Math.random();

	xmlHttp=GetXmlHttpObject(url2);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){loginSubmitRsp(mode)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
//	alert(url);
}

function loginSubmitRsp(mode){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		//alert(xmlHttp.responseText);
		clearLoadingDiv();
		$('loginWarning').style.innerHTML = '';
		$('loginWarning').style.display = 'none';

		var theGoods = xmlHttp.responseText.split('|');
		if(mode=='emailRequest'){
			if(theGoods[0] == 1){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'password sent to '+theGoods[1];
				//$('controlpanel').innerHTML = theGoods[2];
			}else if(theGoods[0] == 0){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = theGoods[1]+' not in database';
			}else{
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'There has been a problem.  Please contact your site administrator.';			
				if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
			}
		}else{
			if(theGoods[0] == 1){
				$('loginWarning').style.height = '0px';
				$('loginWarning').innerHTML = '';
				createDivId(theGoods[1]);
				//loadPage(rootdomain+'RootControlpanel/login.php?req=1','loginDiv','loadPage');
				location.href = rootdomain + 'controlpanel.php';
			}else if(theGoods[0] == 0){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'Invalid Email Address/Password';
			}else{
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'There has been a problem.  Please contact your site administrator.';			
				if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
			}
		}
	}
}

function logoutSubmit(){ 
if(!$('loadingDiv')){	if($('controlPanel')){loading('controlPanel');}	}
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/phpScript.php";
	url=url+"?req=login.php&mode=logout";
	url=url+"&sid="+Math.random();

	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){logoutSubmitRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function logoutSubmitRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			loadPage(rootdomain+'RootControlpanel/login.php','loginDiv','loadPage');
			$('controlPanel').innerHTML = '';
			$('pageFooter').removeChild($('divId'));
		location.href = rootdomain+'sign-in.php';
		return;
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function valueCk(type,field,value,warning,Id,nextFunction,nextStep,mode){
	if($(warning)){
		$(warning).style.display = 'none';
		$(warning).innerHTML = '';
	}
if(type == 'coupon' && field == 'Discount'){
	if(document.thisForm.Discount.value == '' || Number(stripNonNumeric(document.thisForm.Discount.value )) <= 0){
		$('discountWarning').style.display = '';
		$('discountWarning').innerHTML = 'Insert the discount amount assigned to this coupon.';
		window.scroll(0,vertStartPos);
		return false;
	}
	return true;
}else if(type == 'coupon' && field == 'CouponCode'){
	if(document.thisForm.CouponCode.value == ''){
		$(warning).style.display = '';
		$(warning).innerHTML = 'Don\'t forget to insert a coupon code.';
		window.scroll(0,vertStartPos);
		return false;
	}else if(document.thisForm.CouponCode.value.length < 5){
		$(warning).style.display = '';
		$(warning).innerHTML = 'The coupon code must be at least five characters.';
		window.scroll(0,vertStartPos);
		return false;
	}
}else if(type == 'user' && field == 'email'){
	$(warning).style.display = 'none';
	$(warning).innerHTML = '';
	if(document.thisForm.email.value == ''){
		$(warning).style.display = '';
		$(warning).innerHTML = 'Don\'t forget to insert an email address.';
		window.scroll(0,vertStartPos);
		return false;
	}else if (validate(Trim(document.thisForm.email.value), "email") == false) {
		$(warning).style.display = '';
		$(warning).innerHTML = 'Be sure to enter a valid email address.';
		window.scroll(0,vertStartPos);
		return false;
	}
}else if(type == 'user' && field == 'name'){
		$(warning).style.display = 'none';
		$(warning).innerHTML = '';		
		if(document.thisForm.f_name.value == '' || document.thisForm.f_name.value == ''){
			$(warning).style.display = '';
			$(warning).innerHTML = 'Don\'t forget to enter this user\'s name.';
			return false;
		}
		return true; //no need to top database for name
}else{
	if($(warning)){
		$(warning).style.display = 'none';
		$(warning).innerHTML = '';
	}
	if(value == ''){
		$(warning).style.display = '';
		$(warning).innerHTML = 'Don\'t forget to insert a '+type+' name.';
		//document.thisForm.Name.focus();
		window.scroll(0,vertStartPos);
		return false;
	}
}

	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/phpScript.php";
	var cleanVal = cleanValue(value);
	if(type == 'category'){
		url=url+"?req=edit_categories.php&mode=valueCk&CatId="+Id+"&"+field+"="+cleanVal;
	}else if(type == 'product'){
		url=url+"?req=edit_products.php&mode=valueCk&ProductId="+Id+"&"+field+"="+cleanVal;
	}else if(type == 'coupon'){
		url=url+"?req=edit_coupons.php&mode=valueCk&CouponId="+Id+"&"+field+"="+cleanVal;
	}else if(type == 'user'){
		url=url+"?req=edit_users.php&mode=valueCk&userId="+Id+"&"+field+"="+cleanVal;
	}
	url=url+"&sid="+Math.random();

	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){valueCkRsp(type,field,value,warning,Id,nextFunction,nextStep,mode)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	//alert(url);
}

function valueCkRsp(type,field,value,warning,Id,nextFunction,nextStep,mode){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		//alert('Response: '+xmlHttp.responseText);

		if($('loadingDiv')){loading();}
		
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){	
			$(warning).style.display = 'none';
			$(warning).innerHTML = '';
			if(nextFunction != ''){
				//alert('nextStep: ' + nextFunction + '('+mode+','+Id+','+nextStep+')');
				window[nextFunction](mode,Id,nextStep);
			}
			if(type == 'user' && field == 'email'){
				$('emailTrue').style.display = '';
			}
				
			//alert('true');

		}else if(theGoods[0] == 0){
			window.scroll(0,vertStartPos);
			$(warning).style.display = '';
			if(field == 'CouponCode'){
				$(warning).innerHTML = 'This coupon code is already in use. Please choose a different one.';
			}else if(field == 'email'){
				$(warning).innerHTML = 'This email address is already in the database.';
				$('emailTrue').style.display = 'none';
			}else{
				$(warning).innerHTML = 'This '+type+' name is already in use. Please choose a different one.';					
			}
			//document.thisForm.Name.focus();
			return false;
		}else{
			if(showErrors == 1){alert('error: ' + xmlHttp.responseText);}
		}

	}
}

function imageCk(){
	$('imageWarning').style.display = 'none';
	$('imageWarning').innerHTML = '';
		
	var ImageValue = document.thisForm.image.value;
	jpgSearch = ImageValue.indexOf(".jpg");
	jpgSearch2 = ImageValue.indexOf(".JPG");
	jpegSearch = ImageValue.indexOf(".jpeg");
	jpegSearch2 = ImageValue.indexOf(".JPEG");
	gifSearch = ImageValue.indexOf(".gif");
	gifSearch2 = ImageValue.indexOf(".GIF");
	
	if(document.thisForm.image.value!="" && (jpgSearch != -1 || jpgSearch2 != -1 || jpegSearch != -1 || jpegSearch2 != -1 || gifSearch != -1 || gifSearch2 != -1)){
		return true;
	}else if(document.thisForm.image.value!=""){
		window.scroll(0,vertStartPos);
		$('imageWarning').style.display = '';
		$('imageWarning').innerHTML = 'Please select an image file in one of the following formats: .jpg, .jpeg or .gif.';
		document.thisForm.image.focus(); 
		return false;
	}
}
function fnValidateCategory(mode,Id,step){
	if(step == 2){
//		if(imageCk() == false){return false};
		fnValidateCategory(mode,Id,'submit')
		return false;
	}else if(step == 'submit'){
		//alert('submitting');
		window.scroll(0,vertStartPos);
		loading('controlPanel');

		fnSubmit('category',mode,Id);
		return false;		

//		document.thisForm.action=rootdomain+"RootControlpanel/phpScript.php?req=edit_categories.php&mode="+mode+"&CatId="+CatId;
//		document.thisForm.submit();

	}else{
		valueCk('category','Name',document.thisForm.Category.value,'CategoryWarning',Id,'fnValidateCategory','2',mode);
		return false;
	}
}

function fnValidateProduct(mode,Id,step){
	if(step == 2){
//		if(imageCk() == false){return false};
		
		var form = document.thisForm
		for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "text" && form.elements[i].value == "" && str.indexOf("PricingGroup") != "-1"){
		alert("Please fill out all pricing fields. ");
		form.elements[i].focus();
		return false;
		}
		}
		
//		if(notChecked(document.thisForm.elements["CategoryLink[]"],"Category or Categories associated with this product.")) {return false;}
		
		fnValidateProduct(mode,Id,'submit')
		return false;
	}else if(step == 'submit'){
		window.scroll(0,vertStartPos);
		loading('controlPanel');

		fnSubmit('product',mode,Id);
		return false;		

//		document.thisForm.action=rootdomain+"RootControlpanel/phpScript.php?req=edit_products.php&mode="+mode+"&ProductId="+Id;
//		document.thisForm.submit();
	}else{
		valueCk('product','ProductName',document.thisForm.ProductName.value,'ProductNameWarning',Id,'fnValidateProduct','2',mode);
		return false;
	}
}

function fnValidateCoupon(mode,Id,step){
	if(step == 1){
		valueCk('coupon','CouponCode',document.thisForm.CouponCode.value,'codeWarning',Id,'fnValidateCoupon','2',mode)
	}else if(step == 2){		
		if(document.thisForm.Discount.value == '' || Number(stripNonNumeric(document.thisForm.Discount.value )) <= 0){
			$('discountWarning').style.display = '';
			$('discountWarning').innerHTML = 'Insert the discount amount assigned to this coupon.';
			window.scroll(0,vertStartPos);
			return false;
		}		
		fnSubmit('coupon',mode,Id);
		return false;		
	}else{
		valueCk('coupon','Name',document.thisForm.Name.value,'nameWarning',Id,'fnValidateCoupon','1',mode);
		return false;
	}
}

function fnValidateUser(mode,Id,step){
	if(step == 2){
		if(document.thisForm.pswd && document.thisForm.pswd2 && (document.thisForm.pswd.value != '' || document.thisForm.pswd2.value != '') && testPassword() == false){return false;}		
		if(document.thisForm.pswd && document.thisForm.pswd2 && (document.thisForm.pswd.value != '' || document.thisForm.pswd2.value != '') && testPassword2() == false){return false;}		
		fnSubmit('user',mode,Id);
		return false;		
	}else if(step == 1){
		valueCk('user','email',document.thisForm.email.value,'emailWarning',Id,'fnValidateUser','2',mode)
		return false;		
	}else{
		if(valueCk('user','name',document.thisForm.name.value,'nameWarning',Id,'fnValidateUser','1',mode) == false){
			return false;
		}else{
			fnValidateUser(mode,Id,'1');	
			return false;
		}
	}
}

function fnSubmit(type,mode,id,itemType,itemName){ 
	if(!$('loadingDiv')){loading('controlPanel');}
	if(type != 'categoryManagement'){tinyMCE.triggerSave();} //saves tinyMCE value back to the textarea value
	var form = document.thisForm
	var chkSelect = '';
	var CategoryLink = '';
	var ProductLink = '';
	if(type == 'category'){
		var url=rootdomain+"RootControlpanel/phpScript.php?req=edit_categories.php&mode=" + mode + "&CatId=" + id;	
	}else if(type == 'product'){
		var url=rootdomain+"RootControlpanel/phpScript.php?req=edit_products.php&mode=" + mode + "&ProductId=" + id;
	}else if(type == 'coupon'){
		var url=rootdomain+"RootControlpanel/phpScript.php?req=edit_coupons.php&mode=" + mode + "&CouponId=" + id;
	}else if(type == 'user'){
		var url=rootdomain+"RootControlpanel/phpScript.php?req=edit_users.php&mode=" + mode + "&userId=" + id;
	}else if(type == 'categoryManagement' && itemType == 'category'){
//		if(action == 'delete' && $('CategoryType').value == 'Categories'){$('1_ckbox_'+itemid).checked = false;}
//		if(action == 'delete' && $('CategoryType').value == 'Products'){$('2_ckbox_'+itemid).checked = false;}
		if($('categoryTypeOrig').innerHTML != '' && $('categoryTypeOrig').innerHTML != $('CategoryType').value){
				if($('loadingDiv')){loading();}
				if(confirm('Are you sure you would like to change the page type from '+$('categoryTypeOrig').innerHTML+' to '+$('CategoryType').value+'?\nThis will clear the '+$('categoryTypeOrig').innerHTML+' you have saved for '+itemName+'.') == false){
				return;
			}else{
				if(!$('loadingDiv')){loading('controlPanel');}
			}
		}
		var url=rootdomain+"RootControlpanel/phpScript.php?req=categoryManagement.php&mode=" + mode + "&CatId=" + id;		
//		if(action == 'add' && $('CategoryType').value == 'Categories'){$('3_ckbox_'+itemid).checked = true;}
//		if(action == 'add' && $('CategoryType').value == 'Products'){$('4_ckbox_'+itemid).checked = true;}
		if(top.$('updateStatus')){top.$('updateStatus').innerHTML = 'update';}

	}else if(type == 'categoryManagement' && itemType == 'product'){
		if(!$('loadingDiv')){loading('controlPanel');}
		var url=rootdomain+"RootControlpanel/phpScript.php?req=categoryManagement.php&mode=" + mode + "&ProductId=" + id;
//		if(action == 'delete' ){$('1_ckbox_'+itemid).checked = false;}
//		if(action == 'add' ){$('3_ckbox_'+itemid).checked = true;}

		if(top.$('updateStatus')){top.$('updateStatus').innerHTML = 'update';}

	}

	for (i = 0; i < form.elements.length; i++) {
		var elName = form.elements[i].name;
		if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf("CategoryLink[]") != "-1"){
			if(CategoryLink != ''){
				CategoryLink = CategoryLink + ',' + form.elements[i].value;
			}else{
				CategoryLink = form.elements[i].value;
			}
		}else if(form.elements[i].type == 'checkbox' && !form.elements[i].checked && form.elements[i].name.indexOf("CategoryLink[]") != "-1"){
			//var elValue = 'No';	
		}else if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf("ProductLink[]") != "-1"){
			if(ProductLink != ''){
				ProductLink = ProductLink + ',' + form.elements[i].value;
			}else{
				ProductLink = form.elements[i].value;
			}
		}else if(form.elements[i].type == 'checkbox' && form.elements[i].name.indexOf("ProductLink[]") != "-1"){
			//var elValue = 'No';	
		}else if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf("newsletter") != "-1"){
			var elValue = form.elements[i].value;	
		}else if(form.elements[i].type == 'checkbox' && form.elements[i].name.indexOf("newsletter") != "-1"){
			var elValue = 'No';	
		}else if(form.elements[i].type == 'file' && form.elements[i].value != ''){
			var fileId = form.elements[i].id;	
		}else{
			var elValue = cleanValue(form.elements[i].value);		
		}
		if(elName!='Id'  && elName != "CategoryLink[]" && elName != "ProductLink[]" && elName != ''){url=url+"&"+elName+"="+elValue;}
	} //end for(
	
	
	if($('CategoryType') && $('CategoryType').value == "Categories"){ 
		var CategoryLinkArr = [];
		if(CategoryLink != ''){CategoryLinkArr[CategoryLinkArr.length] = CategoryLink;}
		if($('ck_category') && $('ck_category').innerHTML != ''){CategoryLinkArr[CategoryLinkArr.length] = $('ck_category').innerHTML;}
		url = url + "&CategoryLink=" + CategoryLinkArr.join(',');
	}else if($('CategoryType') && $('CategoryType').value == "Categories"){ 
		var ProductLinkArr = [];
		if(ProductLink != ''){ProductLinkArr[ProductLinkArr.length] = ProductLink;}
		if($('ck_product') && $('ck_product').innerHTML != ''){ProductLinkArr[ProductLinkArr.length] = $('ck_product').innerHTML;}
		url = url + "&ProductLink=" + ProductLinkArr.join(',');	
	}else{
		if(CategoryLink != ''){url = url + "&CategoryLink=" + CategoryLink;}
		if(ProductLink != ''){url = url + "&ProductLink=" + ProductLink;}
	}

	var iCnt = iCnt;
	url=url+"&sid="+Math.random();
//alert(url);
//return;
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){fnSubmitRsp(type,mode,id,itemType,fileId)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function fnSubmitRsp(type,mode,id,itemType,fileId){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			if(type == 'category'){
				loadPage(rootdomain+'RootControlpanel/view_category_details.php?CatId='+theGoods[1]+'&mode='+mode,'controlPanel','loadPage');
			}else if(type == 'product'){
				if(fileId && fileId != ''){
					fileUpload(theGoods[1],fileId);
					return;
				}else{
					loadPage(rootdomain+'RootControlpanel/view_product_details.php?ProductId='+theGoods[1]+'&mode='+mode,'controlPanel','loadPage');
				}
			}else if(type == 'coupon'){				
				loadPage(rootdomain+'RootControlpanel/view_coupon_details.php?CouponId='+theGoods[1]+'&mode='+mode,'controlPanel','loadPage');			
			}else if(type == 'user'){				
				loadPage(rootdomain+'RootControlpanel/view_user_details.php?userId='+theGoods[1]+'&mode='+mode,'controlPanel','loadPage');			
			}else if(type == 'categoryManagement'){
				warningPageShow('Updated Successfully');
				populateSmartSearch(type,id,'','',itemType);
				if($('loadingDiv')){loading();}

				if($('ck_category')){$('ck_category').parentNode.removeChild($('ck_category'));}
				if($('x_category')){$('x_category').parentNode.removeChild($('x_category'));}	
				if($('ck_product')){$('ck_product').parentNode.removeChild($('ck_product'));}	
				if($('x_product')){$('ck_product').parentNode.removeChild($('ck_product'));}					
				return;
			}

		}else{
			if(showErrors == 1){alert('Error:' + xmlHttp.responseText);}
		}
	}else{
//	alert('no: '+xmlHttp.readyState);	
	}
}

function statusUpdate(type,action){
var form = document.thisForm;
var numck = 0;
for (i = 0; i < form.elements.length; i++) {
var elName = form.elements[i].name;
if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name == 'chkSelect'){numck = 1;}
}
if(numck == 0){
alert("Select at least one "+ type +" to update.");
return false;
	}
if(type == 'Category'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=view_categories.php&mode=status&action="+action;
}else if(type == 'Product'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=view_products.php&mode=status&action="+action;
}else if(type == 'Coupon'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=view_coupons.php&mode=status&action="+action;
}else if(type == 'Order'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=view_orders.php&mode=status&action="+action;
}else if(type == 'User'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=view_users.php&mode=status&action="+action;
}
var form = document.thisForm
	var numSelected = 0;
	var elValue = '';
	for (i = 0; i < form.elements.length; i++) {	
		if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name == 'chkSelect'){
			var elName = form.elements[i].name;
			if(elValue != ''){
				elValue = elValue + '|' + form.elements[i].value;
			}else{
				elValue = form.elements[i].value;
			}
			
			numSelected += 1;
		}
	} //end for
url=url+"&"+elName+"="+elValue;


if(numSelected>1 && type == 'Category'){type = 'these Categories';
}else if(numSelected>1 && type == 'Product'){type = 'these Products';
}else if(numSelected>1 && type == 'Coupon'){type = 'these Coupons';
}else if(numSelected>1 && type == 'Order'){type = 'these Orders';
}else if(numSelected>1 && type == 'User'){type = 'these Users';
}else if(numSelected==1 && type == 'Category'){type = 'this Category';
}else if(numSelected==1 && type == 'Product'){type = 'this Product';
}else if(numSelected==1 && type == 'Coupon'){type = 'this Coupon';
}else if(numSelected==1 && type == 'Order'){type = 'this Order';
}else if(numSelected==1 && type == 'User'){type = 'this User';
}else{alert(numSelected + ' - ' + type);}

if(action == 'Deleted'){
	msg = "This will remove all information for "+ type +" from the database.\nAre you sure you would like to proceed?";
}else if(action == 'Inactive' || action == 'Active' || action == 'Success' || action == 'Failure' || action == 'Pending'){
	msg = "This will update the status for "+ type +".\nAre you sure you would like to proceed?";
}
//alert(url);
if(confirm(msg)){
	if(!$('loadingDiv')){loading('controlPanel');}
	url=url+"&sid="+Math.random();

	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){updateStatusRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	//alert(url);
}else{
	return false;
}

	}

function updateStatusRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		if($('loadingDiv')){loading();}
		//alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){	
			if(theGoods[1] == 'Category'){
				loadPage(rootdomain + 'RootControlpanel/view_categories.php?mode='+theGoods[2]+'&num='+theGoods[3],'controlPanel','loadPage');
			}else if(theGoods[1] == 'Product'){
				loadPage(rootdomain + 'RootControlpanel/view_products.php?mode='+theGoods[2]+'&num='+theGoods[3],'controlPanel','loadPage');
			}else if(theGoods[1] == 'Coupon'){
				loadPage(rootdomain + 'RootControlpanel/view_coupons.php?mode='+theGoods[2]+'&num='+theGoods[3],'controlPanel','loadPage');
			}else if(theGoods[1] == 'Order'){
				loadPage(rootdomain + 'RootControlpanel/view_orders.php?mode='+theGoods[2]+'&num='+theGoods[3],'controlPanel','loadPage');
			}else if(theGoods[1] == 'User'){
				loadPage(rootdomain + 'RootControlpanel/view_users.php?mode='+theGoods[2]+'&num='+theGoods[3],'controlPanel','loadPage');
			}
		}else{
			if(showErrors == 1){alert('Error: '+xmlHttp.responseText);}
		}
	}
}


function changeCategory(category,Sort){
	var url = rootdomain+'RootControlpanel/view_products.php?changeCategory='+category+'&sort='+Sort;
	loadPage(url,'controlPanel','loadPage');
}

//function keyPressTest(f) {
//var re = /^[0-9]*$/;
//if (!re.test(f.value)) {
//alert("Please enter a valid discount percentage.");
//f.value = f.value.replace(/[^0-9]/g,"");
//}
function keyPressTest(id,value){
	var val = stripNonNumeric(value);
	if(val.length == 0){
		alert("Please enter a valid number.");
		$(id).value='';
		document.thisForm.focus();
	}
}

function getPageCoords (element) {
var coords = { x: 0, y: 0};
while (element) {
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
return coords;
}

function showType(id){
	if ($('CategoryType').value == "Categories"){
		$('selectedCategoryTbl').style.display ="";
		$('categoryTbl').style.display ="";
		$('selectedProductTbl').style.display ="none";
		$('productTbl').style.display ="none";

		if($('searchDiv')){$('searchDiv').parentNode.removeChild($('searchDiv')); $('smartSearch').style.display = 'none';}
		if($('searchInputCategory')){smartSearch('categoryManagement',$('CatId').innerHTML,'category');}
	}else{		
		$('selectedCategoryTbl').style.display = "none";
		$('categoryTbl').style.display = "none";
		$('selectedProductTbl').style.display = "";
		$('productTbl').style.display = "";
		
		if($('searchDiv')){$('searchDiv').parentNode.removeChild($('searchDiv')); $('smartSearch').style.display = 'none';}
		if($('searchInputProduct')){smartSearch('categoryManagement',$('CatId').innerHTML,'category');}
	}
	if($('CategoryTypeSelect')){$('CategoryTypeSelect').style.display = "none"};
	$('contentTbl').style.display ="";
	$('searchIcon').style.display = "";
	populateSmartSearch('categoryManagement',id,'','','category');
	//window.scroll(0,coords.y);
//	resizePopBox();
}


function OptionOver(List,ItemNum,Option){
	var Item = $(List+'_item_'+ItemNum);
		Item.style.cursor = "pointer" ;
	if($(List+'_ckbox_'+ItemNum).checked){
		if(Option == "Out"){ 
			Item.style.backgroundColor = "#FFFFFF";
			Item.style.border = "none";
			Item.style.border = "1px solid #FFFFFF";
			Item.style.backgroundImage = "";
			Item.style.backgroundPosition = "";
			Item.style.backgroundRepeat = "";
			Item.style.backgroundImage = "";
			Item.style.backgroundPosition = "";
			Item.style.backgroundRepeat = "";
	}else{
			Item.style.backgroundColor = "#f1f1f1";
			Item.style.border = "1px solid #000000";
			if(document.getElementsByTagName('li').length > 1 && (List == 1 || List == 2)){
				Item.style.backgroundImage = "url("+rootdomain+"/RootImages/up_down.gif)";
				Item.style.backgroundPosition = "98%";
				Item.style.backgroundRepeat = "no-repeat";
			}
		}
	}else{
		if(Option == "Out"){ 
			Item.style.backgroundColor = "#FFFFFF";
			Item.style.border = "1px solid #FFFFFF";
			Item.style.backgroundImage = "";
			Item.style.backgroundPosition = "";
			Item.style.backgroundRepeat = "";
		}else{
			Item.style.backgroundColor = "#f1f1f1";
			Item.style.border = "1px solid #000000";
			if(document.getElementsByTagName('li').length > 1 && (List == 1 || List == 2)){
				Item.style.backgroundImage = "url("+rootdomain+"/RootImages/up_down.gif)";
				Item.style.backgroundPosition = "98%";
				Item.style.backgroundRepeat = "no-repeat";
			}
		}
	}
}

function selectItem(type,image,ckbox,id){
	if(!$('ck_'+type)){
		var div = document.createElement('div');
		div.id = 'ck_'+type;
		$('pageFooter').appendChild(div);
	}
	if(!$('x_'+type)){
		var div = document.createElement('div');
		div.id = 'x_'+type;
		$('pageFooter').appendChild(div);
	}

	if((ckbox.indexOf('1_ckbox_') != '-1' || ckbox.indexOf('2_ckbox_') != '-1') && $(ckbox).checked == true){
		$(ckbox).checked = false;
		$(image).src = rootdomain+'RootImages/x_box_small.png';
		if(ckbox.indexOf('selectAll') != -1){
			var inputs = document.getElementsByTagName('INPUT');
			for(var iCnt=0;iCnt<inputs.length;iCnt++){
				if(inputs[iCnt].type == 'checkbox'  && (inputs[iCnt].id.indexOf('1_ckbox_') != -1 ||  inputs[iCnt].id.indexOf('2_ckbox_') != -1)){
					if(ckbox.indexOf('1_ckbox_selectAll') != -1 && inputs[iCnt].name == 'CategoryLink[]'){
						inputs[iCnt].checked = false;
						$('removeBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/x_box_small.png';
	
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						if($('x_'+type).innerHTML != ''){
							$('x_'+type).innerHTML = $('x_'+type).innerHTML+','+sid;
						}else{
							$('x_'+type).innerHTML = sid;	
						}
					}else if(ckbox.indexOf('2_ckbox_selectAll') != -1 && inputs[iCnt].name == 'ProductLink[]'){
						inputs[iCnt].checked = false;
						$('removeBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/x_box_small.png';
	
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						if($('x_'+type).innerHTML != ''){
							$('x_'+type).innerHTML = $('x_'+type).innerHTML+','+sid;
						}else{
							$('x_'+type).innerHTML = sid;	
						}
					}
				}
			}	
		}else{
			if($('x_'+type).innerHTML != ''){
				$('x_'+type).innerHTML = $('x_'+type).innerHTML+','+id;
			}else{
				$('x_'+type).innerHTML = id;	
			}
		}

	}else if((ckbox.indexOf('1_ckbox_') != '-1' || ckbox.indexOf('2_ckbox_') != '-1') && $(ckbox).checked == false){
		$(ckbox).checked = true;
		$(image).src = rootdomain+'RootImages/box_small_2.png';

		if(ckbox.indexOf('selectAll') != -1){
			var inputs = document.getElementsByTagName('INPUT');
			for(var iCnt=0;iCnt<inputs.length;iCnt++){
				if(inputs[iCnt].type == 'checkbox' && (inputs[iCnt].id.indexOf('1_ckbox_') != -1 ||  inputs[iCnt].id.indexOf('2_ckbox_') != -1)){
					if(ckbox.indexOf('1_ckbox_selectAll') != -1 && inputs[iCnt].name == 'CategoryLink[]'){
						inputs[iCnt].checked = true;
						$('removeBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_small_2.png';
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						var values = $('x_'+type).innerHTML.split(',');
						var newValues = new Array();
						for(i=0;i<values.length;i++){if(values[i] != sid){newValues[newValues.length] = values[i];}}
						$('x_'+type).innerHTML = newValues.join(',');
					}else if(ckbox.indexOf('2_ckbox_selectAll') != -1 && inputs[iCnt].name == 'ProductLink[]'){
						inputs[iCnt].checked = true;
						$('removeBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_small_2.png';
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						var values = $('x_'+type).innerHTML.split(',');
						var newValues = new Array();
						for(i=0;i<values.length;i++){if(values[i] != sid){newValues[newValues.length] = values[i];}}
						$('x_'+type).innerHTML = newValues.join(',');
					}
				}
			}	
		}else{
			var values = $('x_'+type).innerHTML.split(',');
			var newValues = new Array();
			for(i=0;i<values.length;i++){if(values[i] != id){newValues[newValues.length] = values[i];}}
			$('x_'+type).innerHTML = newValues.join(',');
		}

	}else if((ckbox.indexOf('3_ckbox_') != '-1' || ckbox.indexOf('4_ckbox_') != '-1') && $(ckbox).checked == true){
		$(ckbox).checked = false;
		$(image).src = rootdomain+'RootImages/box_small.png';

		if(ckbox.indexOf('selectAll') != -1){
			var inputs = document.getElementsByTagName('INPUT');
			for(var iCnt=0;iCnt<inputs.length;iCnt++){
				if(inputs[iCnt].type == 'checkbox' && (inputs[iCnt].id.indexOf('3_ckbox_') != -1 ||  inputs[iCnt].id.indexOf('4_ckbox_') != -1)){
					if(ckbox.indexOf('3_ckbox_selectAll') != -1 && inputs[iCnt].name == 'CategoryLink[]'){
						inputs[iCnt].checked = false;
						$('addBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_small.png';
	
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						var values = $('ck_'+type).innerHTML.split(',');
						var newValues = new Array();
						
						for(i=0;i<values.length;i++){if(values[i] != sid){newValues[newValues.length] = values[i];}}
						$('ck_'+type).innerHTML = newValues.join(',');
					}else if(ckbox.indexOf('4_ckbox_selectAll') != -1 && inputs[iCnt].name == 'ProductLink[]'){
						inputs[iCnt].checked = false;
						$('addBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_small.png';
	
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						var values = $('ck_'+type).innerHTML.split(',');
						var newValues = new Array();
						
						for(i=0;i<values.length;i++){if(values[i] != sid){newValues[newValues.length] = values[i];}}
						$('ck_'+type).innerHTML = newValues.join(',');
					}
				}
			}	
		}else{
			var values = $('ck_'+type).innerHTML.split(',');
			var newValues = new Array();
			for(i=0;i<values.length;i++){if(values[i] != id){newValues[newValues.length] = values[i];}}
			$('ck_'+type).innerHTML = newValues.join(',');
		}
	}else if((ckbox.indexOf('3_ckbox_') != '-1' || ckbox.indexOf('4_ckbox_') != '-1') && $(ckbox).checked == false){
		$(ckbox).checked = true;
		$(image).src = rootdomain+'RootImages/box_ck.png';

		if(ckbox.indexOf('selectAll') != -1){
			var inputs = document.getElementsByTagName('INPUT');
			for(var iCnt=0;iCnt<inputs.length;iCnt++){
				if(inputs[iCnt].type == 'checkbox' && (inputs[iCnt].id.indexOf('3_ckbox_') != -1 ||  inputs[iCnt].id.indexOf('4_ckbox_') != -1)){
					if(ckbox.indexOf('3_ckbox_selectAll') != -1 && inputs[iCnt].name == 'CategoryLink[]'){
						inputs[iCnt].checked = true;
						$('addBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_ck.png';
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						if($('ck_'+type).innerHTML != ''){
							$('ck_'+type).innerHTML = $('ck_'+type).innerHTML+','+sid;
						}else{
							$('ck_'+type).innerHTML = sid;	
						}
					}else if(ckbox.indexOf('4_ckbox_selectAll') != -1 && inputs[iCnt].name == 'ProductLink[]'){
						inputs[iCnt].checked = true;
						$('addBox_'+inputs[iCnt].value).src = rootdomain+'RootImages/box_ck.png';
						var sid = id.replace(/selectAll/,inputs[iCnt].value);
						if($('ck_'+type).innerHTML != ''){
							$('ck_'+type).innerHTML = $('ck_'+type).innerHTML+','+sid;
						}else{
							$('ck_'+type).innerHTML = sid;	
						}					
					}
				}
			}	
		}else{			
			if($('ck_'+type).innerHTML != ''){
				$('ck_'+type).innerHTML = $('ck_'+type).innerHTML+','+id;
			}else{
				$('ck_'+type).innerHTML = id;	
			}
		}
	}	
}

function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  // submit
  frm.submit();
}


function validateRow(frm)
{
  var chkb = $('chkValidate');
  if (chkb.checked) {
    var tbl = $('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = $('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('Row ' + i + ' is empty');
        return;
      }
    }
  }
  openInNewWindow(frm);
}


function price(){
	if($('priceinfo').style.display=="block"){
	$('priceinfo').style.display='none';
	$('but').style.display='none';	
	}
	else{
	$('priceinfo').style.display='block';
	$('but').style.display='block';
	}
}

function deadline(){
	if($('deadline').style.display=="block"){
	$('deadline').style.display='none';
	$('customdeadline').style.display='block';
	}else{
	$('deadline').style.display='block';
	$('customdeadline').style.display='none';
}
	}


function delp()
	{
		if(confirm("Are you sure you would like to delete this Product?"))
		{
			document.delForm.action="view_products.php?mode=del"
			document.delForm.submit();
		}
		else
		{
				return false;
		}
	}


function listall()
{
    var tag, tags;
    tags = "The tags in the page are:"
    for(i = 0; i < document.all.length; i++)
    {
        tag = document.all(i).tagName + '<br>';
        tags = tags + "\r" + tag;
    }
    document.write(tags);
}

function showProducts(){
	if ($('Type').value =="Products"){
		$('Product1').style.display ="";
		$('Product2').style.display ="";
		$('Product3').style.display ="";
		$('Product4').style.display ="";
		$('Product5').style.display ="";
		$('Product6').style.display ="";
		$('Product7').style.display ="";								
	}else{
		$('Product1').style.display ="none";
		$('Product2').style.display ="none";
		$('Product3').style.display ="none";
		$('Product4').style.display ="none";
		$('Product5').style.display ="none";
		$('Product6').style.display ="none";
		$('Product7').style.display ="none";								
	}
}

function stripNonNumeric(str,id)
{
  str += '';
  var rgx = /^\d|\.|-$/;
   var out = '';
   for( var i = 0; i < str.length; i++ )
   {
     if( rgx.test( str.charAt(i) ) ){
       if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
              ( str.charAt(i) == '-' && out.length != 0 ) ) ){
         out += str.charAt(i);
       }
     }
   }
   if(id != '' && $(id)){
	   $(id).value = out;
	   return;
   }else{
	  return out;
   }
}
				
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function ParsedQueryString() {
	this._init();
}

ParsedQueryString.version = '1.0';

ParsedQueryString.prototype =
{
	_init:
		function ()
		{
			this._parameters = {};

			if (location.search.length <= 1)
return;
var pairs = location.search.substr(1).split(/[&;]/);

			for (var i = 0; i < pairs.length; i++)
			{
				var pair = pairs[i].split(/=/);
				var name = this._decodeURL(pair[0]);
				
				if (Boolean(pair[1]))
				{
					var value = this._decodeURL(pair[1]);
					if (Boolean(this._parameters[name]))
						this._parameters[name].push(value);
					else
						this._parameters[name] = [value];
				}
			}
		},

	_decodeURL:
		function (url) {
			return decodeURIComponent(url.replace(/\+/g, " "));
		},

	param:
		function (name)
		{
			if (Boolean(this._parameters[name]))
				return this._parameters[name][0];
			else
				return "";
		},

	params:
		function (name)
		{
			if (Boolean(name))
			{
				if (Boolean(this._parameters[name]))
				{
					var values = [];
					for (var i = 0; i < this._parameters[name].length; i++)
						values.push(this._parameters[name][i]);
					return values;
				}
				else
					return [];
			}
			else
			{
				var names = [];
				for (var name in this._parameters)
					names.push(name);
				return names;
			}
		}
};
function clearValue(id,origValue){
	if($('loginWarning')){
		$('loginWarning').style.innerHTML = '';
		$('loginWarning').style.display = 'none';
	}
	//alert('1. '+$(id).value+'\n2. '+origValue+'\n3. '+$(id).className);
	if($(id).value == origValue){$(id).value = '';}
	return;
}
function ifEmpty(id,origValue){
	if($(id) && $(id).value == ''){$(id).value = origValue;}
	return;
}
function emailRequest(type){
	$('loginWarning').style.innerHTML = '';
	$('loginWarning').style.display = 'none';

	if(type == 'show'){
		$('pswd').style.display = 'none';
		$('emailRequestShow').style.display = 'none';		
		$('emailRequestHide').style.display = '';				
		$('onLoadLogin').style.left = '160px';
		$('email').style.left = '160px';
		$('loginWarning').style.left = '160px';
		$('loginSubmitTxt').innerHTML = 'Send Email';
	}else{
		$('pswd').style.display = '';	
		$('emailRequestShow').style.display = '';		
		$('emailRequestHide').style.display = 'none';				
		$('onLoadLogin').style.left = '0px';
		$('email').style.left = '0px';		
		$('loginWarning').style.left = '0px';		
		$('loginSubmitTxt').innerHTML = 'Login';
	}
//$('divLogin').removeChild($('pswd'));

}

function shipCountryDropDown(){
	if(document.thisForm.country.value=="United States of America"){
		$('ShipUsaStates').style.display = '';
		$('ShipCanadaStates').style.display = 'none';
	}else{
		$('ShipUsaStates').style.display = 'none';
		$('ShipCanadaStates').style.display = '';
	}
}

function TabNext(obj,event,len,nextField) {
	phone_field_length=1;
    if (event == "down") {
           phone_field_length=obj.value.length;
   }else if (event == "up") {
          if (obj.value.length != phone_field_length) {
                phone_field_length=obj.value.length;
                if (phone_field_length == len) {
                $(nextField).focus();
                }
          }
    }
}

function testPassword(){
	if(document.thisForm.pswd.value.length < 6){
		$('pswdWarning').style.display='';
		window.scroll(0,0);
		return false;
	}
}

function testPassword2(){
	if(document.thisForm.pswd.value != document.thisForm.pswd2.value){
		$('pswdWarning2').style.display='';
		//document.thisForm.pswd2.focus(); 
		window.scroll(0,0);
		return false;
	}else{
		$('pswdWarning2').style.display='none';	
	}
}

function showUpdatePswd(arg){
	if(arg == 1){
			$('updatePswd1').style.display = '';
			$('updatePswd2').style.display = '';
	}else{
			$('updatePswd1').style.display = 'none';
			$('updatePswd2').style.display = 'none';
			document.thisForm.pswd.value = '';
			document.thisForm.pswd2.value = '';		
			$('pswdWarning').style.display='none';
			$('pswdWarning2').style.display='none';			
	}
}

function showBckGroundDim(){
	var bckGroundDim = document.createElement('div');
	bckGroundDim.className = 'bckGroundDim';
	bckGroundDim.id = 'bckGroundDim';
	$('pageFooter').appendChild(bckGroundDim);
}

function popBox(type,id,name,mode,width,height,left,top){
	showBckGroundDim();
	var pageFooter = $('pageFooter');
	var bckGroundDim = $('bckGroundDim');
	var popBox = document.createElement('div');	
	popBox.className = 'popBox';
	if(width && width != ''){popBox.style.width = width + '%';}
	if(height && height != ''){popBox.style.height = height + '%';}
	if(left && left != ''){popBox.style.left = left + '%';}
	if(top && top != ''){popBox.style.top = top + '%';}	
	popBox.id = 'popBox';
	pageFooter.appendChild(popBox);

	var updateStatus = document.createElement('div');	
	updateStatus.id = 'updateStatus';
	updateStatus.style.display = 'none';
	popBox.appendChild(updateStatus);

	if(mode == 'upload'){
		var updateStatus = 'upload';
	}else{
		var updateStatus = $('updateStatus').innerHTML;
	}

	var xBox = document.createElement('div');	
	xBox.className = 'xBox';
	xBox.innerHTML = 'X';
	xBox.style.cursor = 'pointer';
	xBox.id = 'xBoxId'
	xBox.onclick = function (){return popBoxRemove(type,id,$('updateStatus').innerHTML,mode);};
	if(left && left != ''){var xLeft = Number(left) + 39; xBox.style.left = xLeft + '%';}
	if(top && top != ''){var xTop = Number(top) + 3; xBox.style.top = xTop + '%';}	
	popBox.appendChild(xBox);

	var popBoxContent = document.createElement('div');	
	popBoxContent.style.height = '100%';
	popBox.appendChild(popBoxContent);
/*
	var iframe = document.createElement('1');
	if(mode == 'imageManagement' && type == 'category'){
		iframe.src = rootdomain+'RootControlpanel/imageManagement.php?type='+type+'&CatId='+id+'&mode='+mode;
	}else if(mode == 'imageManagement' && type == 'product'){
		iframe.src = rootdomain+'RootControlpanel/imageManagement.php?type='+type+'&ProductId='+id+'&mode='+mode;		
	}else if(mode == 'categoryManagement' && type == 'category'){
		iframe.src = rootdomain+'RootControlpanel/categoryManagement.php?type='+type+'&CatId='+id+'&mode='+mode;
	}else if(mode == 'categoryManagement' && type == 'product'){
		iframe.src = rootdomain+'RootControlpanel/categoryManagement.php?type='+type+'&ProductId='+id+'&mode='+mode;
	}else if(mode == 'upload'){
		iframe.src = rootdomain+'RootControlpanel/uploadManagement.php?type='+type+'&mode='+mode;
	}else if(mode == 'download'){
		iframe.src = rootdomain+'RootControlpanel/downloadManagement.php?type='+type+'&mode='+mode;
	}else if(mode == 'style'){
		iframe.src = rootdomain+'RootControlpanel/styleManagement.php?type='+type+'&ProductId='+id+'&mode='+mode;
	}
*/

	var iframe = document.createElement('iframe');
	if(mode == 'imageManagement' && type == 'category'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=imageManagement.php&type='+type+'&CatId='+id+'&mode='+mode;
	}else if(mode == 'imageManagement' && type == 'product'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=imageManagement.php&type='+type+'&ProductId='+id+'&mode='+mode;		
	}else if(mode == 'categoryManagement' && type == 'category'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=categoryManagement.php&type='+type+'&CatId='+id+'&mode='+mode;
	}else if(mode == 'categoryManagement' && type == 'product'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=categoryManagement.php&type='+type+'&ProductId='+id+'&mode='+mode;
	}else if(mode == 'upload'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=uploadManagement.php&type='+type+'&mode='+mode;
	}else if(mode == 'download'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=downloadManagement.php&type='+type+'&mode='+mode;
	}else if(mode == 'style'){
		iframe.src = rootdomain+'RootControlpanel/popBox.php?req=styleManagement.php&type='+type+'&PricingGroupId='+id+'&mode='+mode;
	}
	iframe.frameBorder = '0';
	//iframe.style.border = 'dashed 2px black';
	iframe.scrolling = 'no';
	iframe.width = '100%';	
	iframe.id = "iframe";	
	iframe.className = "iframe";
	popBoxContent.appendChild(iframe);
}

function iframeHeight(){
	if($('pB') && $('pBC')){
		var wndo2 = new dw_scrollObj('pB', 'pBC');
	}
	if($('pB1') && $('pBC1')){
		var wndo2 = new dw_scrollObj('pB1', 'pBC1');
	}
	if($('pB2') && $('pBC2')){
		var wndo2 = new dw_scrollObj('pB2', 'pBC2');
	}
	if($('pB3') && $('pBC3')){
		var wndo2 = new dw_scrollObj('pB3', 'pBC3');
	}
	if($('pB4') && $('pBC4')){
		var wndo2 = new dw_scrollObj('pB4', 'pBC4');
	}
	applyTableDnD();
}
function resizePopBox(){
	if($('titleHeight')){
		var titleHeight = $('titleHeight').offsetHeight;
	}else{
		var titleHeight = 0;
	}
	var pBheight = Number(top.$('iframe').offsetHeight) - Number(titleHeight) - 15;
	var pBwidth = Number(top.$('iframe').offsetWidth) - 25;	
	var pBtop = Number(titleHeight) + 10;
	var navArrowsHeight = Number(top.$('iframe').offsetHeight) - 70;
	var navArrowsWidth = Number(top.$('iframe').offsetWidth) - 15;	
	
	if($('pB')){
		$('pB').style.height = (Number(pBheight) - 10) +'px';

		if($('pBC').offsetHeight > $('pB').offsetHeight){
			$('pB').style.width = (Number(pBwidth)) +'px';	
			$('navArrows').style.display = '';
			$('navArrows').style.top = navArrowsHeight +'px';
			$('navArrows').style.left = navArrowsWidth +'px';
		}else{
			$('pB').style.width = (Number(pBwidth) ) +'px';		
			$('navArrows').style.display = 'none';
		}
	}
	if($('leftColumn')){
		$('leftColumn').style.height = pBheight +'px';
		$('leftColumn').style.width = ((.5 * Number(pBwidth)) + 5) +'px';	
		$('leftColumn').style.left = 0 +'px';	
		$('leftColumn').style.top = pBtop +'px';			
	}
	if($('rightColumn')){
		$('rightColumn').style.height = pBheight +'px';
		$('rightColumn').style.width = ((.5 * Number(pBwidth)) + 8) +'px';	
		$('rightColumn').style.left = ((.5 * Number(pBwidth)) + 15) +'px';			
		$('rightColumn').style.top = pBtop +'px';					
	}

	if($('pB1')){
		var pBcontentWidth = ((.5 * Number(pBwidth)) - 6);		
		var pBcontentHeight = (Number(pBheight) - 100)
		$('pB1').style.height = pBcontentHeight +'px';
		if($('pageTypeTbl').style.display == ''){
			$('pB1').style.top = (Number(pBtop) - 22) +'px';	
		}else{
			$('pB1').style.top = (Number(pBtop) + 15) +'px';			
		}
		$('pB1').style.left = 4 +'px';			

		if($('pBC1').offsetHeight > $('pB1').offsetHeight){
			$('pB1').style.width =  (Number(pBcontentWidth) - 25) + 'px';			
			$('navArrows1').style.display = '';
			$('navArrows1').style.bottom = 10 +'px';
			$('navArrows1').style.left = (Number($('pB1').offsetWidth) + 10) +'px';
		}else{
			$('pB1').style.width =  (Number(pBcontentWidth) - 0) + 'px';						
			$('navArrows1').style.display = 'none';
		}	
	}
	
	if($('pB2')){
		var pBcontentWidth = ((.5 * Number(pBwidth)) - 6);		
		var pBcontentHeight = (Number(pBheight) - 100)
		$('pB2').style.height = pBcontentHeight +'px';
		$('pB2').style.top = (Number(pBtop) - 22) +'px';	
		$('pB2').style.left = 4 +'px';			

		if($('pBC2').offsetHeight > $('pB2').offsetHeight){
			$('pB2').style.width =  (Number(pBcontentWidth) - 25) + 'px';			
			$('navArrows2').style.display = '';
			$('navArrows2').style.bottom = 10 +'px';
			$('navArrows2').style.left = (Number($('pB2').offsetWidth) + 10) +'px';
		}else{
			$('pB2').style.width =  (Number(pBcontentWidth) - 0) + 'px';						
			$('navArrows2').style.display = 'none';
		}
	}

	if($('pB3')){
		var pBcontentWidth = ((.5 * Number(pBwidth)) - 6);		
		var pBcontentHeight = (Number(pBheight) - 100)

		if($('smartSearch').style.display == ''){
			$('pB3').style.height = (Number(pBcontentHeight) - Number($('smartSearch').offsetHeight)) +'px';
			if($('pageTypeTbl').style.display == ''){
				$('pB3').style.top = (Number(pBtop) - 22 + Number($('smartSearch').offsetHeight)) +'px';	
			}else{
				$('pB3').style.top = (Number(pBtop) + 22 + Number($('smartSearch').offsetHeight)) +'px';			
			}		
		}else{
			$('pB3').style.height = pBcontentHeight +'px';
			if($('pageTypeTbl').style.display == ''){
				$('pB3').style.top = (Number(pBtop) - 22) +'px';	
			}else{
				$('pB3').style.top = (Number(pBtop) + 15) +'px';			
			}
		}
		$('pB3').style.left = 4 +'px';			
		
		if($('pBC3').offsetHeight > $('pB3').offsetHeight){
			$('pB3').style.width =  (Number(pBcontentWidth) - 25) + 'px';			
			$('navArrows3').style.display = '';
			$('navArrows3').style.bottom = 10 +'px';
			$('navArrows3').style.left = (Number($('pB3').offsetWidth) + 10) +'px';
		}else{
			$('pB3').style.width =  (Number(pBcontentWidth) - 0) + 'px';
			$('navArrows3').style.display = 'none';
		}
	}

	if($('pB4')){
		var pBcontentWidth = ((.5 * Number(pBwidth)) - 6);		
		var pBcontentHeight = (Number(pBheight) - 100);
		
		if($('smartSearch').style.display == ''){
			//alert($('searchDiv').offsetHeight+'\n'+$('pB3').style.height);
			if($('advancedSearchDiv')){
				$('pB4').style.height = (Number(pBcontentHeight) - Number($('smartSearch').offsetHeight) - 22) +'px';
				$('pB4').style.top = (Number(pBtop)  - 10 + Number($('searchDiv').offsetHeight)) +'px';					
			}else{
				$('pB4').style.height = (Number(pBcontentHeight) - Number($('searchDiv').offsetHeight) - 5)  +'px';
				$('pB4').style.top = (Number(pBtop)  - 22 + Number($('searchDiv').offsetHeight)) +'px';		
			}
		}else{
			$('pB4').style.height = pBcontentHeight +'px';
			$('pB4').style.top = (Number(pBtop) - 22 + Number($('smartSearch').offsetHeight)) +'px';
		}
		$('pB4').style.left = 4 +'px';			
		
		if($('pBC4').offsetHeight > $('pB4').offsetHeight){
			$('pB4').style.width =  (Number(pBcontentWidth) - 25) + 'px';			
			$('navArrows4').style.display = '';
			$('navArrows4').style.bottom = 10 +'px';
			$('navArrows4').style.left = (Number($('pB4').offsetWidth) + 10) +'px';
		}else{
			$('pB4').style.width =  (Number(pBcontentWidth) - 0) + 'px';
			$('navArrows4').style.display = 'none';
		}
	}

	if($('contentTable')){
		$('contentTable').style.height = pBheight +'px';
		$('contentTable').style.width = pBwidth +'px';	
	}
	iframeHeight();
}

function popBoxRemove(type,id,status,mode){
	//alert('type: '+type);
	var pageFooter = top.$('pageFooter');	
	var bckGroundDim = top.$('bckGroundDim');		
	var popBox = top.$('popBox');
	if(type == 'category' && mode == 'upload'){
		loadPage(rootdomain+'RootControlpanel/view_categories.php?mode='+status,'controlPanel','loadPage','top');		
	}else if(type == 'product' && mode == 'upload'){
		loadPage(rootdomain+'RootControlpanel/view_products.php?mode='+status,'controlPanel','loadPage','top');		
	}else if(type == 'product' && mode == 'download'){
		loadPage(rootdomain+'RootControlpanel/view_products.php?mode='+status,'controlPanel','loadPage','top');		
	}else if(type == 'category'){
		if(status == 'update'){var functionName = "warningPageShow('Updated Successfully');";}else{var functionName = "loadPage";}
		loadPage(rootdomain+'RootControlpanel/view_category_details.php?CatId='+id+'&mode='+status,'controlPanel',functionName,'top');
	}else if(type == 'product'){
		loadPage(rootdomain+'RootControlpanel/view_product_details.php?ProductId='+id,'controlPanel','loadPage','top');
	}else if(type == 'editChars'){
		if(status == 'saved'){var functionName = "warningPageShow('Updated Successfully');";}else{var functionName = 'loadPage';}
		loadPage(rootdomain+'RootControlpanel/view_styles.php?type=defaults','controlPanel',functionName,'top');
	}
	pageFooter.removeChild(popBox);
	pageFooter.removeChild(bckGroundDim);
}

function fileUpload(id,fileUploadNames){
	var thisForm = document.thisForm;
	var fileUploadArr = fileUploadNames.split(',');
	
	for(i=0;i<fileUploadArr.length;i++){
		if(!checkExt('fileUpload',$(fileUploadArr[i]).value,fileUploadArr[i])){return false;}
	}
		var UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random())
		thisForm.action = cgi+"upload.cgi?upload_id="+UID;

		if(thisForm.popup && thisForm.popup.checked == true){
			var uploadProgress = $('uploadProgress');
			var iframeProgress = document.createElement('iframe');
			iframeProgress.style.backgroundColor = '#f1f1f1';
			
			iframeProgress.src = thisForm.action.split('upload.cgi')[0]+'upload_status.cgi?upload_id='+UID;
			iframeProgress.frameBorder = '0';
			iframeProgress.scrolling = 'no';
			iframeProgress.width = '100%';	
			iframeProgress.id="iframeProgress";

//alert('action: '+thisForm.action+'\n progress:'+iframeProgress.src);
//	return;
			uploadProgress.appendChild(iframeProgress);
			iframeHeight();
	//		win1 = window.open(thisForm.action.split('upload.cgi')[0]+'upload_status.cgi?upload_id='+UID,'win1','width=320,height=240,resizable=1');
	//		win1.window.focus();
	
		}

	thisForm.submit();
    return true;
}

function StartUpload(type,id,mode){
	var f1 = document.thisForm;
	if(mode == 'xls'){
		for (i=0; i<f1.elements.length; i++){
			if(f1.elements[i].type == 'radio' && f1.elements[i].checked && f1.elements[i].name.indexOf("uploadAction") != "-1"){
				var uploadAction = f1.elements[i].value;
			}
		}
	}

	if(type == 'category'){	
		var typeName = 'categories';
	}else if(type == 'product'){
		var typeName = 'products';
	}else if(type == 'product' && $('uploadSelectAction') && $('uploadSelectAction').value == 'Groups'){
		var typeName = 'Product Characteristics';
		var type = "group";
	}else if(type == 'product' && $('uploadSelectAction') && $('uploadSelectAction').value == 'Options'){
		var typeName = 'Options for Product Characteristics';
		var type = "option";
	}else if(type == 'product' && $('uploadSelectAction') && $('uploadSelectAction').value == 'Direct'){
		var typeName = 'Options for Direct Upload';
		var type = "direct";		
	}
	
    if(f1.fileUpload.value == "" && mode == 'image'){
		if(type == 'category'){
			f1.action=rootdomain+"RootControlpanel/phpScript.php?req=imageManagement.php&fileUpload=&CatId="+id;
		}else if(type == 'product'){
			f1.action=rootdomain+"RootControlpanel/phpScript.php?req=imageManagement.php&fileUpload=&ProductId="+id;		
		}
		f1.target='_self';
	}else if(f1.fileUpload.value == "" && mode == 'xls'){
		$('uploadWarning').innerHTML = '';
	    $('uploadWarning').style.display = 'none';
		$('uploadWarning').style.display = '';
		$('uploadWarning').innerHTML = "Be sure to select a file to upload.";
		resizePopBox();
		return false;
	}else if(!uploadAction && mode == 'xls'){
		$('uploadWarning').innerHTML = '';
	    $('uploadWarning').style.display = 'none';
		$('uploadWarning').style.display = '';
		$('uploadWarning').innerHTML = "What would you like to do with the uploaded "+typeName+"?";
		resizePopBox();
		return false;

	}else{
		f1.action= cgi+"upload.cgi?upload_id=";
		var UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
		f1.action = f1.action.split('?')[0]+'?upload_id='+UID;
		if(!checkExt(mode,f1.fileUpload.value))return false;
		if(f1.popup.checked){
		var uploadProgress = $('uploadProgress');
		var iframeProgress = document.createElement('iframe');
		iframeProgress.style.backgroundColor = '#f1f1f1';
		iframeProgress.src = f1.action.split('upload.cgi')[0]+'upload_status.cgi?upload_id='+UID;
		iframeProgress.frameBorder = '0';
		iframeProgress.scrolling = 'no';
		iframeProgress.width = '100%';	
		iframeProgress.id="iframeProgress";

//	alert('action: '+thisForm.action+'\n progress:'+iframeProgress.src);
//	return;

		uploadProgress.appendChild(iframeProgress);
		resizePopBox();
//		win1 = window.open(f1.action.split('upload.cgi')[0]+'upload_status.cgi?upload_id='+UID,'win1','width=320,height=240,resizable=1');
//		win1.window.focus();
		}

	}
	f1.submit();
    return true;
}


function checkExt(type,value,fileUpload){
	if(type == 'xls'){
		var name = 'uploadWarning';
		var exts = "txt|xls";
		//var exts = ".*"; //Use this to accept all Extensions
	}else if(type == 'image'){
		var name = 'imageWarning';	
		var exts = "jpeg|jpg|gif";
		//var exts = ".*"; //Use this to accept all Extensions
	}else if(type == 'fileUpload'){ //dasco SpecFile
		var fileVal = value.split('\\');
		var value = fileVal[fileVal.length-1];
		var exts = "pdf";
		var warning = fileUpload+'Warning';
		
		$(warning).innerHTML = '';
		$(warning).style.display = 'none';
		if(value == "")return true;
		var re = new RegExp("^.+\.("+exts+")$","i");
		if($('loadingDiv')){$('loadingDiv').parentNode.removeChild($('loadingDiv'));}    
		if(!re.test(value)){
			var extVal = value.split('.');
			var value = extVal[extVal.length-1];
			
			$(warning).style.display = '';
			$(warning).innerHTML = "."+ value + " is not an allowed extension (."+exts.replace(/\|/g,', .')+")";
			iframeHeight();
			return false;
		}
		return true;
	}
	
	$(name).innerHTML = '';
	 $(name).style.display = 'none';
    if(value=="")return true;
    var re = new RegExp("^.+\.("+exts+")$","i");
    if(!re.test(value))
    {
        $(name).style.display = '';
		$(name).innerHTML = "."+ value + " is not an allowed extension (."+exts.replace(/\|/g,', .')+")";
		resizePopBox();
        return false;
    }
    return true;
}

function addImage(){
if($('addImageRow').style.display=='none'){
	$('addImageRow').style.display='';
	$('addImage').style.display='none';	
	$('addImageCancel').style.display='';		
	$('printImages').style.height = '363px';
	resizePopBox();
}else{
	$('addImageRow').style.display='none';
	$('addImage').style.display='';	
	$('addImageCancel').style.display='none';		
	document.thisForm.fileUpload.value = '';
	$('printImages').style.height = '465px';	
	resizePopBox();
}
}
function categoryUpdate(type,id){
	if(type == 'category'){
		
	}	
}

function cancelAdd(type){
	if(type == 'category' && $('lastPage').innerHTML != $('lastPage2').innerHTML){
		loadPage($('lastPage2').innerHTML,'controlPanel','loadPage');
	}else if(type == 'category' && $('lastPage').innerHTML == $('lastPage2').innerHTML){
		loadPage(rootdomain+'RootControlpanel/view_categories.php','controlPanel','loadPage');
	}else if(type == 'product' && $('lastPage').innerHTML != $('lastPage2').innerHTML){
		loadPage($('lastPage2').innerHTML,'controlPanel','loadPage');
	}else if(type == 'product' && $('lastPage').innerHTML == $('lastPage2').innerHTML){		
		loadPage(rootdomain+'RootControlpanel/view_products.php','controlPanel','loadPage');
	}
}

function searchMenuButton(){
	if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == 'none'){
		smartSearch('product','')
	}else{
		resetPage();
	}
}

function smartSearch(type,id,itemType,noSearchOn){
//	if(type == 'categoryManagement'){
		if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == ''){
			//$('smartSearchFrontEnd').style.display = 'none';
			return;
		}else if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == 'none'){
			$('smartSearchFrontEnd').style.display = '';
			productFeatures(id,1);
			if($('searchInput')){return;}
		}
		
		//if(noSearchOn != 'noSearchOn'){searchOn();}
		
		if(!$('searchInput')){
			if($('smartSearchDiv')){$('smartSearchDiv').style.display = '';}
			$('smartSearch').style.display = '';
			
			if(type != 'category' && type != 'product'){		
				$('smartSearch').style.height = '40px';
				$('smartSearch').style.paddingTop = '8px'; 
				$('smartSearch').style.paddingBottom = '8px';
	//			$('smartSearch').style.width = '100%'; 
	//			$('smartSearch').style.backgroundColor = '#f1f1f1'; 
				$('smartSearch').style.borderStyle = 'solid'; 
				$('smartSearch').style.borderWidth = '0px'; 
				$('smartSearch').style.borderColor = '#B5B5B5';
				if($('categoryTbl')){$('categoryTbl').style.height = '70%';}
				if($('productTbl')){$('productTbl').style.height = '70%';}			
			}
//			var row = tbl.insertRow(4);
//			row.className='tblBody';
//			row.id = 'smartSearch';
//	
//			var cell = row.insertCell(0);
//			cell.colSpan = '2';


			var searchDiv = document.createElement('div');
			searchDiv.id = 'searchDiv';
			searchDiv.style.border = '0px dashed black';
			if(type != 'category' && type != 'product'){
				searchDiv.className = 'searchDiv';		
			}else{
				searchDiv.style.width = '99%';
			}
			$('smartSearch').appendChild(searchDiv);			
			
			var title = document.createElement('div');
			title.innerHTML = 'Search';
			title.className = 'smartSearchTitle';
			searchDiv.appendChild(title);			
			
			var title = document.createElement('div');
			title.innerHTML = 'In addition to searching by model number, please select from <span style=\'text-decoration:underline;cursor:pointer;\' onclick=\'window.scroll(0,400);\'>Search Options</span> to further your product search.';
			title.className = 'smartSearchTitle2';
			searchDiv.appendChild(title);						
			
			var inputDiv = document.createElement('div');
			searchDiv.appendChild(inputDiv);			

			var searchInput = document.createElement('input');
			searchInput.type = 'text';
			searchInput.id = 'searchInput';
			searchInput.className = 'txtbox';
			searchInput.style.paddingTop = '4px';
			searchInput.style.paddingLeft = '0px';
			searchInput.style.marginTop = '4px';
			searchInput.style.height = 'auto';
			searchInput.style.width = '98%';
			searchInput.style.fontSize = '14px';			
			searchInput.style.fontWeight = 'bold';	
			searchInput.className = 'loginClass';				
			searchInput.value = startSearch;
			if($('smartSearchFrontEnd')){
				searchInput.onkeyup=function(){listProducts('','','','','',1,'');} 		
			}else{
				searchInput.onkeyup=function(){populateSmartSearch(type,id,'','',itemType);} 
			}

			searchInput.onfocus = function(){clearValue(this.id,startSearch);}
			searchInput.onblur= function(){ifEmpty(this.id,startSearch);} 
			inputDiv.appendChild(searchInput);
			
			if(type == 'categoryManagement' && itemType == 'category' && $('CategoryType').value == 'Products'){
				if(!$('searchInputProduct')){
					var searchInputProduct = document.createElement('div');
					searchInputProduct.id = 'searchInputProduct';
					searchInputProduct.style.display = '';
					searchInputProduct.innerHTML = startSearch;
					$('pageFooter').appendChild(searchInputProduct);
				}
				$('searchInput').value = $('searchInputProduct').innerHTML;
				
				var advancedSearchDiv = document.createElement('div');
				advancedSearchDiv.style.float = 'right';
				advancedSearchDiv.style.textAlign = 'right';
				advancedSearchDiv.style.marginTop = '4px';			
				advancedSearchDiv.style.marginBottom = '4px';
				searchDiv.appendChild(advancedSearchDiv);

				var advancedSearch = document.createElement('span');
				advancedSearch.innerHTML = 'Advanced';
				advancedSearch.id = 'advancedTitle';
				advancedSearch.onclick = function(){advancedSearchFn('','');} 		
				advancedSearch.onmouseover =  function(){this.style.textDecoration = 'none';}
				advancedSearch.onmouseout =  function(){this.style.textDecoration = 'underline';}
				advancedSearch.className = 'advancedSearch';
				advancedSearchDiv.appendChild(advancedSearch);	
				
			}else if(type == 'categoryManagement' && itemType == 'category' && $('CategoryType').value == 'Categories'){
				if(!$('searchInputCategory')){
					var searchInputCategory = document.createElement('div');
					searchInputCategory.id = 'searchInputCategory';
					searchInputCategory.style.display = '';
					searchInputCategory.innerHTML = startSearch;				
					$('pageFooter').appendChild(searchInputCategory);
				}
				$('searchInput').value = $('searchInputCategory').innerHTML;
			}else if($('smartSearchFrontEnd')){
				var advancedSearchDiv = document.createElement('div');
				advancedSearchDiv.style.textAlign = 'right';
				advancedSearchDiv.style.paddingTop = '4px';			
				advancedSearchDiv.style.paddingBottom = '4px';
				searchDiv.appendChild(advancedSearchDiv);
				if(showAdvancedSearchOption == 1){			
					var advancedSearch = document.createElement('span');
					advancedSearch.innerHTML = 'Advanced';
					advancedSearch.id = 'advancedTitle';
					advancedSearch.onclick = function(){advancedSearchFn('','');} 		
					advancedSearch.onmouseover =  function(){this.style.textDecoration = 'none';}
					advancedSearch.onmouseout =  function(){this.style.textDecoration = 'underline';}
					advancedSearch.className = 'advancedSearch';
					advancedSearchDiv.appendChild(advancedSearch);			
				}else{
					advancedSearchFn('','');
				}
			}
			if(type != 'category' && type != 'product'){			
				var results = document.createElement('div');
				results.innerHTML = $('results').innerHTML;
				results.className = 'results';
				results.id = 'resultsSpan';
				searchDiv.appendChild(results);							
			}
		}else if($('smartSearch').style.display == 'none'){
			$('smartSearch').style.display = '';
			if($('categoryTbl')){$('categoryTbl').style.height = '70%';}
			if($('productTbl')){$('productTbl').style.height = '70%';}			

		}else{
			if(type == 'category' && $('categorySearchDiv')){
				$('categorySearchDiv').parentNode.removeChild($('categorySearchDiv'));
			}else if(type == 'product' && $('productSearchDiv')){
				$('productSearchDiv').parentNode.removeChild($('productSearchDiv'));
			}

			if(type == 'categoryManagement' && $('searchInputProduct') && $('CategoryType').value == 'Products'){
				$('searchInputProduct').parentNode.removeChild($('searchInputProduct'));
			}else if(type == 'categoryManagement' && $('searchInputCategory') && $('CategoryType').value == 'Categories'){
				$('searchInputCategory').parentNode.removeChild($('searchInputCategory'));
			}


			$('smartSearch').style.display = 'none';			
			$('searchInput').value = startSearch;
			if($('categoryTbl')){$('categoryTbl').style.height = '90%';}
			if($('productTbl')){$('productTbl').style.height = '90%';}			

			populateSmartSearch(type,id,'','',itemType);
		}
		
		if(top.$('popBox')){resizePopBox();}
		productFeatures(id,1);
//	}
}
function populateSmartSearch(type,id,colSort,categoryChange,itemType){
	if(!$('loadingDiv')){loading('controlPanel');}

	if($('searchInput') && $('searchInput').value != startSearch){
			var str = cleanValue($('searchInput').value);
		}else{
			var str = '';
		}
	
	if(type == 'category'){		
		if(!colSort && $('categoryColSortDiv')){
			var colSort = $('categoryColSortDiv').innerHTML;
		}else if(!colSort){
			var colSort = '';
		}else if($('categoryColSortDiv')){
			$('categoryColSortDiv').innerHTML = colSort;
		}else{
			var categoryColSortDiv = document.createElement('div');
			categoryColSortDiv.id = 'categoryColSortDiv';
			categoryColSortDiv.style.display = 'none';
			categoryColSortDiv.innerHTML = colSort;
			$('pageFooter').appendChild(categoryColSortDiv)
		}

		var url = rootdomain + 'RootControlpanel/phpScript.php?req=view_categories.php&mode=search&search='+cleanValue(str)+'&sort='+colSort;
		if(!$('categorySearchDiv') && cleanValue(str) != ''){
			var pageFooter = $('pageFooter');
			var categorySearchDiv = document.createElement('div');
			categorySearchDiv.id = 'categorySearchDiv';
			categorySearchDiv.style.display = 'none';
			categorySearchDiv.innerHTML = $('searchInput').value;
			pageFooter.appendChild(categorySearchDiv);
		}else if($('categorySearchDiv') && $('searchInput').value == ''){
			var pageFooter = $('pageFooter');
			var categorySearchDiv = $('categorySearchDiv');
			pageFooter.removeChild(categorySearchDiv); 
		}else if($('categorySearchDiv') ){
			var categorySearchDiv = $('categorySearchDiv');
			categorySearchDiv.innerHTML = $('searchInput').value;		
		}
		
		if($('categoryDownload')){
			$('categoryDownload').href = rootdomain + 'RootControlpanel/generateReport.php?type=category&mode=download&search='+cleanValue(str)+'&sort='+colSort;
		}

	}else if(type == 'product'){		
		if(!colSort && $('productColSortDiv')){
			var colSort = $('productColSortDiv').innerHTML;
		}else if(!colSort){
			var colSort = '';
		}else if($('productColSortDiv')){
			$('productColSortDiv').innerHTML = colSort;
		}else{
			var productColSortDiv = document.createElement('div');
			productColSortDiv.id = 'productColSortDiv';
			productColSortDiv.style.display = 'none';
			productColSortDiv.innerHTML = colSort;
			$('pageFooter').appendChild(productColSortDiv)
		}
	
		if(!categoryChange && $('productCategoryChangeDiv')){
			var categoryChange = $('productCategoryChangeDiv').innerHTML;
		}else if(!categoryChange){
			var categoryChange = '';
		}else if($('productCategoryChangeDiv')){
			$('productCategoryChangeDiv').innerHTML = categoryChange;
		}else{
			var productCategoryChangeDiv = document.createElement('div');
			productCategoryChangeDiv.id = 'productCategoryChangeDiv';
			productCategoryChangeDiv.style.display = 'none';
			productCategoryChangeDiv.innerHTML = categoryChange;
			$('pageFooter').appendChild(productCategoryChangeDiv)
		}
	
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=view_products.php&mode=search&search='+cleanValue(str)+'&sort='+colSort+'&changeCategory='+categoryChange;
		if(!$('productSearchDiv') && cleanValue(str) != ''){
			var pageFooter = $('pageFooter');
			var productSearchDiv = document.createElement('div');
			productSearchDiv.id = 'productSearchDiv';
			productSearchDiv.style.display = 'none';
			productSearchDiv.innerHTML = $('searchInput').value;
			pageFooter.appendChild(productSearchDiv);
		}else if($('productSearchDiv') && $('searchInput').value == ''){
			var pageFooter = $('pageFooter');
			var productSearchDiv = $('productSearchDiv');
			pageFooter.removeChild(productSearchDiv); 
		}else if($('productSearchDiv') ){
			var productSearchDiv = $('productSearchDiv');
			productSearchDiv.innerHTML = $('searchInput').value;		
		}
		if($('downloadLink')){
			$('downloadLink').value = rootdomain + 'RootControlpanel/generateReport.php?type=product&mode=download&search='+cleanValue(str)+'&sort='+colSort+'&changeCategory='+categoryChange;
		}
	
	}else if(type == 'categoryManagement' && itemType == 'category'){
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=search&CatId='+id+'&CategoryType='+$('CategoryType').value+'&search='+cleanValue(str);
		if(str == ''){str = startSearch;} //just used for categoryManagement stored vals
		if($('searchInputCategory') && $('CategoryType').value == 'Categories'){$('searchInputCategory').innerHTML = str;}
		if($('searchInputProduct') && $('CategoryType').value == 'Products'){$('searchInputProduct').innerHTML = str; }	
		if(!$('searchInput')){searchOn('removeAdvanced');}//clear old session searchLimitsCategoryManagement
	}else if(type == 'categoryManagement' && itemType == 'product'){
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=search&ProductId='+id+'&search='+cleanValue(str);
	}

	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}

		xmlHttp=GetXmlHttpObject(url);
		if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;} 
		xmlHttp.onreadystatechange=function(){populateSmartSearchRsp(type,id,colSort,categoryChange,itemType)};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	
}



function populateSmartSearchRsp(type,id,colSort,categoryChange,itemType){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
		//alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');

	if(type == 'category' || type == 'product'){
		$('tallyResults').innerHTML = theGoods[0];		
		$('searchResults').innerHTML = theGoods[1];			
	}else if(type == 'categoryManagement' && itemType == 'category'){
		var CategoryType = $('CategoryType').value;
		
			if(CategoryType == 'Categories'){
				$('categorySelected').innerHTML=theGoods[0];
				if(theGoods[0].indexOf('<ul') != -1){
					Sortable.create('1_myList',{ghosting:false, constraint:true, hoverclass:'over',
					onChange:function(element){
					// Total elements in the list (in this case 7 <li> element)
					//var totElement = <?= $iCnt-1;  ?>;
					var totElement = $('1_myList').getElementsByTagName('li').length;
					var newOrder = Sortable.serialize(element.parentNode);
					for(i=1; i<=totElement; i++){
					newOrder = newOrder.replace("1_myList[]=","");
					newOrder = newOrder.replace("&",",");
					}
					// display the string with the new order in the &ltPgt; with id listNewOrder
					//$('listNewOrder').innerHTML = 'New Order: ' + newOrder;
	//				$('newOrderInput').value = newOrder;
					}
					});				
				}
				$('productSelected').innerHTML='';			
				$('categorySearchProducts').innerHTML='';			
				$('categorySearchCategories').innerHTML=theGoods[1];
			
			}else if(CategoryType == 'Products'){
				if($('4_ckbox_selectAll')){
					$('4_ckbox_selectAll').checked = false;
					$('addBox_selectAll').src = rootdomain+'RootImages/box_small.png';
				}
				if($('2_ckbox_selectAll')){
					$('2_ckbox_selectAll').checked = false;
					$('removeBox_selectAll').src = rootdomain+'RootImages/box_small_2.png';
				}
				
				$('productSelected').innerHTML=theGoods[0];

				if(theGoods[0].indexOf('<ul') != -1){

					Sortable.create('2_myList',{ghosting:false, constraint:true, hoverclass:'over',
					onChange:function(element){
					// Total elements in the list (in this case 7 <li> element)
					//var totElement = <?= $iCnt-1;  ?>;
					var totElement = $('2_myList').getElementsByTagName('li').length;

/*					for(i = 0; i < $('2_myList').getElementsByTagName('div').length; i++){
						var totElement = 0;
						if($('2_myList').getElementsByTagName('div')[i].id.indexOf('_item_') != -1){totElement = totElement + 1;}
						alert(totElement);
					}
*/					
					var newOrder = Sortable.serialize(element.parentNode);
					for(i=1; i<=totElement; i++){
					newOrder = newOrder.replace("2_myList[]=","");
					newOrder = newOrder.replace("&",",");
					}

					// display the string with the new order in the &ltPgt; with id listNewOrder
					//$('listNewOrder').innerHTML = 'New Order: ' + newOrder;
					//$('newOrderInput').value = newOrder;
					}
					});
				}
				$('categorySelected').innerHTML='';			
				$('categorySearchCategories').innerHTML = '';
				$('categorySearchProducts').innerHTML = theGoods[1];
				//alert(theGoods[1]);
			
			}
			resizePopBox();
		}else if(type == 'categoryManagement' && itemType == 'product'){
				$('categorySelected').innerHTML=theGoods[0];
				if(theGoods[0].indexOf('<ul') != -1){
					Sortable.create('1_myList',{ghosting:false, constraint:true, hoverclass:'over',
					onChange:function(element){
					// Total elements in the list (in this case 7 <li> element)
					//var totElement = <?= $iCnt-1;  ?>;
					var totElement = $('1_myList').getElementsByTagName('li').length;
					var newOrder = Sortable.serialize(element.parentNode);
					for(i=1; i<=totElement; i++){
					newOrder = newOrder.replace("1_myList[]=","");
					newOrder = newOrder.replace("&",",");
					}
					// display the string with the new order in the &ltPgt; with id listNewOrder
					//$('listNewOrder').innerHTML = 'New Order: ' + newOrder;
	//				$('newOrderInput').value = newOrder;
					}
					});				
				}
				$('productSelected').innerHTML='';			
				$('categorySearchProducts').innerHTML='';			
				$('categorySearchCategories').innerHTML=theGoods[1];
			
				resizePopBox();
			}//end 	}else if(type == 'categoryManagement' && itemType == 'product'){
		
			if($('resultsSpan')){
				$('resultsSpan').innerHTML = $('results').innerHTML;
			}

		if(type == 'categoryManagement'){
		if($('ck_category')){
				var ck_boxes = $('ck_category').innerHTML.split(',');
				for(i = 0; i < ck_boxes.length; i++){
					if($('addBox_'+ck_boxes[i])){
						$('addBox_'+ck_boxes[i]).src = rootdomain+'RootImages/box_ck.png';
						if($('3_ckbox_'+ck_boxes[i])){$('3_ckbox_'+ck_boxes[i]).checked = true;}
						if($('4_ckbox_'+ck_boxes[i])){$('4_ckbox_'+ck_boxes[i]).checked = true;}
					}
				}
			}

		if($('ck_product')){
				var ck_boxes = $('ck_product').innerHTML.split(',');
				for(i = 0; i < ck_boxes.length; i++){
					if($('addBox_'+ck_boxes[i])){
						$('addBox_'+ck_boxes[i]).src = rootdomain+'RootImages/box_ck.png';
						if($('3_ckbox_'+ck_boxes[i])){$('3_ckbox_'+ck_boxes[i]).checked = true;}
						if($('4_ckbox_'+ck_boxes[i])){$('4_ckbox_'+ck_boxes[i]).checked = true;}
					}
				}//end for()
			}//end If()
		} //if(type == 'categoryManagement'){
}
}
function fnSelectAll(){
	var form = document.thisForm;
	for(i=0;i<form.elements.length;i++){
		if(form.elements[i].type == 'checkbox' && form.elements[i].disabled != true && $('selectAll').checked == true){
			form.elements[i].checked = true;
		}else if(form.elements[i].type == 'checkbox' && $('selectAll').checked == false){
			form.elements[i].checked = false;
		}
	}
}

function addChar(actionId,ProductId){
if(actionId == 'addCharCancel'){
	$('addCharCancel').style.display = 'none';
//	$('addCharNew').style.display = '';		
	$('addCharsDiv').style.display = 'none';
	$('printChars').style.height = '495px';
	resizePopBox();
	return;
}else if(actionId == 'addChar'){
	if( $('PricingGroupType').value == 'new'){
		$('addCharsDiv').style.display = 'none';
		$('newSpacer').style.display = 'none';			
		$('addCharCancel').style.display = 'none';
//		$('addCharNew').style.display = '';
		addPricingGroup('new');
		return;
	}else{
		$('addCharCancel').style.display = 'none';
//		$('addCharNew').style.display = '';
		$('addCharsDiv').style.display = 'none';
		$('newSpacer').style.display = 'none';			
		addPricingGroup('defaults');			
		//addChar('saveCharDefault');
		return;
	}
}else if(actionId == 'saveChar'){

var expPG = /PricingGroup\[(\d+)]\[0\]\[(\d+)\]/;
var expPGO = /PricingGroup\[(\d+)\]\[(\d+)\]\[(\d+)\]\[(\d+)\]/;
var vars = '&PricingGroup=';
var varsAlert = '';
var defaultPricingGroupIdOriginals = '';
for(iCnt=0;iCnt<document.thisForm.elements.length;iCnt++){ //test pricing groups options
	var warningSpan = 'warning'+document.thisForm.elements[iCnt].id;
	if($(warningSpan)){$(warningSpan).innerHTML = '';}
	var resp = expPG.exec(document.thisForm.elements[iCnt].name);
	var resp2 = expPGO.exec(document.thisForm.elements[iCnt].name);	

	if(resp && resp2 == null && Trim(document.thisForm.elements[iCnt].value) == ''){
//		alert(warningSpan);
		$(warningSpan).innerHTML = ' Characteristic name is required';
		document.thisForm.elements[iCnt].value = ''; //remove whitespaces
		document.thisForm.elements[iCnt].focus();
		return false;
	}else if(resp && resp2 == null ){
		var optionNames = '';

		if($('PricingGroupIdOriginal['+resp[1]+']')){
			var defaultId = $('PricingGroupIdOriginal['+resp[1]+']').innerHTML;
		}else{
			var defaultId = '0';
		}
//		alert('Group:\n'+document.thisForm.elements[iCnt].value.replace(/&/g,'-,-')+'\n'+'PricingGroupIdOriginal['+resp[1]+']'+'\n'+defaultId);
		
		if(vars != '&PricingGroup='){vars += '|,|,|';}
		vars += document.thisForm.elements[iCnt].value.replace(/&/g,'-,-')+'|,|'+resp[2]+'|,|'+defaultId;	
	
		for(iCntPGO=0;iCntPGO<document.thisForm.elements.length;iCntPGO++){ //test pricing group options
			var warningSpan = 'warning'+document.thisForm.elements[iCntPGO].id;
			if($(warningSpan)){$(warningSpan).innerHTML = '';}
			var respPGO = expPG.exec(document.thisForm.elements[iCntPGO].name);
			var respPGO2 = expPGO.exec(document.thisForm.elements[iCntPGO].name);			

			if(respPGO == null && respPGO2 && resp[1] == respPGO2[1] && respPGO2[3] == 0 && Trim(document.thisForm.elements[iCntPGO].value) == ''){ //[3] = Option Name
				maxPricingGroup(resp[1]);
				$(warningSpan).innerHTML = ' Option name is required';
				document.thisForm.elements[iCntPGO].value = ''; //remove whitespaces
				document.thisForm.elements[iCntPGO].focus();
				return false;
			}else if(respPGO == null && respPGO2 && resp[1] == respPGO2[1] && respPGO2[3] == 0){
				if($('PricingGroupOptionIdOriginal['+respPGO2[1]+']['+respPGO2[2]+']')){
					var defaultId = $('PricingGroupOptionIdOriginal['+respPGO2[1]+']['+respPGO2[2]+']').innerHTML;
				}else{
					var defaultId = '0';
				}
//				alert('Options\n'+document.thisForm.elements[iCntPGO].value.replace(/&/g,'-,-')+'\n'+'PricingGroupOptionIdOriginal['+respPGO2[1]+']['+respPGO2[2]+']'+'\n'+defaultId);
				var val = cleanValue(document.thisForm.elements[iCntPGO].value);
				vars += '|,|'+val+'|,|'+respPGO2[4]+'|,|'+defaultId;	
				optionNames += '\n'+document.thisForm.elements[iCntPGO].value+' - '+respPGO2[4];
			}//end if()
		}//end for()


	varsAlert += document.thisForm.elements[iCnt].value+' - '+resp[2]+'\n options: '+optionNames+'\n\n';	
		
	}//end if()
}//end for()
//alert(varsAlert);
//alert(vars);
//return; //temp


		if(!$('loadingDiv')){loading('controlPanel');}
		
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=styleManagement.php&mode=saveChar';
		if(ProductId != ''){url = url + '&ProductId=' + ProductId;}
		url = url + vars;

if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
		//alert(url);
		xmlHttp=GetXmlHttpObject(url);
		if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
		xmlHttp.onreadystatechange=function(){addCharRsp(actionId,ProductId)};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function addCharRsp(actionId,ProductId){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
		//alert(xmlHttp.responseText);
			if(ProductId != ''){
				var type = ProductId;
			}else{
				var type = 'defaults';
			}
//			$('loadCharsDiv').innerHTML = '';
//			loadChars(type);
			popBoxRemove('editChars',ProductId,'saved','');
		
			return false;
		}else{
			alert('Error: '+xmlHttp.responseText);
		}	
	}
}

function warningPageShow(msg){

	if($('warningPage').style.display == ''){
		$('warningPage').innerHTML = '';
		$('warningPage').style.display = 'none';
	}else{
		$('warningPage').innerHTML = msg;
		$('warningPage').style.display = '';
		setTimeout("warningPageShow()",2000);	//	clearTimeout()
	}

	return;
}

function editChars(action,ProductId){
	if($('editChars').style.display == ''){
		$('editCharsSave').style.display = '';
		$('editCharsCancel').style.display = '';
		$('editChars').style.display = 'none';
		$('addCharNew').style.display = 'none';
		var inputs = document.getElementsByTagName('INPUT');
		for(var i=0; i<inputs.length; i++){
			if(inputs[i].id.indexOf('PricingGroupCkbox') != -1){
				inputs[i].style.display = '';
			}
		}
		$('noSortChars').id = 'sortableChars';
		applyTableDnD();		
		return;
	}else{		
		$('editChars').style.display = '';
		$('addCharNew').style.display = '';		
		$('editCharsSave').style.display = 'none';
		$('editCharsCancel').style.display = 'none';
		var inputs = document.getElementsByTagName('INPUT');
		for(var i=0; i<inputs.length; i++){
			if(inputs[i].id.indexOf('PricingGroupCkbox') != -1){
				inputs[i].style.checked = false;
				inputs[i].style.display = 'none';
			}
		}
	}
	if(!$('loadingDiv')){loading('controlPanel');}	
	if(action == 'editCharsCancel'){
		loadPage(rootdomain+'RootControlpanel/view_styles.php?type=defaults','controlPanel','loadPage','');
		return;
	}else if (action == 'editCharsSave'){
		var inputs = document.getElementsByTagName('INPUT');
		var PricingGroups = [];
		for(var i=0; i<inputs.length; i++){
			if(inputs[i].id.indexOf('PricingGroupCkbox') != -1 && inputs[i].id.checked != true){
				PricingGroups[PricingGroups.length] = inputs[i].id.replace(/PricingGroupCkbox/,'');
			}
		}
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=styleManagement.php&mode=editCharsSave&ProductId='+ProductId+'&PricingGroups='+PricingGroups.join(',');
		if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
		//alert(url);
		xmlHttp=GetXmlHttpObject(url);
		if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
		xmlHttp.onreadystatechange=function(){editCharsRsp()};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function editCharsRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){ 		
			loadPage(rootdomain+'RootControlpanel/view_styles.php?type=defaults','controlPanel','warningPageShow(\'Updated Successfully\');','');
		}else if(showErrors == 1){
			alert(xmlHttp.responseText);		
		}
		return;			
	}
}

function loadChars(type,id){
	if(!$('loadingDiv')){loading('controlPanel');}
	
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=styleManagement.php&mode=loadChars&type='+type+'&PricingGroupId='+id;
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	//alert(url);
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){loadCharsRsp(type)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadCharsRsp(type){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
			var loadCharsDiv = $('loadCharsDiv');
			loadCharsDiv.style.display = '';	
			loadCharsDiv.innerHTML = theGoods[0];
			$('GroupNumIndex').innerHTML = theGoods[1];	
		if(theGoods[1] == ''){ addPricingGroup(type);}
	resizePopBox();
	applyKeyPress();
	return;			
	}
}


function applyTableDnD(){
	var tbls = document.getElementsByTagName("table");
	for(iCnt=0;iCnt<document.getElementsByTagName("table").length;iCnt++){
	if(tbls[iCnt].id.indexOf('tblPricingGroup') != -1 || tbls[iCnt].id.indexOf('sortable') != -1 ){
		var table = $(tbls[iCnt].id);
		var tableDnD = new TableDnD();
		tableDnD.init(table);
	}
	}
}

function applyKeyPress(){
	var form = document.thisForm;
	for(iCnt=0;iCnt<form.elements.length;iCnt++){
		form.elements[iCnt].onkeypress = 'alert(\'13\')';
		return;
		//keyPress('product','update','save','".$_REQUEST['ProductId']."',event)
	}
}

function setSessionTimeOut(){
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=controlpanel.php&mode=setSessionTimeOut';
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}

	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){setSessionTimeOutRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function setSessionTimeOutRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
//		if($('loadingDiv')){loading();}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
//		alert("Timeout Extended: "+theGoods[0]);
		return;
	}
}

function autoTimeOut(timeOutSec,autoTimeOut,CompanyName){
	if($('popBoxTimeout') && $('autoTimeOutId').innerHTML == 0){
		logoutSubmit();
		return;
	}else if($('popBoxTimeout')){
		$('autoTimeOutId').innerHTML = Number($('autoTimeOutId').innerHTML) - 1;
		setTimeout("autoTimeOut('"+timeOutSec+"','"+autoTimeOut+"','"+CompanyName+"')",1000);
		ckSessionTimeOut(timeOutSec,autoTimeOut,CompanyName);
		return;
	}
}

function ckSessionTimeOut(timeOutSec,autoTimeOut,CompanyName){
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=controlpanel.php&mode=ckSessionTimeOut';
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}

	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){ckSessionTimeOutRsp(timeOutSec,autoTimeOut,CompanyName)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function ckSessionTimeOutRsp(timeOutSec,autoTimeOut,CompanyName){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
//		if($('loadingDiv')){loading();}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		$('timeOut').innerHTML = theGoods[0];
		$('currentTimeCount').innerHTML = theGoods[1];

		if( $('popBoxTimeout') && theGoods[0] > theGoods[1]){
			displayTimeOut(timeOutSec,autoTimeOut,CompanyName,'Yes');
		}else if($('popBoxTimeout') && theGoods[0] == ''){
			logoutSubmit();
		}
		return;
	}
}
function displayTimeOut(timeOutSec,autoTimeOut,CompanyName,ans){ 
	var timeOutMin = timeOutSec/60;
	var ckSessionTimeOutNow = Number($('timeOut').innerHTML) - 1;
	if ($('popBoxTimeout') && ans == 'Yes'){ 
		$('pageFooter').removeChild($('popBoxTimeout'));
		if(!$('popBox')){
			$('pageFooter').removeChild($('bckGroundDim'));
		}else{
			$('popBox').style.display = '';
		}
		$('timeOut').innerHTML = Number($('currentTimeCount').innerHTML) + Number(timeOutSec);
		setSessionTimeOut();
		document.onkeydown=function(){setSessionTimeOut();$('timeOut').innerHTML = Number($('currentTimeCount').innerHTML) + timeOutSec;return;}
		document.onmousedown=function(){setSessionTimeOut();$('timeOut').innerHTML = Number($('currentTimeCount').innerHTML) + timeOutSec;return;}

		setTimeout("displayTimeOut('"+timeOutSec+"','"+autoTimeOut+"','"+CompanyName+"','')",1000);
		return;
	}else if($('popBoxTimeout') && ans == 'No'){ 
		$('pageFooter').removeChild($('popBoxTimeout'));	
//		$('pageFooter').removeChild($('bckGroundDim'));		
		loading('bckGroundDim','onLoad_blk.gif','30%');
		logoutSubmit();
		return;
	}else if($('currentTimeCount').innerHTML == $('timeOut').innerHTML){
		if(!$('popBox')){
			showBckGroundDim();
		}else{
			$('popBox').style.display = 'none';
		}
		var pageFooter = $('pageFooter');
		var bckGroundDim = $('bckGroundDim');
		var popBoxTimeout = document.createElement('div');	
		popBoxTimeout.className = 'popBoxSmall';
		popBoxTimeout.id = 'popBoxTimeout';
		pageFooter.appendChild(popBoxTimeout);
	
		var popBoxContentTimeout = document.createElement('div');	
		popBoxContentTimeout.id = 'popBoxContentTimeout';

		var elTitle = document.createElement('div');	
		elTitle.innerHTML = CompanyName;	
		elTitle.style.fontWeight = 'bold';	
		elTitle.style.fontSize = '12px';	
		elTitle.style.paddingTop = '30px';

		var el = document.createElement('div');	
		el.innerHTML = 'Your session has been inactive for '+timeOutMin.toFixed(0)+' minutes.<br>Would you like to continue?';	
		el.style.fontWeight = 'bold';	
		el.style.fontSize = '16px';	
		el.style.paddingTop = '10px';
		
		var el1 = document.createElement('div');	
		el1.style.paddingTop = '15px';
		el1.align = 'center';

		var el2 = document.createElement('div');	
		el2.align = 'center';
		el2.className = 'sessionContainerBtns';
		
		var el3 = document.createElement('div');	
		el3.innerHTML = 'Yes';	
		el3.className = 'sessionBtns';
		el3.onclick = function(){return displayTimeOut(timeOutSec,autoTimeOut,CompanyName,'Yes')};
		
		var el6 = document.createElement('div');	
		el6.innerHTML = '&nbsp;';	
		el6.className = 'sessionBtns';
		el6.style.width = '40px';	
		el6.style.background = '#FFFFFF';
		el6.style.border = 'none';				
		
		var el4 = document.createElement('div');	
		el4.innerHTML = 'No';	
		el4.style.left = '100px';	
		el4.className = 'sessionBtns';
		el4.onclick = function(){return displayTimeOut(timeOutSec,autoTimeOut,CompanyName,'No')};		
		
		var el5 = document.createElement('div');	
		el5.style.paddingTop = '50px';
		el5.innerHTML = "Your session will end automatically in <span id='autoTimeOutId'>"+autoTimeOut+"</span> seconds.";
		
		popBoxContentTimeout.appendChild(elTitle);
		popBoxContentTimeout.appendChild(el);
		el2.appendChild(el3);	
		el2.appendChild(el6);				
		el2.appendChild(el4);				
		el1.appendChild(el2);				
		popBoxContentTimeout.appendChild(el1);				
		popBoxContentTimeout.appendChild(el5);						
		popBoxTimeout.appendChild(popBoxContentTimeout);
		
		document.onkeydown='';
		document.onmousedown='';

		setTimeout("autoTimeOut('"+timeOutSec+"','"+autoTimeOut+"','"+CompanyName+"')",1000);
		return;
}else{
		$('currentTimeCount').innerHTML = Number($('currentTimeCount').innerHTML) + 1; 
		var timeLeft = (Number($('timeOut').innerHTML) - Number($('currentTimeCount').innerHTML));
		minVar = Math.floor(timeLeft/60);
		secVar = timeLeft % 60;
		$('timeOutMinutes').innerHTML = minVar+":"+secVar;
		setTimeout("displayTimeOut("+timeOutSec+",'"+autoTimeOut+"','"+CompanyName+"','')",1000); 
		
		if($('currentTimeCount').innerHTML == ckSessionTimeOutNow){
			ckSessionTimeOut(timeOutSec,autoTimeOut,CompanyName);
			return;
		}

	}
} 

function getDefaultPricingGroup(GroupNum){
if($('PricingGroupType')){
	var PricingGroupType = $('PricingGroupType').value;
}else{
	var PricingGroupType = $('PricingGroupType').value;
}
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=styleManagement.php&mode=getDefaultPricingGroup&PricingGroupId='+PricingGroupType+'&GroupNum='+GroupNum;
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	//alert('newUrl: '+newUrl+'\n cleanUrl: '+cleanUrl);
	
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){getDefaultPricingGroupRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);


}

function getDefaultPricingGroupRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
//alert(xmlHttp.responseText);
			var theGoods = xmlHttp.responseText.split('|');
			var div = document.createElement('div');
			div.innerHTML = theGoods[0];
			div.id = 'div_'+theGoods[1];
			$('loadCharsDiv').appendChild(div);
			var GroupNum = Number(theGoods[1]) - 1;
			if($('PricingGroup['+GroupNum+']')){$('PricingGroup['+GroupNum+']').focus();}

			resizePopBox();
			applyKeyPress();
			return;
	}

}

function addPricingGroup(type){
	if(type != 'defaults' && type != 'new'){
//		$('addCharsDiv').style.display = '';
//		$('addCharCancel').style.display = '';
//		$('addCharNew').style.display = 'none';
		if($('addCharsDiv')){$('addCharsDiv').style.width = '100%';}
		$('newSpacer').style.display = '';
		resizePopBox();
		return;
	}
	var GroupNum = $('GroupNumIndex').innerHTML * 1;
	if(GroupNum != 0){
		var div = $('loadCharsDiv'); 
		var el = document.createElement('div');
		el.className ='spacingTables';
		el.id ='spacer'+GroupNum;   
		div.appendChild(el);
	}

$('GroupNumIndex').innerHTML = GroupNum + 1;

if(type == 'defaults'){
	getDefaultPricingGroup(GroupNum);
	return;
}else{
	var div = $('loadCharsDiv');
	div.style.display = '';

	var tbl = document.createElement('table');
	tbl.border='0';
	tbl.cellSpacing='1';
	tbl.cellPadding='5';
	tbl.width='100%';
	tbl.id='tblPricingGroup[' + GroupNum + ']';
	tbl.className='tblHead';
	tbl.style.fontSize='12px';
	tbl.style.fontWeight='bold';
	tbl.align='center';
	//tbl.style.background-color = '#990000';
	div.appendChild(tbl);
	
	var row = tbl.insertRow(0);
	row.className='tbltitle';
	row.setAttribute('noDrop','true'); 
	row.setAttribute('noDrag','true'); 
	
	var cell_00 = row.insertCell(0);
	
	var el4 = document.createElement('div');
	el4.className = 'floatRight';
	el4.style.width = '150px';	
	
	var el3 = document.createElement('input');
	el3.type = 'submit';
	el3.name = 'RemoveBtn[]';
	el3.id = 'RemoveBtn[]';
	el3.className = 'buttenRemove';
	el3.value = '';  
	el3.title = 'Click to delete this product characteristic.';
	el3.onclick = function(){return removePricingGroup(GroupNum)};

	var el6 = document.createElement('input');
	el6.type = 'submit';
	el6.name = 'MaximizeBtn[]';
	el6.id = 'MaximizeBtn[]';
	el6.className = 'buttenMaximize';
	el6.value = '';  
	el6.title = 'Click to maximize this product characteristic.';
	el6.onclick = function(){return maxPricingGroup(GroupNum)};

	var el7 = document.createElement('input');
	el7.type = 'submit';
	el7.name = 'MinimizeBtn[]';
	el7.id = 'MinimizeBtn[]';
	el7.className = 'buttenMinimize';
	el7.value = '';  
	el7.title = 'Click to minimize this product characteristic.';
	el7.onclick = function(){return minPricingGroup(GroupNum)};
	
	var el5 = document.createElement('span');
	el5.className = 'paddingLeft10';
	
	//var el = document.createTextNode('Product Characteristic: ');
	
	var el2 = document.createElement('input');
	el2.type = 'text';
	el2.name = 'PricingGroup[' + GroupNum + '][0][00]';  //[00] - reserved for new groups
	el2.id = 'PricingGroup[' + GroupNum + '][0]';
	//el2.value = 'PricingGroup[' + GroupNum + '][0][00]';
//	el2.value = GroupNum;	
	el2.className = 'txtboxGroupName';
	
	var el23 = document.createElement('span');
	el23.id = 'warningPricingGroup[' + GroupNum + '][0]';
	el23.className = 'warningText';
	
	cell_00.appendChild(el4);
	el4.appendChild(el3);
	el4.appendChild(el6);
	el4.appendChild(el7);	
	//cell_00.appendChild(el);
	//cell_00.appendChild(el5);
	cell_00.appendChild(el2);
	cell_00.appendChild(el23);
	
	
	var lastRow = tbl.rows.length;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
	row.className='tblBody';
	row.setAttribute('noDrop','true'); 
	row.setAttribute('noDrag','true'); 

	
	  var cell_00 = row.insertCell(0);
	  var el = document.createTextNode('Option Name');
	  cell_00.appendChild(el);
		
	  var el5 = document.createElement('span');
	  el5.className = 'paddingPriceTitle';
	  cell_00.appendChild(el5);
	  
	//  var el = document.createTextNode('Option Price');
	//  cell_00.appendChild(el);
	
	var lastRow = tbl.rows.length;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
		row.id = 'tblRowPricingOption[' + GroupNum + '][1]';
		row.className='tblBody';
	  
	  var cell_00 = row.insertCell(0);
	 
	  var el4 = document.createElement('div');
	  el4.className = 'floatRight';
	  el4.style.width = '150px';		  
	  
	  var el = document.createElement('input');
	  el.type = 'submit';
	  el.name = 'RemoveOptionBtn[]';
	  el.id = 'RemoveOptionBtn[]';
	  el.className = 'buttenRemove';
	  el.value = '';  
	  el.title = 'Click to delete this product characteristic.';
	  el.onclick = function(){return removeGroupOption(GroupNum,'1')};
	  el4.appendChild(el);
	  cell_00.appendChild(el4);
	  
	  
	  var el = document.createElement('input');
	  el.type = 'text';
	  el.name = 'PricingGroup['+GroupNum+'][1][0][00]';
	//  el.value = 'PricingGroup['+GroupNum+'][1][0][00]';  
//	  el.value = GroupNum;  	
	  el.id = 'PricingGroup['+GroupNum+'][1][0]';
	  el.className = 'txtboxPSize';
	  cell_00.appendChild(el);
	
		var el = document.createElement('span');
		el.id = 'warningPricingGroup[' + GroupNum + '][1][0]';
		el.className = 'warningText';
		cell_00.appendChild(el);
	  
	/* var el5 = document.createElement('span');
	  el5.className = 'paddingPrice';
	  cell_00.appendChild(el5);
	  
	  var el = document.createElement('input');
	  el.type = 'text';
	  el.name = 'PricingGroup[' + GroupNum + '][2][]';
	  el.id = 'PricingGroup[' + GroupNum + '][2][PPrice]';
	  el.className = 'txtboxPPrice';
	  el.onkeypress = keyPressTest;
	  cell_00.appendChild(el);
	*/
	var lastRow = tbl.rows.length;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
	row.className='tblBody';
	row.setAttribute('noDrop','true'); 
	row.setAttribute('noDrag','true'); 

	
	var cell_00 = row.insertCell(0);
	
	 var el4 = document.createElement('div');
	  el4.className = 'floatRight';
	  
	var el = document.createElement('input');
		el.type = 'submit';
		el.name = 'AddPricingOption[]';
		el.id = 'AddPricingOption[]';
		el.className = 'buttenAdd';
		el.value = '';
		el.title='Click to add an option to this product characteristic.'
		el.onclick = function(){return addGroupOption(GroupNum)};
		el4.appendChild(el);
		cell_00.appendChild(el4);

		var el = document.createElement('input');
			el.name = GroupNum + '-Option';
			el.id = GroupNum + '-Option';
			el.type = 'hidden';
			el.value = 2;
			cell_00.appendChild(el);
	$('PricingGroup['+GroupNum+'][0]').focus();
	if($('popBox')){resizePopBox();}
	applyKeyPress();
	return;
}//end if(type == 'defaults'){
}

function removePricingGroup(GroupNum)
{
if($('tblPricingGroup[' + GroupNum + ']')){
var ans = confirm('Are you sure you would like to delete this product characteristic?');
if(ans){
	var div = $('loadCharsDiv');
	var tbl = $('tblPricingGroup[' + GroupNum + ']');
	tbl.parentNode.removeChild(tbl);
	if($('spacer'+GroupNum)){$('spacer'+GroupNum).style.display = 'none';}
	resizePopBox();
	}else{
		return ans;
	}
}
} 

function showDetailsPricingGroup(GroupNum){
	if($('PricingGroupOptions'+GroupNum)){
		var tbl = $('PricingGroupOptions'+GroupNum);
		if(tbl.style.display == 'none'){
			maxPricingGroup(GroupNum);
		}else{
			minPricingGroup(GroupNum);			
		}				
	}
}

function minPricingGroup(GroupNum){
	if(GroupNum == 'all'){
		var tbls = document.getElementsByTagName('div');
		for(var i=0; i<tbls.length; i++){
			if(tbls[i].id.indexOf('PricingGroupOptions') != -1){
				var idStrip = tbls[i].id.replace(/PricingGroupOptions/,'');
				minPricingGroup(idStrip);
			}
		}	
	}

	if($('PricingGroupOptions'+GroupNum)){
		$('PricingGroupOptions'+GroupNum).style.display = 'none';
	}
}

function maxPricingGroup(GroupNum){
	if(GroupNum == 'all'){
		var tbls = document.getElementsByTagName('div');
		for(var i=0;i<tbls.length;i++){
			if(tbls[i].id.indexOf('PricingGroupOptions') != -1){
				var idStrip = tbls[i].id.replace(/PricingGroupOptions/,'');
				maxPricingGroup(idStrip);
			}
		}	
	}
	
	if($('PricingGroupOptions'+GroupNum)){
		$('PricingGroupOptions'+GroupNum).style.display = '';
	}
}

function addGroupOption(GroupNum){
	if($(GroupNum + '-Option')){
			var OptionNum = $(GroupNum + '-Option').value;
		}else{
			var OptionNum = 1;
	}

	var tbl = $('tblPricingGroup[' + GroupNum + ']');
		
	var lastRow = tbl.rows.length -1;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
	row.id = 'tblRowPricingOption[' + GroupNum + '][' + OptionNum +']';
	row.className ='tblBody';

  var cell_00 = row.insertCell(0);
  var el4 = document.createElement('div');
  el4.className = 'floatRight';
  el4.style.width = '150px';	  
  
  var el = document.createElement('input');
  el.type = 'submit';
  el.name = 'RemoveOptionBtn[]';
  el.id = 'RemoveOptionBtn[]';
  el.className = 'buttenRemove';
  el.value = '';
  el.title = 'Click to delete this product characteristic option.';  
  el.onclick = function(){return removeGroupOption(GroupNum,OptionNum)};
  el4.appendChild(el);
  cell_00.appendChild(el4);	

  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'PricingGroup[' + GroupNum + '][' + OptionNum + '][0][00]'; //[00] - reserved for new options
  el.id = 'PricingGroup[' + GroupNum + '][' + OptionNum + '][0]';
//  el.value = 'PricingGroup[' + GroupNum + '][' + OptionNum + '][0][00]';
  el.className = 'txtboxPSize';
  cell_00.appendChild(el);
  
  	var el = document.createElement('span');
	el.id = 'warningPricingGroup['+GroupNum+']['+OptionNum+'][0]';	
	el.className = 'warningText';
	cell_00.appendChild(el);

/*  var el = document.createElement('span');
  el.className = 'paddingPrice';
  cell_00.appendChild(el);
  
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'PricingGroup[' + GroupNum + '][' + OptionNum + '][]';
  el.id = 'PricingGroup[' + GroupNum + '][' + OptionNum + '][PPrice]';
  el.className = 'txtboxPPrice';
  el.onkeypress = keyPressTest;
  cell_00.appendChild(el);
*/
if($(GroupNum + '-Option')){
//	alert('exists' + document.thisForm.GroupNum.value);
	var OptionNumNew = 1 * $(GroupNum + '-Option').value;
	 $(GroupNum + '-Option').value = OptionNumNew + 1;
//	alert('done' + document.thisForm.GroupNum.value);
}else{
	var div2 = $('loadCharsDiv');
	var el = document.createElement('input');
	el.type = 'hidden';
	el.name = GroupNum + '-Option';
	el.id = GroupNum + '-Option';
	el.value = 2;
	div2.appendChild(el);
	
//	alert('created first');	
}
$('PricingGroup[' + GroupNum + '][' + OptionNum + '][0]').focus();
resizePopBox();
applyKeyPress();
return false;
}

function upGroupOption(GroupNum,OptionNum){
if($('tblRowPricingOption[' + GroupNum + '][' + OptionNum +']')){

//alert('tblRowPricingOption[' + GroupNum + '][' + OptionNum +'] is here.');
		var tbl = $('tblPricingGroup[' + GroupNum + ']');		
		var tr = $('tblRowPricingOption[' + GroupNum + '][' + OptionNum +']');

for(iCnt=0;iCnt<tbl.rows.length;iCnt++){
	if(tbl.rows[iCnt].id != ''){alert(tbl.rows[iCnt].id +'\n'+GroupNum+'\n'+OptionNum);}
}

resizePopBox();
return;
}
} 


function removeGroupOption(GroupNum,OptionNum){
	if($('tblRowPricingOption[' + GroupNum + '][' + OptionNum +']')){
	var ans = confirm('Are you sure you would like to delete this product characteristic option?');
	if(ans){
	//alert('tblRowPricingOption[' + GroupNum + '][' + OptionNum +'] is here.');
			var tbl = $('tblPricingGroup[' + GroupNum + ']');		
			var tr = $('tblRowPricingOption[' + GroupNum + '][' + OptionNum +']');
	
	var lastRow = tbl.rows.length - 1;
	
	if(lastRow > 3){ // ck to see if it's the last option
		var tbl = tr; // Look up the hierarchy for TABLE
		while (tbl != document && tbl.nodeName != 'TABLE') 
		{		
			tbl = tbl.parentNode;
		}
		
		if (tbl && tbl.nodeName == 'TABLE') 
		{
			while (tr.hasChildNodes()) 
			{
			tr.removeChild( tr.lastChild );
			}
		tr.parentNode.removeChild( tr );
		}
	
				
	}else{ // blank inputs on last group option
		$('PricingGroup[' + GroupNum + '][' + OptionNum + '][0]').value = '';
		//	$('PricingGroup[' + GroupNum + '][' + OptionNum + '][1]').value = '';
	
	}			
	resizePopBox();
	return false;
		}else{
			return ans;
		}
	}else{
		if(showErrors == 1){alert('error: $(\'tblRowPricingOption[' + GroupNum + '][' + OptionNum +']\') doesn\'t exist');}
	}
} 


var currenttable = null;
document.onmousemove = function(ev){
    if (currenttable && currenttable.dragObject) {
        ev   = ev || window.event;
        var mousePos = currenttable.mouseCoords(ev);
        var y = mousePos.y - currenttable.mouseOffset.y;
        if (y != currenttable.oldY) {
            // work out if we're going up or down...
            var movingDown = y > currenttable.oldY;
            // update the old value
            currenttable.oldY = y;
            // update the style to show we're dragging
            currenttable.dragObject.style.backgroundColor = "#eee";
            // If we're over a row then move the dragged row to there so that the user sees the
            // effect dynamically
            var currentRow = currenttable.findDropTargetRow(y);
            if (currentRow) {
                if (movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow.nextSibling);
                } else if (! movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow);
                }
            }
        }

        return false;
    }
}

document.onmouseup   = function(ev){
    if (currenttable && currenttable.dragObject) {
        var droppedRow = currenttable.dragObject;
        // If we have a dragObject, then we need to release it,
        // The row will already have been moved to the right place so we just reset stuff
        droppedRow.style.backgroundColor = '#FFFFFF';
        currenttable.dragObject   = null;
        // And then call the onDrop method in case anyone wants to do any post processing
        currenttable.onDrop(currenttable.table, droppedRow);
        currenttable = null; // let go of the table too
    }
}


function getEventSource(evt) {
    if (window.event) {
        evt = window.event; // For IE
        return evt.srcElement;
    } else {
        return evt.target; // For Firefox
    }
}

function TableDnD() {
    this.dragObject = null;
    this.mouseOffset = null;
    this.table = null;
    this.oldY = 0;


    this.init = function(table) {
        this.table = table;
        var rows = table.tBodies[0].rows; //getElementsByTagName("tr")
        for (var i=0; i<rows.length; i++) {
			var nodrag = rows[i].getAttribute("NoDrag")
			if (nodrag == null || nodrag == "undefined") { //There is no NoDnD attribute on rows I want to drag
				this.makeDraggable(rows[i]);
			}
        }
    }

    this.onDrop = function(table, droppedRow) {
    }

    this.getPosition = function(e){
        var left = 0;
        var top  = 0;
		if (e.offsetHeight == 0) {
			e = e.firstChild; // a table cell
		}

        while (e.offsetParent){
            left += e.offsetLeft;
            top  += e.offsetTop;
            e     = e.offsetParent;
        }

        left += e.offsetLeft;
        top  += e.offsetTop;

        return {x:left, y:top};
    }

    this.mouseCoords = function(ev){
        if(ev.pageX || ev.pageY){
            return {x:ev.pageX, y:ev.pageY};
        }
        return {
            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    }

    this.getMouseOffset = function(target, ev){
        ev = ev || window.event;

        var docPos    = this.getPosition(target);
        var mousePos  = this.mouseCoords(ev);
        return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
    }


    this.makeDraggable = function(item) {
        if(!item) return;
        var self = this;
        item.onmousedown = function(ev) {
            var target = getEventSource(ev);
            if (target.tagName == 'INPUT' || target.tagName == 'SELECT') return true;
            currenttable = self;
            self.dragObject  = this;
            self.mouseOffset = self.getMouseOffset(this, ev);
            return false;
        }
        item.style.cursor = "move";
    }

    this.findDropTargetRow = function(y) {
        var rows = this.table.tBodies[0].rows;
		for (var i=0; i<rows.length; i++) {
			var row = rows[i];
			var nodrop = row.getAttribute("NoDrop");
			if (nodrop == null || nodrop == "undefined") {
				var rowY    = this.getPosition(row).y;
				var rowHeight = parseInt(row.offsetHeight)/2;
				if (row.offsetHeight == 0) {
					rowY = this.getPosition(row.firstChild).y;
					rowHeight = parseInt(row.firstChild.offsetHeight)/2;
				}
				if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
					return row;
				}
			}
		}
		return null;
	}
}

function listProducts(id,categoryFormat,productFormat,nav,showImages,searchGo,noLoading,startList,listNum,searchOn,pgo){

	if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == '' && Trim($('searchInput').value) == ''){
		$('searchInput').value = '';
		//return;
	}
	if(!$('loadingDiv') && noLoading != 1){loading('controlPanel');}

	if(nav == 'next'){
		var startList = Number($('endList').innerHTML) + 1;
		$('startListCategory').innerHTML = startList;
	}else if(nav == 'back'){
		var startList = Number($('startList').innerHTML) - Number($('listNum').value);
		if(startList < 1){startList = 1;};
		$('startListCategory').innerHTML = startList;
	}else if((startList && startList != '') && (listNum && listNum != '')){
		var startList = startList;
		var listNum = listNum;
//		alert('startList:'+startList+'\nlistNum:'+listNum);
	}else{
		if($('totalList') && $('listNum').value > Number($('totalList').innerHTML)){
			var startList = 1;
			$('startListCategory').innerHTML = startList;
		}else if($('startListCategory')){
			var startList = $('startListCategory').innerHTML;
		}else if(startList){
		}else{
			var startList = 1;
		}
		
	}

	if(!categoryFormat || categoryFormat == ''){var categoryFormat = '';}
	if(!productFormat || productFormat == ''){var productFormat = '';}	
	if(!showImages || showImages == ''){var showImages = '';}

	if($('listNum') && !listNum){var listNum = $('listNum').value;}else if(!listNum){var listNum = '';}

if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == '' && searchGo == 1){
	if(Trim($('searchInput').value) == startSearch){
		var searchInput = '';
	}else{
		var searchInput = cleanValue(Trim($('searchInput').value));
	}
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=populatePage&categoryFormat='+categoryFormat+'&productFormat='+productFormat+'&listNum='+listNum+'&startList='+startList+'&showImages='+showImages+'&search='+searchInput; //+'&sort='+colSort+'&changeCategory='+categoryChange;
	if(id && id != ''){url = url+'&CatId='+id;}else{url = url+'&CatId=';}
//	if($('advancedSearchDiv') && $('advancedSearchDiv').style.display == ''){url = url+'&advancedSearch=1';}
}else{
	if(!pgo){var pgo = '';}
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=populatePage&CatId='+id+'&categoryFormat='+categoryFormat+'&productFormat='+productFormat+'&listNum='+listNum+'&startList='+startList+'&showImages='+showImages+"&pgo="+pgo;
}
//$('productContent').innerHTML = $('productContent').innerHTML + '<br><br><br><br>' + url;
//if($('divIP').innerHTML == '75.110.135.86'){alert(url);}
if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}

	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){listProductsRsp(id,url,searchGo,searchOn,searchInput)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function listProductsRsp(id,url,searchGo,searchOn,searchInput){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
	//if($('divIP').innerHTML == '75.110.135.86'){alert(xmlHttp.responseText);}
	if($('loadingDiv')){loading();}
	var theGoods = xmlHttp.responseText.split('|-|');
	//$('productContent').innerHTML = xmlHttp.responseText;			
	
	$('controlPanel').innerHTML = theGoods[0];

	if(searchOn == 'yes'){smartSearch('product','','','noSearchOn');}
//	$('categoryMenu').style.display = 'none';	
//	$('listNumResults').innerHTML += "<br><br>"+url+"<br><br>";			


	if($('smartSearchFrontEnd') && $('smartSearchFrontEnd').style.display == '' && searchGo == 1){
		if($('pageTitle') && $('searchTitle') && searchInput != ""){$('pageTitle').style.display = 'none';$('searchTitle').style.display = '';}
		if($('searchLimits')){$('searchLimits').style.display = '';}
	}
		
	if(theGoods[3]>0){
		$('tdRight').style.display = 'none';
		$('tdCenter').style.width = '100%';

		if(theGoods[1] == 1){
			$('arrowLt').src = rootdomain+'RootImages/arrow_lt_gray.gif';
			$('arrowLtSpan').style.cursor = 'auto';
			$('arrowLtSpan').onclick = '';
			$('arrowLtSpan').title = '';
		}else{
			$('arrowLt').src = rootdomain+'RootImages/arrow_lt.gif';
			$('arrowLtSpan').onclick = function(){listProducts(id,'','','back','',searchGo)};
			$('arrowLtSpan').style.cursor = 'pointer';			
			$('arrowLtSpan').title = 'View the previous group of items';
		}
		if(theGoods[2] == theGoods[3]){
			$('arrowRt').src = rootdomain+'RootImages/arrow_rt_gray.gif';
			$('arrowRtSpan').style.cursor = 'auto';
			$('arrowRtSpan').onclick = '';			
			$('arrowRtSpan').title = '';			
		}else{
			$('arrowRt').src = rootdomain+'RootImages/arrow_rt.gif';
			$('arrowRtSpan').onclick = function(){listProducts(id,'','','next','',searchGo)};
			$('arrowRtSpan').style.cursor = 'pointer';			
			$('arrowRtSpan').title = 'View the next group of items';
		}

		if(theGoods[4] == 'list' && $('listProductsList')){
			$('listProductsList').src = rootdomain+'RootImages/listProductsListGray.gif';
			$('listProductsList').style.cursor = 'auto';
			$('listProductsList').onclick = '';			
			$('listProductsList').title = '';			
	
			$('listProductsTable').src = rootdomain+'RootImages/listProductsTable.gif';
			$('listProductsTable').style.cursor = 'pointer';

			if(theGoods[8] == 'Products'){
				$('listProductsTable').onclick = function(){listProducts(id,'','table','','',searchGo);};
			}else{
				$('listProductsTable').onclick = function(){listProducts(id,'table','','','',searchGo);};
			}
			$('listProductsTable').title = 'Display items in a table';			
	//		if($('divIP').innerHTML == '75.110.135.86'){alert('list: '+ id);}
			
		}else if(theGoods[4] == 'table'){
			$('listProductsList').src = rootdomain+'RootImages/listProductsList.gif';
			$('listProductsList').style.cursor = 'pointer';

		if(theGoods[8] == 'Products'){
			$('listProductsList').onclick = function(){listProducts(id,'','list','','',searchGo)};
		}else{
			$('listProductsList').onclick = function(){listProducts(id,'list','','','',searchGo)};
		}
			$('listProductsList').title = 'Display items in a list';			
			
			$('listProductsTable').src = rootdomain+'RootImages/listProductsTableGray.gif';
			$('listProductsTable').style.cursor = 'auto';
			$('listProductsTable').onclick = '';
			$('listProductsTable').title = '';			
	//		if($('divIP').innerHTML == '75.110.135.86'){alert('table: '+ id);}
		}		
		if(theGoods[5] == 'yes'){
			$('showImages').src = rootdomain+'RootImages/cameraGray.gif';
			$('showImages').style.cursor = 'pointer';
			$('showImages').onclick = function(){listProducts(id,'','','','no',searchGo)};;			
			$('showImages').title = 'Hide images';						
		}else if(theGoods[5] == 'no'){
			$('showImages').src = rootdomain+'RootImages/camera.gif';
			$('showImages').style.cursor = 'pointer';
			$('showImages').onclick = function(){listProducts(id,'','','','yes',searchGo)};
			$('showImages').title = 'Show images';			
		}
	}else{
		$('tdRight').style.display = '';
		$('tdCenter').style.width = '567px';
	}//end if(theGoods[1] >0 )
	
	productFeatures(id,1);
	$('compareProducts').style.display = "";
	}
}

function productFeatures(id,searchOn){
	if(searchOn != 1){var searchOn = 0;}
	if(!$('loadingDiv') && $('controlPanel')){loading('controlPanel');}
	var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=productFeatures&CatId='+id+"&searchOn="+searchOn;
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
//	alert(url);
//	if($('divIP').innerHTML == '75.110.135.86'){alert(url);}
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){productFeaturesRsp(id)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function productFeaturesRsp(id){
//alert(xmlHttp.readyState+'\n\n'+xmlHttp.status);
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){

//	if($('divIP').innerHTML == '75.110.135.86'){alert(xmlHttp.responseText);}

	if($('loadingDiv')){loading();}
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			if($('productFeatures')){
				$('productFeaturesTitle').innerHTML = "Search Options";
				$('productFeaturesGroups').innerHTML = theGoods[1];
				$('categoryMenu').innerHTML = theGoods[2];
				if(theGoods[1] != ''){$('productFeatures').style.display = "";}

				divHeight('templateLeftDiv','productListHeight',-220)	
			}
		}//end if(theGoods[1] >0 )
	}
}

function compareProducts(id,mode){
	if(mode == 'compare'){
		if(Number($('compareProductsNum').innerHTML) == 0){	
			alert("Compare products by selecting the checkbox next to the product's name.");
			return;	
		}else if(Number($('compareProductsNum').innerHTML) == 1){	
			alert("Please select more than one product to compare.");
			return;
		}
		listProducts('compare','','list');
		$('smartSearchFrontEnd').style.display = 'none';
//		$('compareSubmitSide').style.display = 'none';
		return;
	}else if(id != ''){
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=compareProducts&ProductId='+id;
	}else{
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=compareProducts&ProductId=';
	}
	if(!$('loadingDiv') && $('controlPanel')){loading('controlPanel');}
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
//	if($('divIP').innerHTML == '75.110.135.86'){alert(url);}
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){compareProductsRsp(id,mode)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function compareProductsRsp(id,mode){
//alert(xmlHttp.readyState+'\n\n'+xmlHttp.status);
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
//	if($('divIP').innerHTML == '75.110.135.86'){alert(xmlHttp.responseText);}
	if($('loadingDiv')){loading();}
		var theGoods = xmlHttp.responseText.split('|');

		if(theGoods[0] == 1){
			$('compareProducts').style.display = '';	
			$('compareProductsDiv').innerHTML = theGoods[1];
			if(mode == 'remove' && $('compare'+id) && $('compare'+id).checked == true){
				$('compare'+id).checked = false;
			}else if($('pageTitle').innerHTML == 'Compare Products'){
				listProducts('compare','','list');
			}
			if($('pageTitle').innerHTML == 'Compare Products' && $('compareProductsNum').innerHTML == 1){resetPage();}
		}else if(theGoods[0] == 2){
			alert("You have reached the maximum number of products you're able to compare at one time.  Please limit your selections to four products.  Thank you");
			if($('compare'+id)){$('compare'+id).checked = false;}
			return;	
		}else{
			$('compareProductsDiv').innerHTML = "Compare products by selecting the checkbox next to the product's name.<div id='compareProductsNum' style='display:none'>0</div>";
			var el = document.getElementsByTagName('input');
			for(i=0;i<el.length;i++){if(el[i].type == 'checkbox' && el[i].checked == true){el[i].checked = false;}}
			if($('pageTitle').innerHTML == 'Compare Products'){resetPage();}
		}
		divHeight('templateLeftDiv','productListHeight',-220)
	}
}


function resetPage(){
//	$('smartSearchFrontEnd').style.display = 'none';	
	if($('searchInput')){$('searchInput').value = startSearch;}
	searchOn('reload');
//	if($('searchResetId') && $('searchResetId').innerHTML != ''){
//		listProducts($('searchResetId').innerHTML);
//	}else if($('searchResetId')){
//		location.reload(true);
//  }	
}

function searchOn(action){
	if($('CategoryType') && $('CategoryType').value == 'Products'){//categoryManagement
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=searchOn&action='+action;
	}else{
		var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=searchOn&action='+action;
	}
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
//	alert(url);	
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){searchOnRsp(action)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function searchOnRsp(action){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
			//alert(theGoods[0]);
			if(action == 'reload'){
				//alert(location.href);
				location.reload(true);
			}
	}
}

function advancedSearchFn(PricingGroupId,PricingGroupOptionId,action){
	if($('CategoryType') && $('CategoryType').value == 'Products'){//categoryManagement
		if(action == 'removeAdvanced'){
			$('advancedTitle').onclick = function(){advancedSearchFn('','');}
			$('advancedSearchDiv').parentNode.removeChild($('advancedSearchDiv'));
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=removeAdvanced';
		}else if(action && (action == 'include' || action == 'exclude' || action == 'remove' )){
			if(!PricingGroupOptionId){var PricingGroupOptionId = $('searchPricingGroupOptions').value;}
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=storeSearchLimits&PricingGroupId='+PricingGroupId+'&PricingGroupOptionId='+PricingGroupOptionId+'&action='+action;
		}else if(action && (action == 'returnSearchLimits')){
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=returnSearchLimits';
		}else if($('searchPricingGroups') && $('searchPricingGroups').value != ''){
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=searchPricingGroupOptions&PricingGroupId='+$('searchPricingGroups').value;
			//$('applySearchLimit').style.display = 'none';
		}else{	
			var advancedSearchDiv = document.createElement('div');
			advancedSearchDiv.id = 'advancedSearchDiv';
			advancedSearchDiv.style.display = '';
			advancedSearchDiv.style.width = '100%';
			//advancedSearchDiv.style.border = '1px solid black';
			$('searchDiv').appendChild(advancedSearchDiv);
	
			var advancedSearchTitle = document.createElement('div');
			advancedSearchTitle.innerHTML = 'Select a product characteristic to further limit your search:';
			advancedSearchTitle.style.fontSize = '11px';
			advancedSearchTitle.style.marginTop = '2px';
			advancedSearchTitle.style.marginBottm = '2px';
			$('advancedSearchDiv').appendChild(advancedSearchTitle);
		
			var searchPricingGroupsDiv = document.createElement('div');
			searchPricingGroupsDiv.id = 'searchPricingGroupsDiv';
			$('advancedSearchDiv').appendChild(searchPricingGroupsDiv);

			//$('advancedSearchDiv').onclick = function(){advancedSearchFn('','','removeAdvanced')}
			
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=categoryManagement.php&mode=searchPricingGroups';
		}
	
	}else if($('smartSearchFrontEnd') && ($('advancedSearchDiv') || showAdvancedSearchOption == 0)){
		if(action == 'removeAdvanced'){
//			$('smartSearchFrontEnd').style.height = '68px';
			$('advancedSearchDiv').style.display = 'none';
			if($('searchLimits')){$('searchLimits').style.display = 'none';}
			if($('searchPricingGroups')){$('searchPricingGroups').innerHTML = '';}
			if($('searchPricingGroupOptions')){$('searchPricingGroupOptions').innerHTML = '';}
			if($('advancedTitle')){$('advancedTitle').innerHTML = 'Advanced';$('advancedTitle').onclick = function(){advancedSearchFn('','');}}
							
			searchOn('removeAdvanced');
			if(Trim($('searchInput').value) != '' && $('searchInput').value != startSearch){
				listProducts('','','','','',1);
			}
			return;
		}
//		$('advancedSearchDiv').style.display = '';
		if($('searchLimits')){$('searchLimits').style.display = '';}

		if($('advancedTitle')){
			$('advancedTitle').innerHTML = 'Close Advanced';
			$('advancedTitle').onclick = function(){advancedSearchFn('','','removeAdvanced');}
		}
	
/*		if(showAdvancedSearchOption == 1){
			$('smartSearchFrontEnd').style.height = 200+'px';	
		}else{
			$('smartSearchFrontEnd').style.height = 180+'px';	
		}
*/
		if(action && (action == 'include' || action == 'exclude' || action == 'remove')){
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=storeSearchLimits&PricingGroupId='+PricingGroupId+'&PricingGroupOptionId='+PricingGroupOptionId+'&action='+action;
			if(action != 'remove'){
				//$('smartSearchFrontEnd').style.height = Number($('smartSearchFrontEnd').style.height.replace(/px/g,'')) + 65+'px';
			}
		}else if((PricingGroupId && PricingGroupId != '') && (PricingGroupOptionId && PricingGroupOptionId != '')){
		
			if(showAdvancedSearchOptionExclusive == 1){
			//	$('smartSearchFrontEnd').style.height = Number($('smartSearchFrontEnd').style.height.replace(/px/g,'')) + 65+'px';
				//$('applySearchLimit').style.display = '';
				var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=searchShowApply&PricingGroupId='+PricingGroupId+'&PricingGroupOptionId='+PricingGroupOptionId;
			}else{
				var action = 'include';
				var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=storeSearchLimits&PricingGroupId='+PricingGroupId+'&PricingGroupOptionId='+PricingGroupOptionId+'&action='+action;
		
			}
			for(iCnt=0;iCnt<document.getElementsByTagName('div').length;iCnt++){
				if(	document.getElementsByTagName('div')[iCnt].id.indexOf('PricingGroupOptionId-') != -1 	){
					document.getElementsByTagName('div')[iCnt].style.fontWeight = 'normal';
				}
			}
			//$('PricingGroupOptionId-'+PricingGroupOptionId).style.fontWeight = 'bold';
		}else if(PricingGroupId && PricingGroupId != ''){
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=searchPricingGroupOptions&PricingGroupId='+PricingGroupId;
			$('applySearchLimit').style.display = 'none';
			for(iCnt=0;iCnt<document.getElementsByTagName('div').length;iCnt++){
				if(	document.getElementsByTagName('div')[iCnt].id.indexOf('PricingGroupId-') != -1 	){
					document.getElementsByTagName('div')[iCnt].style.fontWeight = 'normal';
				}
			}
			$('PricingGroupId-'+PricingGroupId).style.fontWeight = 'bold';
		
		}else{
			$('applySearchLimit').style.display = 'none';
			var url = rootdomain + 'RootControlpanel/phpScript.php?req=RootStore.php&mode=searchPricingGroups';
		}		
	}
//	if($('divIP').innerHTML == '75.110.135.86'){alert(url);}
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	xmlHttp=GetXmlHttpObject(); // prevent infinite loop by not including url
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){advancedSearchFnRsp(PricingGroupId,PricingGroupOptionId,action)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function advancedSearchFnRsp(PricingGroupId,PricingGroupOptionId,action){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
//		if($('divIP').innerHTML == '75.110.135.86'){alert(xmlHttp.responseText);}
		//alert(PricingGroupId+'\n'+PricingGroupOptionId+'\n'+action);
		if($('loadingDiv')){loading();}
		var theGoods = xmlHttp.responseText.split('|');
	
	if($('CategoryType') && $('CategoryType').value == 'Products'){
		if(action && (action == 'include' || action == 'exclude' || action == 'remove')){
			if($('searchPricingGroupOptions')){
				$('searchPricingGroupOptions').parentNode.removeChild($('searchPricingGroupOptions'));
				$('searchPricingGroups').selectedIndex = 0;
			}
			advancedSearchFn('','','returnSearchLimits');
			return;
		}else if(action && (action == 'returnSearchLimits')){
			$('searchLimits').innerHTML = theGoods[0];
			populateSmartSearch('categoryManagement',$('CatId').innerHTML,'','','category');
		}else if($('searchPricingGroups') && $('searchPricingGroups').value != ''){
			if(!$('searchPricingGroupOptionsDiv')){
				var searchPricingGroupOptionsDiv = document.createElement('div');
				searchPricingGroupOptionsDiv.id = 'searchPricingGroupOptionsDiv';
				$('advancedSearchDiv').appendChild(searchPricingGroupOptionsDiv);
				$('searchPricingGroupOptionsDiv').innerHTML = theGoods[0];
		
				var searchLimits = document.createElement('div');
				searchLimits.id = 'searchLimits';
				$('advancedSearchDiv').appendChild(searchLimits);
			}else{
				$('searchPricingGroupOptionsDiv').innerHTML = theGoods[0];		
			}
		}else{
			$('searchPricingGroupsDiv').innerHTML = theGoods[0];
		}
		resizePopBox();
	}else{
	
		if(action && (action == 'include' || action == 'exclude' || action == 'remove')){
			$('applySearchLimit').innerHTML = '';

			/*if(showAdvancedSearchOption == 1){
				$('smartSearchFrontEnd').style.height = 200+'px';
			}else{
				$('smartSearchFrontEnd').style.height = 180+'px';	
			}
			*/
			listProducts('','','','','',1);
		}else if((PricingGroupId && PricingGroupId != '') && (PricingGroupOptionId && PricingGroupOptionId != '')){
			$('applySearchLimit').innerHTML = theGoods[0];
		}else if(PricingGroupId && PricingGroupId != ''){
			$('searchPricingGroupOptions').innerHTML = theGoods[0];
			var wndo4 = new dw_scrollObj('wn4', 'lyr4');	
		}else{
//			$('searchPricingGroups').innerHTML = theGoods[0];
			var wndo2 = new dw_scrollObj('wn2', 'lyr2');	
			if(action != 'noSearch' && Trim($('searchInput').value) != '' && $('searchInput').value != startSearch){
				//listProducts('','','','',1,'');
			}
		}
		//productFeatures('',1);
	}
	}
}

function changeImg(img){
	$('defaultImg').src = img;	
}

function fnOnLoad(type){
	if(type == 'category'){
		if($('exampleDoc')){
			$('exampleDoc').href = rootdomain+"/RootControlpanel/generateReport.php?type="+type+"&mode=upload&example=1";
		}
		if($('exampleDoc2')){
			$('exampleDoc2').href = rootdomain+"/RootControlpanel/generateReport.php?type="+type+"&mode=upload&example=1";
		}
	}else{ 
		if($('exampleDoc')){
			$('exampleDoc').href = rootdomain+"/RootControlpanel/generateReport.php?type="+type+"&mode=upload&example=1";
		}
		if($('exampleDoc1')){
			$('exampleDoc1').href = rootdomain+"/RootControlpanel/generateReport.php?type=group&mode=upload&example=1";
		}
		if($('exampleDoc2')){
			$('exampleDoc2').href = rootdomain+"/RootControlpanel/generateReport.php?type=option&mode=upload&example=1";
		}
		if($('exampleDoc3')){
			$('exampleDoc3').href = rootdomain+"/RootControlpanel/generateReport.php?type="+type+"&mode=upload&example=1";
		}
		if($('exampleDoc4')){
			$('exampleDoc4').href = rootdomain+"/RootControlpanel/generateReport.php?type=group&mode=upload&example=1";
		}
		if($('exampleDoc5')){
			$('exampleDoc5').href = rootdomain+"/RootControlpanel/generateReport.php?type=option&mode=upload&example=1";
		}
	} 
	resizePopBox();
}


function uploadSelect(type){
	$('showUploadForm').style.display = '';		
	if ($('uploadSelectAction').value == 'Products'){
		document.thisForm.type.value = 'product';
		$('addToSpan').innerHTML = 'Products';
		$('replaceSpan').innerHTML = 'Products';
		$('showUploadFieldNamesProducts').style.display = '';		
		$('showUploadFieldNamesPricingGroups').style.display = 'none';				
		$('showUploadFieldNamesPricingGroupOptions').style.display = 'none';								
		if($('uploadWarning') && Trim($('uploadWarning').innerHTML) != ''){return StartUpload(type,'','xls', $('uploadSelectAction').value);}
	}else if($('uploadSelectAction').value == 'Groups'){
		document.thisForm.type.value = 'group';
		$('addToSpan').innerHTML = 'Product Characteristics';
		$('replaceSpan').innerHTML = 'Product Characteristics';
		$('showUploadFieldNamesProducts').style.display = 'none';		
		$('showUploadFieldNamesPricingGroups').style.display = '';				
		$('showUploadFieldNamesPricingGroupOptions').style.display = 'none';		
		if($('uploadWarning') && Trim($('uploadWarning').innerHTML) != ''){return StartUpload(type,'','xls', $('uploadSelectAction').value);}
	}else if($('uploadSelectAction').value == 'Options'){
		document.thisForm.type.value = 'option';
		$('addToSpan').innerHTML = 'Options for Product Characteristics';
		$('replaceSpan').innerHTML = 'Options for Product Characteristics';
		$('showUploadFieldNamesProducts').style.display = 'none';		
		$('showUploadFieldNamesPricingGroups').style.display = 'none';				
		$('showUploadFieldNamesPricingGroupOptions').style.display = '';
		if($('uploadWarning') && Trim($('uploadWarning').innerHTML) != ''){return StartUpload(type,'','xls', $('uploadSelectAction').value);}
	}else if($('uploadSelectAction').value == 'Direct'){
		document.thisForm.type.value = 'direct';
		$('addToSpan').innerHTML = 'Options for Direct Upload';
		$('replaceSpan').innerHTML = 'Options for Direct Upload';
		$('showUploadFieldNamesProducts').style.display = 'none';		
		$('showUploadFieldNamesPricingGroups').style.display = 'none';				
		$('showUploadFieldNamesPricingGroupOptions').style.display = '';
		if($('uploadWarning') && Trim($('uploadWarning').innerHTML) != ''){return StartUpload(type,'','xls', $('uploadSelectAction').value);}
	}
}

function showItem(el){
	if($(el) && ($(el).style.display == 'none' || $(el).style.display == '')){
		$(el).style.display = 'block';
		if(el == 'menuCompanyInformation'){$('companyInformation').style.color = '#8DB55F';}
		if(el == 'menuServices'){$('services').style.color = '#8DB55F';}
		if(el == 'menuGovernmentSales'){$('governmentSales').style.color = '#8DB55F';}		
	}else if($(el) && $(el).style.display == 'block'){
		$(el).style.display = 'none';		
		if(el == 'menuCompanyInformation'){$('companyInformation').style.color = '#FFFFFF';}
		if(el == 'menuServices'){$('services').style.color = '#FFFFFF';}
		if(el == 'menuGovernmentSales'){$('governmentSales').style.color = '#FFFFFF';}				
	}
}

function showElement(el){
	if($(el).style.display == ''){
		$(el).style.display = 'none';
	}else{
		$(el).style.display = '';
	}
	divHeight('templateLeftDiv','productListHeight',-220)
}

function subText(id,arg1,arg2){
	if($(id) && $(id).innerHTML == arg2){
		$(id).innerHTML = arg1;
	}else if($(id)){
		$(id).innerHTML = arg2;
	}
}

function sendMail(request){
var form = document.thisForm;
if($('nameWarning')){$('nameWarning').style.display = 'none';}
if($('emailWarning')){$('emailWarning').style.display = 'none';}
if($('phoneWarning')){$('phoneWarning').style.display = 'none';}
if($('commentsWarning')){$('commentsWarning').style.display = 'none';}
if($('emailPanelWarning')){$('emailPanelWarning').style.display = 'none';}

if(form.txtName && form.txtName.value == ''){	$('nameWarning').style.display = '';return false;}
if(form.txtEmail && form.txtEmail.value == ''){ $('emailWarning').style.display = '';$('emailWarning').innerHTML = '- Please insert your email';return false;}
if(form.txtEmail && validate(form.txtEmail.value,'email') == false){$('emailWarning').style.display = '';$('emailWarning').innerHTML = '- Please insert a valid email';return false;}
//if(form.txtPhone.value == ''){ $('phoneWarning').style.display = '';return false;}
//if(form.txtComments.value == ''){	$('commentsWarning').style.display = '';return false;}

if(request && request == 'IP'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=local-resources.php";
}else if(request && request == 'productComparison'){
	var url=rootdomain+"RootControlpanel/phpScript.php?req=RootStore.php&mode=populatePage&CatId=compare&type=productComparisonEmail";
}else{
	var url=rootdomain+"RootControlpanel/phpScript.php?req=contact-us.php";
}
for (i = 0; i < form.elements.length; i++) {
	var elName = form.elements[i].name;
	var elValue = cleanValue(form.elements[i].value);		
	url=url+"&"+elName+"="+elValue;
} //end for(

url=url+"&sid="+Math.random();

	if(!document.getElementById('loadingDiv')){loading('emailPanel');}
//	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){sendMailRsp(request)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function sendMailRsp(request){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			if(request && request == 'IP'){
				$('emailPanel').innerHTML = '<div>Your request has been sent successfully. Thank you for your comments.  We will be in touch with you, shortly.</div>';
			}else if(request && request == 'productComparison'){				
				$('emailPanelWarning').style.display = '';
				$('emailPanelWarning').innerHTML = '<div style="font-weight:normal;margin-top:4px;">Your email has been sent successfully. Please feel free to <a style="font-size:12px;color:#ff0000;" href=\''+rootdomain+'contact-us.php\'>contact us</a> with any questions you may have.</div></div>';
				$('emailComparisonTitle').style.display = '';				
				$('emailComparisonInput').style.display = 'none';
				$('txtEmail').value = 'email address';
			}else{
				$('emailPanel').innerHTML = '<div>Your request has been sent successfully. Thank you for your comments.  We will be in touch with you, shortly.</div>';	
			}
			
		}else{
			if(request && request == 'productComparison'){							
				$('emailPanelWarning').style.display = '';
				$('emailPanelWarning').innerHTML = '<div style="font-weight:normal;">Unfortunately, your email was not sent. There appears to be a problem with this form.  Please feel free to <a style="font-size:12px;color:#ff0000;" href=\''+rootdomain+'contact-us.php\'>contact us</a> with any questions you may have.</div>';			
			}else{
				$('emailPanelWarning').style.display = '';
				$('emailPanelWarning').innerHTML = '<div>Unfortunately, your email was not sent. There appears to be a problem with this form.  Please contact us using the information above.</div>'			
				
			}
		}
	}
}

function fnNewsletter(){
	$('newsletterWarning').innerHTML = '';
	$('newsletterWarning').style.display = 'none';	
	if ($('emailNewsletter').value == '' || $('emailNewsletter').value == 'Email Address'){
		$('newsletterWarning').innerHTML = 'Please provide an email address';
		$('newsletterWarning').style.display = '';		
		$('emailNewsletter').focus();
		return;
	}else if (validate($('emailNewsletter').value, 'email') == false){
		$('newsletterWarning').innerHTML = 'Please provide a valid email address';
		$('newsletterWarning').style.display = '';		
		$('emailNewsletter').focus();
		return;
	}

	var url=rootdomain+"RootControlpanel/phpScript.php?req=newsletter&email="+cleanValue($('emailNewsletter').value);
	url=url+"&sid="+Math.random();

	if(!document.getElementById('loadingDiv')){loading('controlPanel');}
//	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){alert("Your browser does not support AJAX!");return;} 
	xmlHttp.onreadystatechange=function(){fnNewsletterRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function fnNewsletterRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		
//		if(theGoods[0] == 1){
			$('newsletterDiv').innerHTML = '<div style=\'text-align:center;\'>Thank you. Your address has been added to our mailing list.</div>';	
/*		}else{
			$('newsletterDiv').innerHTML = '<div style=\'text-align:center;\'>There was an error adding ' + theGoods[1] + ' to the Daughtridge Sales mailing list. Please <a style=\'font-size:12px;\' href=\''+rootdomain+'/contact-us.php\'>contact us</a></div>';	
		}
*/		

	}
}

function divHeight(clone,div,delta){
	if(!$(clone) || !$(div)){return;}
	var newHeight = Number($(clone).offsetHeight) + delta;
	if(div == 'productListHeight' && $(div).offsetHeight < newHeight){
		$('productListHeightInnerDiv').style.height = newHeight +'px';
	}
	$(div).style.height = newHeight +'px';	
	window.onresize = function(){ divHeight('templateLeftDiv','productListHeight',-220); }
}

function tonsOnRam(el){
	if(el == "tonsOnRam" || el == "ramSize"){
		 var properPsi = (Number(stripNonNumeric($('tonsOnRam').value))*2000)/(0.7854*(Number(stripNonNumeric($('ramSize').value))*Number(stripNonNumeric($('ramSize').value))));
		 $('properPsi').innerHTML = properPsi.toFixed(2);
	}else if(el == "psiUsed" || el == "ramSize2"){
		 var properTonsOnRam = (Number(stripNonNumeric($('ramSize2').value)) * Number(stripNonNumeric($('ramSize2').value)) * 0.7854 * Number(stripNonNumeric($('psiUsed').value)) )/2000;
		 $('properTonsOnRam').innerHTML = properTonsOnRam.toFixed(2);
	}

}
