//-------------------------------------------//
// Menu mouseover functions
//
// parameters:
// objId - tab being rolled over or off
//-------------------------------------------//
function mmOnmouseover(objId){
	var obj = document.getElementById(objId);
	if (obj != null){
		obj.attributes['class'].value="menuOnHoverBg"
	}
}
function mmOffmouseover(objId){
	var obj = document.getElementById(objId);
	if (obj != null){
		obj.attributes['class'].value="menuOffHoverBg"
	}
}
function mmOnmouseout(objId){
	var obj = document.getElementById(objId);
	if (obj != null){
		obj.attributes['class'].value="menuOnBg"
	}
}
function mmOffmouseout(objId){
	var obj = document.getElementById(objId);
	if (obj != null){
		obj.attributes['class'].value="menuOffBg"
	}
}
//-------------------------------------------//
// trim(str) - trims a string
//
// parameters:
// str - value to be trimmed
//-------------------------------------------//
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

//-------------------------------------------//
// showDiv(MyDivID) - Shows hidden div
//
// parameters:
// MyDivID - Div ID
//-------------------------------------------//
function showDiv(MyDivID){
	document.getElementById(MyDivID).style.display = "block";
}

//-------------------------------------------//
// hideDiv(MyDivID) - hides div
//
// parameters:
// MyDivID - Div ID
//-------------------------------------------//
function hideDiv(MyDivID){
	document.getElementById(MyDivID).style.display = "none";
}

//-------------------------------------------//
// removeCCAccount(AcctName) 
//	Removes Payment Account
//
// parameters:
// AcctID - Account ID to Delete
// AcctName - Name of the Account
//-------------------------------------------//
function removeCCAccount(AcctID, AcctName) {
	if(confirm("Are you sure you want to remove this " +AcctName+ " account?")){
		location.href = "ccInfo.php?do=Remove&acct="+AcctID;
	}
}

//-------------------------------------------//
// primaryCCAccount(AcctName) 
//	Assigns a default payment account
//
// parameters:
// AcctID - Account ID to Delete
// AcctName - Name of the Account
//-------------------------------------------//
function primaryCCAccount(AcctID, AcctName) {
	if(confirm("Are you sure you want to make " +AcctName+ " your primary account?")){
		location.href = "ccInfo.php?do=Primary&acct="+AcctID;
	}
}

//-------------------------------------------//
// removeDomain(Domain)
//	Removes Domain
//
// parameters:
// DomainID - Domain ID to Delete
// Domain - Name of the Domain
//-------------------------------------------//
function removeDomain(DomainID, Domain){
	if(confirm("Are you sure you want to remove this group ("+Domain+")? \nNote, this cannot be undone, if applications are installed, all data/tables will be lost.")){
		location.href = "domains.php?do=Remove&dom="+DomainID;
	}
}

//-------------------------------------------//
// payOption(MyOption)
//	adds pay option (new/existing) in hidden var
//
// parameters:
// MyOption - option selected
//-------------------------------------------//
function payOption(MyOption){
	document.getElementById("hdnAcctOpt").value = MyOption;
}

//-------------------------------------------//
// domOption(MyOption)
//	adds group option (new/existing) in hidden var
//
// parameters:
// MyOption - option selected
//-------------------------------------------//
function domOption(MyOption){
	if(MyOption=="existing") {
		if(document.getElementById("radSelGroupNew").checked) {
			MyOption = "new";
		}
	}
	document.getElementById("hdnGroupOpt").value = MyOption;
}

//-------------------------------------------//
// domPayment(MyDomain)
//	updates the payment option based on domain
//
// parameters:
//-------------------------------------------//
function domPayment(){
	AcctID = 0;
	Domain = "";
	if (document.getElementById("hdnNoDomsExist").value==0) {
		DomainID = document.getElementById("hdnDomainID");
		Domain   = DomainID[DomainID.selectedIndex].text;
		DomainID = DomainID[DomainID.selectedIndex].value;
		AcctID   = document.getElementById("hdnDomAcct"+DomainID).value;
	}
	if (AcctID <= 0 || document.getElementById("hdnGroupOpt").value=="new" || document.getElementById("hdnAcctOpt").value=="new") {
		hideDiv("divUpdAcct");
		showDiv("divPymtAccts");
		document.getElementById("radUpdAcctYes").checked = true;
		Domain = document.getElementById("domainName").value;
	} else {
		showDiv("divUpdAcct");
		hideDiv("divPymtAccts");
		document.getElementById("radUpdAcctNo").checked = true;
	}
	document.getElementById("domainName").value = Domain;
}

//-------------------------------------------//
// newWin(MyFile,MyWindowName)
//
// paramters:
// MyFile - image or html/php file to display
// WinName - window name
// WinWIdth - window width
// WinHeight - window height
//-------------------------------------------//
function newWindow(MyFile,WinName,WinWidth,WinHeight){
	WinName=open(MyFile,'NewWindow','width='+WinWidth+',height='+WinHeight+'scrollbars=yes,resizable=yes,screenX=50,screenY=100,top=50,left=100');
	WinName.focus();
}

