/*******************************
/**  Scripts for GG   **
*******************************/



function doConfirm(controlIn){
    if (confirm("Are you sure you wish to delete this entry?")){
        eval(controlIn);
        }
    }
    

function RemoveDepartments()
		{
			var amt = document.Form1.DepartmentList.options.length;
			var curropt;
			
			var x = 0;
			
			while ( x < amt )
			{
				curropt = document.Form1.DepartmentList.options[x];
				
				if ( curropt.selected )
				{
					document.Form1.DepartmentList.remove(x);
					amt--;
				}
					
				x++;
				
			} 
	
		}
		
		function AddDepartment()
		{
			var amt = document.Form1.DepartmentList.options.length;
			
			var i = document.Form1.DeptDropList.selectedIndex;
			
			var optxt = document.Form1.DeptDropList.options[i].text;
			var opval = document.Form1.DeptDropList.options[i].value;
			
			var newop = new Option(optxt,opval);
			
			document.Form1.DepartmentList.add(newop, amt);
	
		}
	
	
	

		function MM_findObj(n, d) 
		{ //v3.0
			var p,i,x;  
			if(!d) d=document; 
			if((p=n.indexOf("?"))>0&&parent.frames.length) 
			{
				d=parent.frames[n.substring(p+1)].document; 
				n=n.substring(0,p);
			}
			if(!(x=d[n])&&d.all) 
				x=d.all[n]; 
				
			for (i=0;!x&&i<d.forms.length;i++) 
				x=d.forms[i][n];
			
			for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
				x=MM_findObj(n,d.layers[i].document); 
				
			return x;
		}
		
		function MM_swapImage() 
		{ //v3.0
			var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
			for(i=0;i<(a.length-2);i+=3)
				if ((x=MM_findObj(a[i]))!=null)
				{
					document.MM_sr[j++]=x; 
					if(!x.oSrc) 
						x.oSrc=x.src; x.src=a[i+2];
				}
		}
		
		function MM_swapImgRestore() 
		{ //v3.0
			var i,x,a=document.MM_sr; 
			for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
				x.src=x.oSrc;
		}

		function MM_preloadImages() 
		{ //v3.0
			var d=document; 
			if(d.images)
			{ 
				if(!d.MM_p) 
					d.MM_p=new Array();
				var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
				for(i=0; i<a.length; i++)
					if (a[i].indexOf("#")!=0)
					{ 
						d.MM_p[j]=new Image; 
						d.MM_p[j++].src=a[i];
					}
			}
		}
		
		
				
		function ProdSearch(linkurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				location.href(linkurl + document.forms[0].txtSearch.value);
				
			}
			else
			{
				return true;
			}
		}
		
		
		
		
		function EnterKeyBranch()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].AddBranchButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
						
		
		function PerformLogin(email,pass,path)
		{
			
			if ( (email == '') || (pass == '') )
			{
				alert('Email/Password are required for login');
				
				document.forms[0].Email.value = '';
				document.forms[0].Password.value = '';
				
				document.forms[0].Email.focus();
				
				return false;
			}
		
			var fullpath = path + '?Email=' + email + '&Password=' + pass;
			
			location.href(fullpath);
			
		}
		
		
		
		// SEARCH CLICK - BANNER
		function PerformSearch(linkurl)
		{
			var redirecturl = linkurl + document.forms[0].txtSearch.value;
		
			location.href(redirecturl);
		
		}
		
	
		// ENTER KEY SEARCH - BANNER
		function EnterKeySearch(myurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				var linkurl = myurl + document.forms[0].SearchField.value;
				
				location.href(linkurl);return false;
				
			} 
			else 
			{	
				return true;
			}
			
		}
		
		
		
		// ENTER KEY LOGIN - DYNAMIC BANNER
		function EnterKeyLogin(myurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				PerformLogin(document.forms[0].Email.value, document.forms[0].Password.value, myurl);
				
			} 
			else
			{
				return true;
			}
			
		}
		
		function formatPhone(num)
		{ 
			
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 10)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="(";
				var ini = num.substring(0,3);
				_return+=ini+") ";
				var st = num.substring(3,6);
				_return+=st+"-";
				var end = num.substring(6,10);
				_return+=end;
			}
			return _return; 
		} 
	
	// REPLACE A SUBSTRING WITHIN A STRING
	function replaceSubstring(inputString, fromString, toString) 
	{
		// Goes through the inputString and replaces every occurrence of fromString with toString
		var temp = inputString;
		if (fromString == "") 
		{
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) 
		{ // If the string being replaced is not a part of the replacement string (normal situation)
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		else 
		{ // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";
			// Find a string that doesn't exist in the inputString to be used
			// as an "inbetween" string
			while (midString == "") 
			{
				for (var i=0; i < midStrings.length; i++) 
				{
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) 
					{
						midString = tempMidString;
						i = midStrings.length + 1;
					}
				}
			} // Keep on going until we build an "inbetween" string that doesn't exist
			// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			// Next, replace the "inbetween" string with the "toString"
			while (temp.indexOf(midString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} // Ends the check to see if the string being replaced is part of the replacement string or not
		return temp; // Send the updated string back to the user
	
	} // Ends the "replaceSubstring" function


	