/*
SCRIPT NAME:	CPSP-JS-ScriptLib.js
AUTOR:		Pandemonium
COPYRIGHT:	© 2008 by Pandemonium
---------------------------------------------------------------------------
THIS SCRIPT WAS WRITTEN BY PANDEMONIUM FOR
CUSTOM-PSP.COM IN SUMMER 2008. MODIFICATION
CONDITIONALLY AND ONLY WITH AGREEMENT FROM
THE AUTOR!!
*/


// This function chechs the "GO!Messenger Registration"-Form for correct entries
// If there are any invalid or missing entries, user will get an error-message!
function SubmitGOmsgrRegistration() {
	
	var GOmsgrUsr = document.getElementById("GOmsgrUserID").value;
	var GOmsgrMic = document.getElementById("GOmsgrAudio").value;
	var GOmsgrCam = document.getElementById("GOmsgrVideo").value;
	var GOmsgrMsg = document.getElementById("GOmsgrComment").value;
	
	var FormErrorVal = 0;
	var FormErrorMsg = "";
	
	// Check for correct 'GOmsgrUsr'-Entry
	if(!GOmsgrUsr || GOmsgrUsr=="") {
		FormErrorVal = FormErrorVal + 1;
		FormErrorMsg = FormErrorMsg+"- GO!messenger ID wurde nicht angegeben\n";
	}
	
	// Check for correct 'GOmsgrMic'-Entry
	if(GOmsgrMic.toLowerCase() != "ja" && GOmsgrMic.toLowerCase() != "nein") {
		FormErrorVal = FormErrorVal + 1;
		FormErrorMsg = FormErrorMsg+"- Headset/Audio wurde nicht angegeben\n";
	}
	
	// Check for correct 'GOmsgrCam'-Entry
	if(GOmsgrCam.toLowerCase() != "ja" && GOmsgrCam.toLowerCase() != "nein") {
		FormErrorVal = FormErrorVal + 1;
		FormErrorMsg = FormErrorMsg+"- GO!Cam/Video wurde nicht angegeben\n";
	}
	
	// Check for correct 'GOmsgrUsr'-Entry
	if(!GOmsgrMsg || GOmsgrMsg=="") {
		GOmsgrMsg = "-";
	}
	
	
	if(FormErrorVal == 0) {
		//alert(GOmsgrUsr+"\n"+GOmsgrMic+"\n"+GOmsgrCam+"\n"+GOmsgrMsg);
		window.location.href="http://custom-psp.com/?page_id=225&action=register&GOmsgrUsr="+GOmsgrUsr+"&GOmsgrMic="+GOmsgrMic+"&GOmsgrCam="+GOmsgrCam+"&GOmsgrMsg="+GOmsgrMsg+"&VerifyData=0";
	}
	else {
		alert("Sie haben nicht alle Angaben gemacht:\n\n"+FormErrorMsg+"\nBitte korrigiren Sie ihre Eingabe(n).");
	}
}


// This function resete the "GO!Messenger User Registration"-Form and
// delets all entered values and woll reset the Form to it's default!
function ResetGOmsgrRegistration() {
	document.getElementById("GOmsgrUserID").value = "";
	document.getElementById("GOmsgrAudio").selectedIndex = 0;
	document.getElementById("GOmsgrVideo").selectedIndex = 0;
	document.getElementById("GOmsgrComment").value = "";
}


// This function cancels the "GO!Messenger User Registration"
// and returns to the standard and empty Registration-Form!
function CancelGOmsgrRegistration() {
	window.location.href="http://custom-psp.com/?page_id=225&action=standard";
}


// This function verifies the "GO!Messenger Registration"-Form again and launches
// finally the process to store all the Data in the GO!Messenger-User-Database.
function VerifyGOmsgrRegistration() {
	
	var GOmsgrUsr = document.getElementById("GOmsgrUserID").value;
	var GOmsgrMic = document.getElementById("GOmsgrAudio").value;
	var GOmsgrCam = document.getElementById("GOmsgrVideo").value;
	var GOmsgrMsg = document.getElementById("GOmsgrComment").value;
	
	//alert(GOmsgrUsr+"\n"+GOmsgrMic+"\n"+GOmsgrCam+"\n"+GOmsgrMsg);
	window.location.href="http://custom-psp.com/?page_id=225&action=register&GOmsgrUsr="+GOmsgrUsr+"&GOmsgrMic="+GOmsgrMic+"&GOmsgrCam="+GOmsgrCam+"&GOmsgrMsg="+GOmsgrMsg+"&VerifyData=1";
}


