/*
 * Flow Scripts
 * Updated: March 5, 2004
 */

function popup(URL, width, height) {
	if (width == "") width = "345";
	if (height == "") height = "200";

	popWin = window.open(URL, "popWin", "toolbar=no,scrollbars=no,location=no,width=" + width + ",height=" + height);
	popWin.focus();
	return false;
}

function popupResize(URL, width, height) {
	if (width == "") width = "345";
	if (height == "") height = "200";

	popWin = window.open(URL, "popWin", "toolbar=no,scrollbars=yes,resizable=yes,location=no,width=" + width + ",height=" + height);
	popWin.focus();
	return false;
}



// Clear Search Keywords
function clearSearch() {
	if (document.getElementById("signupemail")) {

		document.getElementById("signupemail").onfocus = function() {
			if (this.value == this.defaultValue) this.value = ""; }
		document.getElementById("signupemail").onblur = function() {
			if (this.value == "") this.value = this.defaultValue; }
	}
}

// Add close window script to button
function closeWindow() {
	if (document.getElementById("closewin")) {
		document.getElementById("closewin").onclick = function() { window.close(); return false; }
		document.getElementById("closewin").title = "Close Window";
		document.getElementById("closewin").style.display = "block";
	}
}
	


// Add function to any event handler
function addEvent(obj, evType, fn) {

	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else
		return false;
}


if (document.getElementById) {
	addEvent(window, 'load', clearSearch);
	addEvent(window, 'load', closeWindow);
}




// FUNTION "ShowBucket" TAKES THE FOLLOWING ARGUMENTS : 
//("FORM.SELECT-BOX","MULTIPLE/SINGLE",STORED-PROCEDURE)
function ShowBucket(formField, selectionType, storedProcedure) {
	var warnMsg="";

	if (formField == null)
		warnMsg=warnMsg + "\n --  FieldName of the Form to Show SelectedValues";

	if ((selectionType.toLowerCase() != "multiple") && (selectionType.toLowerCase() != "single"))
		warnMsg=warnMsg + "\n --  Selection Type(MULTIPLE/SINGLE)";
	else if (selectionType.toLowerCase() == "single")
		selectionType="";

	if ((storedProcedure == null) || (storedProcedure == ""))
		warnMsg=warnMsg + "\n --  Stored Procedure";

	if (warnMsg != "") {
		warnMsg = "\nERROR\n\nArguments not correctly provided : \n" + warnMsg;
		alert(warnMsg);
		return false;
	}

	var vReturnValue;
	vReturnValue = showModalDialog("/bucket.asp?selectionType=" + selectionType + "&storedProcedure=" + storedProcedure,formField,"dialogHeight: 364px; dialogWidth: 740px; dialogTop: 150px; dialogLeft: 150px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");

	if(vReturnValue==null)  // when window is "CANCELED" or "CLOSED"
		return false;

	for(i=(formField.length-1);i>=0;i--)
		formField.options[i] = null;

	for(i=1,j=0;i<(vReturnValue[0]);i=i+2,j++)
		formField.options[j] = new Option(vReturnValue[i],vReturnValue[i+1]);
}





// Form Validation

function isEmail(str) {
	return (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(str))
}

function lTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j = 0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function rTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function trim(str) {
   return rTrim(lTrim(str));
}

function isNull(str) {
	return trim(str).length == 0;
}
