
// ** WARNING ** //
// This function only works if the 'page' parameter is always set first, and 'cat' is always set last
function changeCat( intCat ) {
	
	var tmp = clearGet( "subcat" );
	var tmp2;
	
	// check for different url configurations
	if( tmp.indexOf( '?cat' ) != -1 ) {
		
		tmp = tmp.split("?cat");
		window.location = tmp[0]+"?cat="+intCat;
	
	} else if( tmp.indexOf( '&cat' ) != -1) {
		
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		window.location = tmp[0]+"?"+tmp2[0]+"&cat="+intCat;
	
	} else if( tmp.indexOf( '?' ) != -1) {
	
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		window.location = tmp[0]+"?"+tmp2[0]+"&cat="+intCat;
	
	} else {
	
		window.location = tmp+"?cat="+intCat;
	
	}
	
}

function changeGrp( intGrp ) {

	var tmp = window.location.href;
	var tmp2;
	
	// check for different url configurations
	if( tmp.indexOf( '?grp' ) != -1 ) {
		
		tmp = tmp.split("?grp");
		window.location = tmp[0]+"?grp="+intGrp;
	
	} else if( tmp.indexOf( '&grp' ) != -1) {
		
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		window.location = tmp[0]+"?"+tmp2[0]+"&grp="+intGrp;
	
	} else if( tmp.indexOf( '?' ) != -1) {
	
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		window.location = tmp[0]+"?"+tmp2[0]+"&grp="+intGrp;
	
	} else {
	
		window.location = tmp+"?grp="+intGrp;
	
	}
	
}

function changeSubCat( intCat ) {
	
	var tmp = window.location.href;
	var tmp2;
	
	// check for different url configurations
	if( tmp.indexOf( '?subcat' ) != -1 ) {
		
		tmp = tmp.split("?subcat");
		window.location = tmp[0]+"?subcat="+intCat;
	
	} else if( tmp.indexOf( '&subcat' ) != -1) {
		
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		tmp2.pop();
		
		if( tmp[1].indexOf( 'action=false' ) != -1) {
			window.location = tmp[0]+"?"+tmp2.join("&")+"&subcat="+intCat;
		} else {
			window.location = tmp[0]+"?"+tmp2.join("&")+"&action=false&subcat="+intCat;
		}
	
	} else if( tmp.indexOf( '?' ) != -1) {
		
		if( tmp.indexOf( 'action=false' ) != -1) {
			window.location = tmp+"&subcat="+intCat;
		} else {
			window.location = tmp+"&action=false&subcat="+intCat;
		}
	
	} else {
	
		window.location = tmp+"?subcat="+intCat;
	
	}
	
}

function clearGet( strName ) {

	var tmp = window.location.href;
	var tmp2;
	
	// check for different url configurations
	if( tmp.indexOf( '?'+strName ) != -1 ) {
		
		tmp = tmp.split("?"+strName);
		return tmp[0];
	
	} else if( tmp.indexOf( '&'+strName ) != -1) {
		
		tmp = tmp.split("?");
		tmp2 = tmp[1].split("&");
		return tmp[0]+"?"+tmp2[0];
	
	}
	
	return tmp;
}

function changeDisplay( objRef, objText ) {
	
	if( objRef.style.display == 'none' ) {

		objText.innerHTML = '[hide]';
		objRef.style.display = 'block';
	
	} else {
	
		objText.innerHTML = '[show]';
		objRef.style.display = 'none';
		
	}

}

function toggleRmCheck( objRef, objRef2 ) {

	if( objRef.checked == true ) {
		objRef.checked = false;
		objRef2.style.backgroundColor = '';
	} else {
		objRef.checked = true;
		objRef2.style.backgroundColor = '#ffa3a3';
	}

}

function submitAddNew() {
	objForm = document.getElementById('addpage');
	objHInput = document.getElementById('newpage');
	objInput = document.getElementById('new_page');
	
	objHInput.value = objInput.value;
	objForm.submit();
	
}

function submitModSubCat() {
	objForm = document.getElementById('modpage');
	objHInput = document.getElementById('newval');
	objInput = document.getElementById('mod_page');
	
	objHInput.value = objInput.value;
	objForm.submit();
}

function submitAddCat() {
	objForm = document.getElementById('addcat');
	objHInput = document.getElementById('newval');
	objInput = document.getElementById('new_cat');
	
	objHInput.value = objInput.value;
	objForm.submit();
	
}
function submitModCat() {
	objForm = document.getElementById('modcat');
	
	objValInput = document.getElementById('newcat');
	objCatInput = document.getElementById('curcat');
	
	objVal = document.getElementById('mod_cat');
	objCat = document.getElementById('cat');
	
	objValInput.value = objVal.value;
	objCatInput.value = objCat.value;

	objForm.submit();
}
function submitRemCat() {

	objForm = document.getElementById('remcat');
	
	objValInput = document.getElementById('oldcat');
	
	objCat = document.getElementById('cat');
	
	objValInput.value = objCat.value;

	objForm.submit();
}

