function ArrayDeleteAt(vArray, vPosition){
	var a2 = new Array();

	for (i=vPosition+1; i<vArray.length; i++){
		a2[a2.length] = vArray[i];
	}

	vArray.length = vPosition;
	vArray = vArray.concat(a2);
	return vArray;
}
		
function clearSearch(object,focus_event){
	if (focus_event && object.value == 'Search Here'){
		object.value='';
	}else if (!focus_event && object.value == ''){
		object.value='Search Here';
	}
}

function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=550,height=450');
	self.name = "mainWin";
}

function confirmModuleDelete(){
	var oTemp = event.srcElement;

	if (!confirm("Are you sure you want to delete this module?\n\nWARNING: This action can no be undone.")){
		return false;
	}

	document.location = oTemp.href;
}

function toggleDetails(i){
	var oTemp = document.getElementById('itemDetails'+i);
	if (oTemp.style.display == '' || oTemp.style.display == 'block') {

		oTemp.style.display = 'none';
		document.getElementById('details'+i).innerHTML = 'View Details'
	}
	else {
		oTemp.style.display = 'block';
		document.getElementById('details'+i).innerHTML = 'Hide Details'
	}
}

function showColorName(strIn){
	if (!strIn || strIn == '') { strIn = ' '; }
	document.getElementById('colorName').innerText = strIn;
}

function checkForm_compare(){
	if (document.formCompare.comparelist.value != ''){ return true;	}
	alert("Please select two to eight products to compare in the checkboxes below.");
	return false;
}

function buildcomparelist(vObject, domain){
	var vList = document.formsort.comparelist.value;
	if (vList == ''){
		var aList = new Array();
	}else{
		var aList = vList.split(',');
		vList = '';
	}

	if (!domain){ domain = 'airwheelchair.com'; }

	if (vObject.checked){
		//add
		if (aList.length == 0){
			//array is empty so add
			aList[aList.length] = vObject.value;
		}else if (aList.length >= 8){
			alert("Sorry, you can not compare more than eight products.");
			vObject.checked = false;
			return false;
		}else{
			for (i=0; i < aList.length; i++){
				if (vObject.value == aList[i]){
					return true;
				}
				aList[aList.length] = vObject.value;
				break;
			}
		}
	}else{
		for (i=0; i < aList.length; i++){
			if (vObject.value == aList[i]){
				aList = ArrayDeleteAt(aList,i);
				break;
			}
		}
	}
	
	for (i=0; i<aList.length; i++){
		vList += aList[i] + ',';
	}
	if (vList.length > 0){ vList = vList.substring(0,vList.length-1); }

	applyCompareList(vList, domain);
}

function clearCompareList(domain){
	var aObjects = document.getElementsByName('compareProduct');

	for (i=0; i < aObjects.length; i++){
		aObjects[i].checked = false;
	}
	
	applyCompareList('', domain);
}

function applyCompareList(vList, domain){
	document.formsort.comparelist.value = vList;
	document.formCompare.comparelist.value = vList;
	document.formCompare2.comparelist.value = vList;
	setCookie("COMPARE_LIST", vList, getExpirationDate(1), '/', domain);

	for (i=1; eval('document.all.pageLink'+i); i++){
		vObject = eval('document.all.pageLink'+i);

		aStrings = vObject.href.split('&');
		vObject.href = aStrings[0];
		for (x=1; x < aStrings.length; x++){
			if (aStrings[x].substring(0,13) != '&comparelist='){
				vObject.href += '&' + aStrings[x];
			}
		}

		vObject.href += '&comparelist=' + vList;
	}
}

function resortList(s){
	document.getElementById('formsort').sort.value = s;
	document.getElementById('formsort').submit();
}

function checkAllBrands(bAll){
	var aChecks = document.all.brandID;
	
	if (bAll && aChecks[0].checked){
		for (i=1; i < aChecks.length; i++)
			aChecks[i].checked = false;
	}else{
		var bAll = true;
		for (i=1; i < aChecks.length; i++){
			if (aChecks[i].checked){
				bAll = false;
				break;
			}
		}
		aChecks[0].checked = bAll;
	}
}

function formatNumber(num, decimalNum, bLeadingZero, bAddCommas){

	var tmpNum = num;
	var aTemp;

	tmpNum *= Math.pow(1000,decimalNum);
	tmpNum = Math.floor(tmpNum);
	tmpNum /= Math.pow(1000,decimalNum);

	var tmpStr = new String(tmpNum);

	if (!bLeadingZero && num < 1 && num > -1 && num !=0)
		if (num > 0)
			tmpStr = tmpStr.substring(1,tmpStr.length);
		else
			tmpStr = "-" + tmpStr.substring(2,tmpStr.length);

	aTemp = tmpStr.split(".");
	if (aTemp.length == 1){ aTemp[1] = ''; }
	while (aTemp[1].length < decimalNum){ aTemp[1] += 0; }
	tmpStr = aTemp[0] + '.' + aTemp[1];

	if (bAddCommas){
		aTemp = tmpStr.split('.');
		var nCommas = Math.floor((aTemp[0].length-1) / 3);
		for (i=nCommas;  i > 0; i--){
			p = aTemp[0].length - (3*i);
			aTemp[0] = aTemp[0].substring(0,p) + "," + aTemp[0].substring(p,aTemp[0].length);
		}
		tmpStr = aTemp[0] + '.' + aTemp[1]; 
	}

	return tmpStr;
}