// This function verifies the "Administration Login"-Form again
// and finally submits the form to send the entered login-data!
function VerifyAdminLoginForm() {
	
	var LoginUser = document.getElementById("LoginUsrName").value;
	var LoginPass = document.getElementById("LoginUsrPass").value;
	
	var FormErrorVal = 0;
	var FormErrorMsg = "";
	
	// Check for correct 'LoginUser'-Entry
	if(!LoginUser || LoginUser=="") {
		FormErrorVal = FormErrorVal + 1;
		FormErrorMsg = FormErrorMsg+"- Die User-ID wurde nicht angegeben\n";
	}
	
	// Check for correct 'LoginUser'-Entry
	if(!LoginPass || LoginPass=="") {
		FormErrorVal = FormErrorVal + 1;
		FormErrorMsg = FormErrorMsg+"- Es wurde kein Password angegeben\n";
	}
	
	if(FormErrorVal == 0) {
		document.getElementById("AdminLoginForm").submit();
	}
	else {
		alert("Sie haben nicht alle Angaben gemacht:\n\n"+FormErrorMsg+"\nBitte korrigiren Sie ihre Eingabe(n).");
	}
}


// This function resets the "Administration Login"-Form
// it erases all entered data and sets their vaalues to null.
function ResetAdminLoginForm() {
	
	document.getElementById("LoginUsrName").value = "";
	document.getElementById("LoginUsrPass").value = "";
	document.getElementById("AdminLoginForm").reset();
}


// This function tries to get the current Login-Informations and if possible
// it will return to the Admin-Area with the current Login-Informations!
function QuickAdminLogin() {
	
	// Check if the "QuickAdminLogin"-Form does exist!
	if(document.getElementById("QuickAdminLogin")) {
		document.getElementById("QuickAdminLogin").submit();
	}
	// "QuickAdminLogin"-Form doesn't exist!
	else {
		// Simply switch the URL of the current window ;-)
		window.location.href="http://custom-psp.com/?page_id=225&action=editmode&VerifyData=0";
	}
}


// This function reacts on the fired kind of the action, requested by
// an administrtative task from inside the "GO!Messenger User List"!!
// (Tasks can be "store/cancel/erase"). This function has two params:
// ActFormID   Current used Formular-ID (type: int)
// DoAction    Current Admin-Action  (type: string)
function GOmsgrAdminCommand(ActFormID,DoAction) {
	
	// The Formular-ID from the current form is defined
	if(ActFormID >= 1) {
		// 
		if(DoAction.toLowerCase() == "store" || DoAction.toLowerCase() == "cancel" || DoAction.toLowerCase() == "erase") {
			// Change the Form-Action depending to the chosen Admin-Action!
			switch(DoAction.toLowerCase()) {
				case "store":
					document.getElementById("EditDBentry_ID"+ActFormID).action = "http://custom-psp.com/?page_id=225&action=editmode&VerifyData=1&DBentry="+ActFormID+"&DBaction=store&DBeditkey=0";
					document.getElementById("EditDBentry_ID"+ActFormID).method = "post";
					break;
				case "cancel":
					document.getElementById("EditDBentry_ID"+ActFormID).action = "http://custom-psp.com/?page_id=225&action=editmode&VerifyData=1&DBentry="+ActFormID+"&DBaction=cancel&DBeditkey=0";
					document.getElementById("EditDBentry_ID"+ActFormID).method = "post";
					break;
				case "erase":
					document.getElementById("EditDBentry_ID"+ActFormID).action = "http://custom-psp.com/?page_id=225&action=editmode&VerifyData=1&DBentry="+ActFormID+"&DBaction=erase&DBeditkey=0";
					document.getElementById("EditDBentry_ID"+ActFormID).method = "post";
					break;
				default:
					document.getElementById("EditDBentry_ID"+ActFormID).action = "http://custom-psp.com/?page_id=225&action=editmode&VerifyData=1&DBentry="+ActFormID+"&DBaction=cancel&DBeditkey=0";
					document.getElementById("EditDBentry_ID"+ActFormID).method = "post";
					break;
			}
			// Submit the current used and customized form!
			document.getElementById("EditDBentry_ID"+ActFormID).submit();
		}
		
	}
	// No defined Formular-ID found
	else {
		alert("Error!");
	}
	
}


// This function is fired if the User submits the "Update/Erase"-Process.
function GOmsgrSubmitEditMode() {
	
	// Simply submit the currently used form
	document.getElementById("EditDBentry").submit();
	
}


// This function is fired if the User wants to stop the Edit-Mode.
// The User will be automatically logged off from the Admin-Panel!
function GOmsgrExitAdminMode() {
	
	// Simply change the URL for the current window
	window.location.href="http://custom-psp.com/?page_id=225&action=standard";
	
}