function submitMove() {
	objForm = document.getElementById('movepage');
	objHInput = objForm.newval;
	objInput = document.getElementById('move_page');
	
	objHInput.value = objInput.value;
	objForm.submit();
}
function hideSubCat() {
	if(document.getElementById('modify_subcat'))document.getElementById('modify_subcat').style.display='none';
	if(document.getElementById('new_subcat'))document.getElementById('new_subcat').style.display='none';
	if(document.getElementById('move_subcat'))document.getElementById('move_subcat').style.display='none';
}
function showModSubCat() {
	hideSubCat();
	document.getElementById('modify_subcat').style.display='inline';
}
function showAddSubCat() {
	hideSubCat();
	document.getElementById('new_subcat').style.display='inline';
}
function showMoveSubCat() {
	hideSubCat();
	document.getElementById('move_subcat').style.display='inline';
}


function checkUserForm( objRef, boolCheckAll ) {
	
	objRef = ( typeof( objRef ) != 'object' ) ? document.getElementById(objRef) : objRef;
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var ph_reg = /[^\s\d\.\-\(\)]/;
	
	arrCheck = new Array();
	
	arrCheck[0] = objRef.uname.value;
	arrCheck[1] = strPass = objRef.pass.value;
	arrCheck[2] = strEmail = objRef.email.value;
	arrCheck[3] = objRef.fname.value;
	arrCheck[4] = objRef.lname.value;
	arrCheck[5] = strPhone = objRef.phone.value;
	arrCheck[6] = objRef.company.value;
	arrCheck[7] = objRef.country.value;
	arrCheck[8] = objRef.province.value;
	arrCheck[9] = objRef.address.value;
	arrCheck[10] = objRef.city.value;
	arrCheck[11] = objRef.postal.value;
	if(typeof(objRef.security_code) == 'object') arrCheck[12] = objRef.security_code.value;
	
	for( x in arrCheck ) {
		if( !boolCheckAll ) {
			if( x > 1 ) break;
		}
		if( arrCheck[x] == '' ) {
			alert( 'Please fill out required fields.' );
			return false;
		}
	}
		
	if( strPass.length < 6 ) {
		alert( 'Password must be at least 6 characters in length' );
		return false;
	}
	
	if( ph_reg.test(strPhone) ) {
		alert('Invalid phone number.  Please use format (###) ###-####');
		return false;
	}
	
	if( boolCheckAll ) {
		if( reg.test(strEmail) == false ) {
				
			alert('Invalid Email Address');
			return;
			
		}
   	}
	objRef.submit();
	
}

function checkComboBox( objRef ) {

	if( objRef.value == 'other' ) {
		document.getElementById('other_div').style.visibility = 'visible';
	} else { 
		document.getElementById('other_div').style.visibility = 'hidden';
	}

}

arrUploadCount = new Array();
arrUploadMax = new Array();

function addUpload( objRef, strPrefix ) {

	if( typeof( arrUploadCount[strPrefix] ) == "undefined" ) arrUploadCount[strPrefix] = 1;
	if( typeof( arrUploadMax[strPrefix] ) == "undefined" ) arrUploadMax[strPrefix] = 12;
	
	if( arrUploadCount[strPrefix] == arrUploadMax[strPrefix] ) return;

	objRef = (typeof(objRef)=='object') ? objRef : document.getElementById(objRef);
	
	
	
	objDiv = document.createElement('div');
	
	objInput = document.createElement('input');
	objInput.name = "upload"+strPrefix+(++arrUploadCount[strPrefix]);
	objInput.size = "15";
	objInput.type = "file";
	
	objLegend = document.createElement('span');
	objLegend.style.fontSize = '11px';
	
	objSpace = document.createTextNode(' ');
	objSpace2 = document.createTextNode(' ');
	
	objText = document.createTextNode('Label:');
	
	objLabel = document.createElement('input');
	objLabel.name = "f_label["+arrUploadCount[strPrefix]+"]";
	objLabel.size = "17";
	objLabel.type = "text";
	
	
	
	objLegend.appendChild(objText);
	
	objDiv.appendChild(objInput);
	objDiv.appendChild(objSpace);
	objDiv.appendChild(objLegend);
	objDiv.appendChild(objSpace2);
	objDiv.appendChild(objLabel);
	
	objRef.appendChild(objDiv);
	
}

function remUpload( objRef, strPrefix ) {

	objRef = (typeof(objRef)=='object') ? objRef : document.getElementById(objRef);
	
	if(objRef.lastChild) {
		objRef.removeChild(objRef.lastChild);
		arrUploadCount[strPrefix]--;
	}
}

function changeLoc( strLoc ) {

	arrTmp = Array();
	strUrl = window.location.href;
	arrTmp = strUrl.split("/");
	
	arrTmp[(arrTmp.length-1)] = strLoc;

	window.location = (arrTmp.join("/"));
}