function updatePrice(bOnLoad){
	var p1 = document.getElementById('price1');
	var p2 = document.getElementById('price2');
	var f = document.f_config;
	var m = 10000
	var x = 0;
	var total = CFV_salePrice * m;
	var lstConfig = '';
	var selObj;
	
	for (i=0; i < aConfigOptions.length; i++){
		x = 0;
		if (document.getElementById(aConfigOptions[i][0]).checked || document.getElementById(aConfigOptions[i][0]).selected){
			x = Math.round(parseFloat(aConfigOptions[i][1]) * m);
		}
		total += x;
	}

	total /= m;
	total = formatNumber(total, 2, false, true);

	p1.innerHTML = total;
	p2.innerHTML = total;

	if (!bOnLoad){
		setCookie("CONFIG_PRODUCTID", CFV_productID, getExpirationDate(1), '/', '<cfoutput>#Application.cookieDomain#</cfoutput>');
		setCookie("CONFIG_VALUES", lstConfig, getExpirationDate(1), '/', '<cfoutput>#Application.cookieDomain#</cfoutput>');
	}
}

function getExpirationDate(vDays){
	var tDate = new Date();
	fixDate(tDate);
	vDays *= 24 * 60 * 60 * 1000;
	tDate.setTime(tDate.getTime() + vDays);
}

function listAppend(lst, value){
	return lst + ((lst.length > 0)?',':'') + value;
}

function popDetails(which, fileID, linkLoc, productID){
	var vFilename;
	if (!productID)
	{
		var vQS = 'productID=' + CFV_productID;
	}
	else
	{
		var vQS = 'productID=' + productID;
	}
	
	if (which == 'file' || which == 'video'){
		vQS += '&fileID=' + fileID;
	}
	if (linkLoc){
		vQS += '&linkLoc=' + linkLoc;
	}

	switch(which){
		case 'specs':
			vFilename = 'pop_specs.cfm'; break;
		case 'image':
			vFilename = 'pop_image.cfm'; break;
		case 'warranty':
			vFilename = 'pop_warranty.cfm'; break;
		case 'photos':
			vFilename = 'pop_photos.cfm'; break;
		case 'reviews':
			vFilename = 'pop_reviews.cfm'; break;
		case 'file':
			vFilename = 'pop_files.cfm'; break;
		case 'colors':
			vFilename = 'pop_colors.cfm'; break;
		case 'video':
			vFilename = 'pop_video.cfm'; break;
		default:
			vFilename = 'specs';
	}

	w_details = window.open('/critpath/' + vFilename + '?' + vQS, 'w_popup', 'width=620,height=450,resizable=1,scrollbars=1');
}

function swapAltImage(indexIn){
	document.getElementById('altLarge').src = aAltImages[indexIn]["src"];
	document.getElementById('altImageText').innerText = aAltImages[indexIn]["altText"];
}

function UpdateTotal(){
	var oSelect;
	var oSpan_grandTotal = document.getElementById('grandTotal');
	var oSpan_shippingTotal = document.getElementById('shippingTotal');
	var m = 10000;
	var grandTotal = CFV_ITEMGRANDTOTAL * m;
	var shippingTotal = 0;
	var shippingTotal_ground = 0;
	var maxGroundShipping = 9.95 * m;
	
	if (CFV_bInternational){
		return true;
	}

	if (document.getElementById('shipping_flag_all')){
		aItemIDs.length = 1;
		aItemIDs[0] = '_all';
	}

	for (x=0; x < aItemIDs.length; x++){
		oSelect = document.getElementById('shipping_flag' + aItemIDs[x]);

		if (oSelect.options[oSelect.selectedIndex].shipMethod == 1){
			shippingTotal_ground += oSelect.options[oSelect.selectedIndex].price * m;
		}else{
			shippingTotal += oSelect.options[oSelect.selectedIndex].price * m;
		}
	}

	if (shippingTotal_ground > maxGroundShipping){
		shippingTotal_ground = maxGroundShipping;
	}

	shippingTotal += shippingTotal_ground;
	grandTotal = grandTotal + shippingTotal;

	oSpan_shippingTotal.innerText = formatNumber(shippingTotal/m, 2, false, true);
	oSpan_grandTotal.innerText = formatNumber(grandTotal/m, 2, false, true);
}

function certify(URL){
	popupWin = window.open(URL, 'Participant', 'location,scrollbars,width=400,height=300');
	window.top.name = 'opener';
}

function Uscribe(uwin){
	chartwin = window.open(uwin,"chartpage","width=375,height=175,toolbar=no,menubar=no,scrollbars=no,resizable=no,screenX=25,screenY=50,top=50,left=25");
	chartwin.focus();
	if (!chartwin.opener){
		chartwin.opener = "self";
	}
}