var prevObj ;
var orgBColor;

function HighLightTR(backColor){
	if (typeof(prevObj) != 'undefined')
		prevObj.bgColor=orgBColor;

	var currObj = event.srcElement;
	currObj = currObj.parentElement;
	orgBColor = currObj.bgColor;
	currObj.bgColor=backColor;

	prevObj = currObj;
}

function deletePubCode(id) {

	return confirm('Remove pub code ' + id + '?');
}

function deletePricePkg() {

	return confirm('Remove this category-specific field and all its associated category relationships?');
}


function displayHTMLFieldTypes() {
	var arr = new Array('checkbox', 'radio', 'text');
	var selectedField = '<%=RequestValue("fldhtmlType")%>';

	if (selectedField == '') selectedField = 'text';

	document.write('<select name="fldhtmlType">');
	for (i=0; i<arr.length; i++) {
		document.write('<option value="' + arr[i] + '"');
		if (arr[i] == selectedField) document.write(' selected');
		document.write('>' + arr[i] + '</option>');
	}
	document.write('</select>');
}

function uploadImage(sURL) {
		window.open(sURL, 'ImgUpld', 'width=500,height=600,location=0,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1');
}

function pageLoaded() {
	imgBlank = new Image;
	imgBlank.src = '/common_scripts/ads/Classifieds/XcCPImages/pix.gif';
	document.imgPleaseWait.src = imgBlank.src;
	document.imgProgressBar.src = imgBlank.src;
}



function displayNextLevel(lvl, id, bFormCompleted) {
	// - selection at previous level has changed
	// - data in <SELECT> objects at all levels from current down no longer valid
	// - disable <SELECT> objects and shrink frames
	var someLargeNum = 10;
	for (i=lvl; i<someLargeNum; i++) {
		if (frames['floatframe' + (i)] != null) {
			var objCatSelectorForm = frames['floatframe' + (i)].document.frmCatID;
			if (objCatSelectorForm != null && objCatSelectorForm.CatID != null) {
				objCatSelectorForm.CatID.disabled = true;
				document.all['floatframe'+i].height=1;
			}
		}
		else break;
	}

	// if the form is not yet completed (ie rootable category has not been reached),
	// we need to display categories for selection in the current frame
	if (frames['floatframe' + (lvl)] != null && !(bFormCompleted == 'True')) {
		frames['floatframe' + (lvl)].location.href='CatSelectorMsg.asp?level=' + lvl + '&id=' + id;
		document.all['floatframe'+lvl].height=210;
	}


	// if the form is completed (expl. see above), set the hidden form element on this page to "id",
	// and enable the "Next" button
	if (bFormCompleted == 'True') {
		document.frmCategories.catID.value = id;
		document.frmCategories.btnNext.disabled = false;
	} else {
		if (document.frmCategories.btnNext != null)
			document.frmCategories.btnNext.disabled = true;
	}


}


function addSymbol(symb) {
	document.placeAd.Description.value=document.placeAd.Description.value + symb;
}

function enforceWordLimit(oObj, limit) {
	var arrWords = (oObj.value).split(/\s+/g); // split the sentence into an array of words
	if (arrWords.length > limit+10) {
		alert("Limit of " + limit + " words exceeded.");
		oObj.value = arrWords.slice(0, limit+10).join(" ") + "...";
	}

}


function selectAll(objToSel) {
// belongs to Search.asp
	if (objToSel.type.indexOf("select-") != -1) {
		// <SELECT> object
		for (i=1; i<objToSel.length-1; i++)
			objToSel[i].selected = true;
		objToSel[0].selected = true;
		if (objToSel[objToSel.length-1].value != -1)
			objToSel[objToSel.length-1].selected = true;
	}

}

function checkSearchForm(oForm) {
// belongs to Search.asp
	if (oForm.RegionID.selectedIndex == -1)
		selectAll(oForm.RegionID);

	if (oForm.CategoryID.selectedIndex == -1)
		selectAll(oForm.CategoryID);
}

