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 MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

// Calendar
function HideCal(id)
{	
	show_calendar('AddUser.txtExpirationDate', 'false');
}

function GetWebCastID(control)
{
	alert(control.value);

}

// User 

function CheckEmptyValues()
{
	if(document.frmUser.txtUserName.value=="" && document.AddUser.txtPassword.value=="" && document.AddUser.txtFirstName.value=="" && document.AddUser.txtLastName.value=="" && document.AddUser.txtEmail.value=="")
	{
		alert("All user information fields are required.  Please try again.");
		document.AddUser.txtUserId.focus();
		return false;			
	}
}

function trim(inputString) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
	while (ch == " ") { 
	// Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	
	ch = retValue.substring(retValue.length-1, retValue.length);
	
	while (ch == " ") { 
		// Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	while (retValue.indexOf("  ") != -1) {
	 // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}

	return retValue; // Return the trimmed string back to the user
} 


// Add and Remove Page


//Adding the Available Level values from the listAvailable control to the
// listSelected control 
function Add(iobj)
{	
	eval('var iobjTemp = ' + iobj + ';');
	var iSel = "";
	if (document.frmRole.listAvailable.length > 0)
  	{
		for(var i=0;i<document.frmRole.listAvailable.length;i++)
		{
			if(document.frmRole.listAvailable.options[i].selected==true) 
			{
				iobjTemp.options[iobjTemp.options.length]=new Option(document.frmRole.listAvailable.options[i].text, document.frmRole.listAvailable.options[i].value);  				   					   	
				document.frmRole.listAvailable.options[i] = null;
				iSel = i;
   			}  	 	
   		}
   		if (iSel >= document.frmRole.listAvailable.options.length) 
			document.frmRole.listAvailable.selectedIndex = iSel - 1;
		else if  (iSel < document.frmRole.listAvailable.options.length) 
			document.frmRole.listAvailable.selectedIndex = iSel;	
			
		if(document.frmRole.listAvailable.options.length <=0)
		{
			document.frmRole.btnRemove.disabled = true;
		}
		if(document.frmRole.listSelected.length>0)
		{
			document.frmRole.btnAdd.disabled = false;
		}
		else
		{
			document.frmRole.btnAdd.disabled = true;
		}
	}				
	return false;
}

//Adding the listSelected control values into the Available Level 
// list box

function Remove(iobj)
{	
	eval('var iobjTemp = ' + iobj + ';');
	var iSel = "";
	
	if (document.frmRole.listSelected.length > 0)
	{
		for(var i=0;i<document.frmRole.listSelected.length;i++)
		{
			if(document.frmRole.listSelected.options[i].selected==true) 
			{
				iobjTemp.options[iobjTemp.options.length]=new Option(document.frmRole.listSelected.options[i].text, document.frmRole.listSelected.options[i].value);  				   	
				document.frmRole.listSelected.options[i] = null;
				iSel = i;	
   			}  	 	
   		}
   		
   		if (iSel >= document.frmRole.listSelected.options.length) 
			document.frmRole.listSelected.selectedIndex = iSel - 1;
		else if  (iSel < document.frmRole.listSelected.options.length) 
			document.frmRole.listSelected.selectedIndex = iSel;	
		
		if(document.frmRole.listSelected.options.length <=0)
		{
			document.frmRole.btnAdd.disabled = true;
		}	
		if(document.frmRole.listAvailable.length >0)
		{
			document.frmRole.btnRemove.disabled = false;
		}
		else
		{
			document.AddUser.btnRemove.disabled = true;
		}
   	}
	return false;
}

function isEmailAddr(email)
{
	var result = false
				
	if(apostrophes(email)==false)
	{
	return false;
	}			  
	
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0)
	{
	var pindex = theStr.indexOf(".",index);
	if ((pindex > index+1) && (theStr.length > pindex+3))
	result = true;
	}
	return result;
}

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{
	// Check that current character is number.
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function apostrophes(rName)
{
	var re = /[']/; 												
	if (re.test(rName)==true) 
	{			
		return false;
	}		
}

function getAllSelectedPages(a)
{  			
	try{	
  	var selectObj = document.frmRole.listSelected;    	
  	if(selectObj.length>0) 
	{
		var strSelected = "";								
		
		for(var i=0;i<selectObj.length;i++)
		{					
			if( i == 0)
			{
				strSelected=selectObj.options[i].value;			   		
			}
			else
			{
				strSelected= strSelected +"|"+ selectObj.options[i].value;			   		
			}					
		} 				 			
		document.frmRole.hdnSelected.value=strSelected;		
	}
	}catch(e){alert(e);}
}

// AJAX Technology

function MoreInfo()
{
        var selectedSubMenu = document.all["txtSubMenu"].value;        
        var xml = DoCallback("SubMenu.aspx", selectedSubMenu);
        // Sync updates
        //alert(xml.responseText);
       // try{
        //alert(document.all["txtCallback"].value);        
        document.all["tdCategoryExists"].style.display = 'visible';
        document.all["txtCallback"].value = xml.responseText;
       // }
       // catch(e){alert(e);}
        //document.all["tdCategoryExists"].innerText = xml.responseText;
        //Msg.innerHTML = xml.responseText;
}
function DoCallback(url, params)
{
	// url:    URL to invoke
	// params: string object to pass to the remote URL
	// Add some parameters to the query string
	var pageUrl = url + "?callback=true&param=" + params;
	// Initialize the XmlHttp object
	var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	        
	// Prepare for a POST statement and synchronous. (All this is 
	// arbitrary and can be changed in your own implementation.)
	xmlRequest.open("POST", pageUrl, false);
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlRequest.send(null);
	// Return the XmlHttp object
	return xmlRequest;
}

function CategorySearch(id)
{
	if(id.value = "Category")
	{
		//alert(document.all["optSort"]);
		document.all["optSort"][0].value  = "satya";
		//alert(document.all["optSort"].enabled);
	}
	else
	{
		document.all["optSort"].enabled = false;
		//alert(document.all["optSort"].enabled);
	
	}
}

function WebcastView(WebcastID)
{	
	try{
		var URL = new String(location.href);		
		URL = URL.replace(/Search/,"View");		
			
		var newWin = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=350, height=250',true);	
		newWin.document.clear();
		
		newWin.document.writeln("<p align=center><img src='Images/copypopup_title.png' border=0>")
		
		if(URL.match("ID"))	newWin.document.writeln("<textarea onclick=javascript:document.getElementById('rSource').select() readonly rows=5 cols=35 id=rSource >" + URL+"</textarea>");	
		else newWin.document.writeln("<textarea onclick=javascript:document.getElementById('rSource').select() readonly rows=5 cols=35 id=rSource >" + URL + "?ID=" +  WebcastID + "</textarea>");	
		
		newWin.document.writeln("<p align=center><INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\"></p></p>");
		
		newWin.document.title = "Link to this page";
		newWin.location.enable = false;
	}
	catch(err){alert(err);}
}