//-------------------------------------------//
// uninstallApp(formID,Domain,AppID,AppName)
//	uninstalls application
//
// paramters:
// AppName - Application Name
// UserAppID - Application ID to Delete
// DomainID - Application Group
//-------------------------------------------//
function uninstallApp(AppName,UserAppID,DomainID){
	if(confirm("Are you sure you want to uninstall "+AppName+" from this group? \nNote, this cannot be undone, all data/tables will be lost.")){
		location.href = "manageApps.php?do=Uninstall&app="+UserAppID+"dom="+DomainID;
	}
}

//-------------------------------------------//
// addApps(formID)
// User wants to apps to domain
//
// paramters:
// formID - Form ID
//-------------------------------------------//
function addApps(formID){
	eval("document.forms.frmDomains"+formID+".action = 'addApp.php'");
	eval("document.forms.frmDomains"+formID+".submit()");
}

function showHide(DivShowHide,ImgChange){
	if(document.getElementById(ImgChange).src.indexOf("images/ico.app.min.gif")!=-1) {
		document.getElementById(ImgChange).src="images/ico.app.max.gif";
//		document.getElementById(DivShowHide).style.display = "none";
		new Effect.SlideUp(document.getElementById(DivShowHide), {queue: 'end'});
	} else {
		document.getElementById(ImgChange).src="images/ico.app.min.gif";
//		document.getElementById(DivShowHide).style.display = "block";
		new Effect.SlideDown(document.getElementById(DivShowHide), {queue: 'end'});
	}
}

//-------------------------------------------//
// updtDomainStatus(MyID,DomainID,DivCheckMark)
// User wants to apps to domain
//
// paramters:
// Status - New Status
// DomainID - Domain to Update
//-------------------------------------------//
function updtDomainStatus(Status,DomainID){
	var saveModText;
	var saveMod_opt = {
		method: 'post',
		onSuccess: function(t) {
			saveModText = t.responseText;
			if(saveModText=="SUCCESS"){
				location.href='clickAdmin.php';
			}else{
				document.getElementById("DivDomStatus").innerHTML = saveModText+"<br/>";
//				document.getElementById("DivDomStatus").class = "error";
			}
			new Effect.Appear(document.getElementById("DivDomStatus"), {duration:0});
			new Effect.Fade(document.getElementById("DivDomStatus"), {duration:5});
		}
	}
	
	function chgDomStatus(){
		new Ajax.Request('updateDomain.php?DomainID='+DomainID+'&newStatus='+Status, saveMod_opt);
	}	

	if(confirm("Are you sure you want to "+Status.toLowerCase()+" this application group?")){
		chgDomStatus();
	}else{
		return false;		
	}
}

//-------------------------------------------//
// getCheckedDomains(nTot)
// Gather checked domain ids
//
// parameters:
// nTot - total number of domains
//-------------------------------------------//
function getCheckedDomains(nTot){
	var strAssignApps="";
	var strUnAssignApps="";
	for (var nCnt=0; nCnt < nTot; nCnt++){
		x=eval("document.frmAssignDomains.chkApp"+nCnt);
		if(x.checked){
			strAssignApps=strAssignApps+"APP_ID_"+x.value;
		}else{
			strUnAssignApps=strUnAssignApps+"APP_ID_"+x.value
		}
	}		
	document.frmAssignDomains.AssignIDs.value=strAssignApps;
	document.frmAssignDomains.UnAssignIDs.value=strUnAssignApps;
	return true;
}

//-------------------------------------------//
// deleteSubUser(SubUserID,SubUserName,nCnt)
// Confirm user wants to delete subuser
//
// parameters:
// SubUserID - SubUser's ID
// SubUserName - SubUser's Name
// nCnt - row position in HTML table
//-------------------------------------------//
function deleteSubUser(SubUserID,SubUserName,nCnt){
	var saveModText;
	var saveMod_opt = {
		method: 'post',
		onSuccess: function(t) {
			saveModText = t.responseText;
			if(saveModText=="SUCCESS"){
				location.href='manageUsers.php';
			}else if(saveModText=="TIED2DOMAIN"){
				document.getElementById("DivDelStatus").innerHTML = "This user has a payment account tied to an existing domain, you will need to update the payment account before you can delete the user.<br/>";
//				document.getElementById("DivDelStatus").class = "error";
			}else{
				document.getElementById("DivDelStatus").innerHTML = saveModText+"<br/>";
//				document.getElementById("DivDelStatus").class = "error";
			}
			new Effect.Appear(document.getElementById("DivDelStatus"), {duration:0});
			new Effect.Fade(document.getElementById("DivDelStatus"), {duration:5});
		}
	}
	
	function removeUser(){
		new Ajax.Request('deleteSubUser.php?SubUserID='+SubUserID, saveMod_opt);
	}	

	if(confirm("Are you sure you want to remove this user ("+SubUserName+")?\nNote: All payment accounts associated with this user will be removed as well")){
		removeUser();
	}else{
		return false;		
	}
}