function verifyForm(oForm, bHasParent) {
//	var bClearAllPubs = true;
	var bClearAllPricePkgs = true;
	var bClearAllCatSpecFlds = true;


	if (eval(oForm.bFormSubmitted.value) == true) {
		alert('You have already submitted this page.  Please wait for the results.');
		return false;
	}
	oForm.bFormSubmitted.value = true;


	// Iterate thru the pub membership <SELECT> object.  If all elements
	// are selected, deselect them all to force the category to
	// inherit from its parent (all records for this category ID
	// will be removed from the CategoryParentPub table).
	// If it has no parent, leave it as is.
//	for (i=0; i<oForm.pubMember.length; i++)
//		if (!oForm.pubMember.options[i].selected) bClearAllPubs = false;
	// If all options are selected, and category has a parent then
	// default to parent's selection
//	if (bHasParent && bClearAllPubs) oForm.pubMember.selectedIndex=-1;



	// Iterate thru the price pkg membership <CHECKBOX> objects.  If all elements
	// are selected, deselect them all to force the category to
	// inherit from its parent (all records for this category ID
	// will be removed from the Prices table).
	// If it has no parent, leave it as is.
	if (oForm.pricePkgMember != null)
		for (i=0; i<oForm.pricePkgMember.length; i++)
			if (!oForm.pricePkgMember[i].checked) bClearAllPricePkgs = false;


	// Iterate thru the price pkg membership <CHECKBOX> objects.  If all elements
	// are selected, deselect them all to force the category to
	// inherit from its parent (all records for this category ID
	// will be removed from the Prices table).
	// If it has no parent, leave it as is.
	if (oForm.catSpecFld != null)
		for (i=0; i<oForm.catSpecFld.length; i++)
			if (!oForm.catSpecFld[i].checked) bClearAllCatSpecFlds = false;

	// If all options are selected, and category has a parent then
	// default to parent's selection w.r.t. price packages
	if (bHasParent && bClearAllPricePkgs)
		for (i=0; i<oForm.pricePkgMember.length; i++) oForm.pricePkgMember[i].checked=false;

	// If all options are selected, and category has a parent then
	// default to parent's selection w.r.t. cat-specific fields
	if ((oForm.catSpecFld != null) && bHasParent && bClearAllCatSpecFlds)
		for (i=0; i<oForm.catSpecFld.length; i++) oForm.catSpecFld[i].checked=false;
}


function deleteCategory(id) {

	result = confirm('Remove this category, all its sub-categories and all related ad info?');
	if (result) {
		document.frmManageCategories.bDeleteCategory.value = true;
		document.frmManageCategories.catIDForRemoval.value = id;
		document.frmManageCategories.submit();
	}
}


function togglePubMembers(oPubSelector) {

	var selectedIndex = oPubSelector.selectedIndex;

//document.frmManageCategories.pubMember.
	for (i=0; i<arrTemp.length; i++) {
		if (eval(arrTemp[i]) && i != selectedIndex) oPubSelector[i].selected = true;
		else if (i == selectedIndex) oPubSelector[i].selected = !(arrTemp[i]);
//		alert(arrTemp[i]);
	}

	for (i=0; i<oPubSelector.length; i++) {
//		alert(oPubSelector[i].selected);
//		arrTemp[i] = false;
		arrTemp[i] = oPubSelector[i].selected;
//		alert(arrTemp[i] + '!');
	}

}
function deletePricePkg(id) {

	return confirm('Remove this price package, all its associated category relationships?');
}


function ShowSimpleWindow(strURL){
	//CREATED BY NEIL RAMRATTAN
	//LAST UPDATE: 02/26/2001
	//this function creates a pop-up box to display the text for the Event Details
	var temp;

	temp = window.open(strURL, '');
	temp.focus();
}


function OpenWindow(url, width, height, scroll) {
	window.open(url, '', 'width=' + width + ',height=' + height + ',scrollbars=' + scroll);
}


var arrTemp = new Array();


// Used in XcCPAdmPackagesToUsers.asp
var btnSubmitClicked = false;


function PackagesToUsers_RefreshUserList() {
	search_value = document.forms['frmUsers'].searchName.value;

	search_type = document.forms['frmUsers'].userSrchType;
	for (i=0; i<search_type.length; i++) 
		if (search_type[i].checked) {
			search_type = search_type[i].value;
			break;
		}
	document.frames['frmUsers'].document.location.href = 
			'XcCPAdmDisplayUsers.asp?CMD=' + search_type + '&value=' + search_value
			
	document.forms['frmUsers'].searchName.focus();
}

function PackagesToUsers_DoSubmit() {
	if (document.forms['frmUsers'].userID.value == '') {
		alert('Please select a user.');
		btnSubmitClicked = false;
		return false;
	}

	var bPkgSelected = false;
	for (i=0; i<document.forms['frmUsers'].packageID.length; i++) 
		if (document.forms['frmUsers'].packageID[i].checked) {
			bPkgSelected = true;
			break;
		}
	if (!bPkgSelected) {
		alert('Please select a package.');
		return false;
	}
	
	if ((document.forms['frmUsers'].radCharge[0].checked == false) & (document.forms['frmUsers'].radCharge[1].checked == false)) {
		alert('Please select the billing mode.');
		btnSubmitClicked = false;
		return false;
	}
	
	btnSubmitClicked = true;
}

function PackagesToUsers_ClearSelectedUser() {
	if (document.forms[0].radUserID != null) {
		for (i=0; i<document.forms[0].radUserID.length; i++)
			document.forms[0].radUserID[i].checked = false;	
		parent.document.forms['frmUsers'].userID.value = '';
	}
}

function FitlerText(mode, text) {
	var re = /^\d+$/;
	var s = new String();
	//alert(text.replace(re, ""));
	for (i=0; i<text.length; i++) {
		if (!isNaN(text.substr(i,1)) && text.substr(i,1) != ' ') s += text.substr(i,1);
	}
	return s;
	//return (re.exec(text));
	//re.exec(
//	if (mode == 'DIGITS') {
//		if (character < 0 || character > 9) return false;	
//	}
}
/////////////////////////////////////////////////////////////////////////////




