//common functions - available all pages - note:page1 is a copy of page for asp only-cachinng control

function launchWindow(url)
{
	nw=window.open(url,"","width=1016,height=600,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes");
	nw.focus();
	return false; //return false for link support
	
}

function launchWindow2(url)
{
	nw=window.open(url,"","width=1016,height=600,scrollbars=yes,resizable=yes,toolbar=no,menubar=yes,location=no");
	nw.focus();
	return false; //return false for link support
	
}

function getobject(obj){ 
	return getobjectA(self,obj);
}

function getobjectA(win,obj){
	var t1=""
	var t2="";
	var result;

	if (win.document.getElementById) {
	    result = win.document.getElementById(obj);
	}
	else if (win.document.all)
	    result = win.document.all[obj];
	
	if(result!=undefined && result!=null)
		return result;
//alert("xxxx");
//alert(result==null);
		
	//not found, check whether its templated
	if(typeof(RVTEMPLATE)!= "undefined")
	{
		t1=RVTEMPLATE+":";
		t2=RVTEMPLATE+"_";
	}
//alert(t1)		
	if (win.document.getElementById)
		return win.document.getElementById(t2+obj);
	else if (win.document.all)
		return win.document.all[t1+obj];
}
 
function toggleDisplay(oDiv,oLink,sText)
{
	if(oDiv.style.display=='inline')
	{
		oDiv.style.display='none'; 
		//oLink.innerText="Show " + sText + "...";
		writeToElement(oLink,"Show " + sText + "...");
	}
	else
	{
		oDiv.style.display='inline';
		//oLink.innerText="Hide " + sText + "...";
		writeToElement(oLink,"Hide " + sText + "...");
		
	}
}



function restoreHidden()
{ 
	if(typeof(arrHidden)=='object')
	{
		for(i=0;i<arrHidden.length;i++)
		{
			getobject(arrHidden[i]).style.display='inline';
		}
	}
}

function writeToElement(oEl,sText)
{
			//nb - need better netscape support
			oEl.innerText = sText;
		
}

function goTo(sURL,sEntID,iNewWind)
{
	//sURL=sURL.toLowerCase();

	if(sURL.indexOf("?")<0)
		sURL+="?";

	//test 4 adding
	//if(sURL.toLowerCase().indexOf("entityid")<0 && sEntID.toString().length > 0)
		//sURL+="&entityID="+sEntID;
 


	if(iNewWind==1)
		launchWindow(sURL);
	else
	{
		redirect(sURL);
	}
	
	
	

}

var bodyCursorState='';

function setCursorWait()
{
	bodyCursorState='wait';
	document.body.style.cursor=bodyCursorState;
} 

 


function isCursorWait()
{ 
	return(bodyCursorState=='wait');
}

function redirect(sURL)
{
		setCursorWait();
		document.location.href=sURL;
		
}

function redirectAfterDelay(sURL,secsToWait)
{
		
		window.setTimeout("redirect('" + sURL + "')",secsToWait*1000);
		
}



function GetCookie(sCookieName)
{

    var CookieString = document.cookie.replace('RVCONFIG=','');
    //alert(CookieString);
    var CookieSet = CookieString.split ('&');
    var CookieItem;
    //alert(CookieSet.length);
    for(i=0;i<CookieSet.length;i++)
    {
		CookieItem=CookieSet[i].split('=');
		if(CookieItem.length==2)
		{
			if(CookieItem[0].toLowerCase()==sCookieName.toLowerCase())
				return CookieItem[1];
		
		}

		
	}
		
		
	return "";
    
}


var iLastTimeOutID=0;
function SetWindowStatus(strText,intAnimateNum)
{
	var MAX_DOTS=10;
	var strTextDisplay=strText;
	var i=0;
	var strExec;
	

	if (strTextDisplay.length==0)
	{
		window.clearTimeout(iLastTimeOutID);
		strTextDisplay='';
	}

	if(intAnimateNum==0)
		window.status=strTextDisplay;
	else 		
	{
		if(intAnimateNum>=MAX_DOTS)
			intAnimateNum=0;
			
		while(i <= intAnimateNum)
		{	strTextDisplay +=  '.'; i++;}
	
		window.status=strTextDisplay;
		strExec="SetWindowStatus(" + "'" + strText + "'," + (intAnimateNum+1) + ")"
		iLastTimeOutID=window.setTimeout(strExec,400);
	
	}

}
/*
 function DropDownSelectionValidator_ClientValidate(source, arguments)
{
//alert("DropDownSelectionValidator_ClientValidate")
	if(arguments.Value=="NULL")
	{
		arguments.IsValid = false;
		document.body.style.cursor='default';
    }
    else
		arguments.IsValid = true;
    
} 


function RadioButtonListRequiredFieldValidator_ClientValidate(source)
{
	var rbl=getobject(source.controltovalidate);

	var col = rbl.all;
	if ( col != null ) 
	{
		for ( i = 0; i < col.length; i++ ) 
		{
			if (col.item(i).tagName == "INPUT") 
			{
				if ( col.item(i).checked ) 
				{
					return true;
				}
			}
		}
	}	


	return false;
 
} 
*/
 
var lastRowSelectionColorUsed;
function selectRow(row, highlight,clickable,i)
{
	var sColor="#cc9999"; 
	
	
      try {
			if(sGridSelectorColor)sColor=sGridSelectorColor; //can come from local.js
      
      }
      catch (e){}
         
    
		
  if (highlight)
  {
    lastRowSelectionColorUsed = row.style.backgroundColor;
    row.style.backgroundColor = sColor;
    switch(i)
    {
		case 1:
			row.nextSibling.style.backgroundColor = sColor;
			break;
		case -1:
			row.previousSibling.style.backgroundColor = sColor;
			break;
	} 
		
    if(clickable)
    {
    
		row.style.cursor='pointer';
		SetWindowStatus('Select record...',0);
		
	}
		
    
  }
  else
  {
    row.style.backgroundColor = lastRowSelectionColorUsed;
	switch(i)
		{
			case 1:
				row.nextSibling.style.backgroundColor = lastRowSelectionColorUsed;
				break;
			case -1:
				row.previousSibling.style.backgroundColor =lastRowSelectionColorUsed;
				break;
		}	
		SetWindowStatus('',0);
		
	}
    
}

function checkEnter2(e)
{

     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return true;
     else
          return false;


}

function checkEnter()
{

	if(window.event && window.event.keyCode==13)
	{
	
		window.event.cancelBubble = true;
		window.event.returnValue = false;

		return true;
	}
	else
		return false;


}


function PostToExternalPage(sAction,sTarget)
{


		var f=document.forms[0];
		
	
		var sOldAction=f.action;
		var sOldTarg=f.target;

		f.__VIEWSTATE.name = 'NOVIEWSTATE';
		f.action=sAction;
		//sTarget="_blank";
		f.target=sTarget;
		f.submit();

		f.action=sOldAction;
		f.target=sOldTarg;
		f.__VIEWSTATE.name = '__VIEWSTATE';

}

function OpenPrintExport(strURL,bNewWindow) 
{  
	//not used at the moment
		var f=document.RVForm;
		if(bNewWindow)
		{
			PrintableWin = window.open("", 'PrintableWin', 'height=600,width=900,left=20,top=20,resizable=yes,alwaysraised=yes,scrollbars=yes,toolbar=yes,dependent=yes,menubar=yes');

			
			var sOldTarg=f.target;
			var sOldAction=f.action;
		 
			f.__VIEWSTATE.name = 'NOVIEWSTATE';

			f.action= strURL;
			f.target="PrintableWin";


			f.submit();

			f.action=sOldAction;
			f.target=sOldTarg;
			f.__VIEWSTATE.name = '__VIEWSTATE';
		}
		else
		{
			var sOldTarg=f.target;
			var sOldAction=f.action;
		 
			f.__VIEWSTATE.name = 'NOVIEWSTATE';

			f.action= strURL;


			f.submit();

			f.action=sOldAction;
			f.__VIEWSTATE.name = '__VIEWSTATE';
		}

}

function showFlash(sSWF,w,h,iDirOption,v4,v5,v6,v7,v8,v9)
{
	var sSubDir;
	if(iDirOption==null)
		iDirOption=0;
		
		
	if(iDirOption==0) //files dir
		sSubDir="/files/";
	else if(iDirOption==1) //images dir
		sSubDir="/images/";

	var sSWFFull="/files/" + PAGE_ENTITY_ID + sSubDir + sSWF;
	
	
	if(iDirOption==2) //full path passed in
	{
		sSWFFull=sSWF;
	}
	
	var sWH='xxxx>';
	if(w > 0)
		sWH=' width=' + w + ' height='+ h + '>';
	
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash5r42.cab#version=5,0,42,0"  name="flash" ' +sWH);
	//document.write(' width=' + w + ' height='+ h);
	//document.write'>');
	document.write('<param name=movie value="' + sSWFFull + '">');
	document.write('<param name=quality value=high>');
	document.write('<PARAM NAME=wmode VALUE=transparent>');
	document.write('<PARAM NAME=loop VALUE=false>');
	document.write('<embed src="' + sSWFFull + '" wmode=transparent quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" name="flash" ' +sWH);
	document.write('</embed></object>');
			
}

function sh_ven(v_id,e_id,nw)
{
	
	
	var sURL="/common/pages/public/rv/venue.aspx?venueID=" + v_id;
	if(e_id)
		sURL+="&entityID=" + e_id
	
		
	
	if(nw==1)
	{
		sURL+="&popup=1";
	
		launchWindow(sURL);
	}
	else
		redirect(sURL);
	
	//venue.aspx?popup=1&amp;venueID

}
 
function writeMungedEmail(email,text,title)
{
	var  re;
	re = /%%/g;

	email=email.replace(re,"@");
	re = /%/g;
	
	email=email.replace(re,".");
	if(text=="")
		text=email;
	//alert("<a title='" + title + "' href='mailto:" + email + "'>" + text + "</a>")
	document.write('<a title="' + title + '" href="mailto:' + email + '">' + text + '</a>');  
}

function getXMLHttpObject() {
 var crossxhr = false;
 if(window.XMLHttpRequest) {
  crossxhr = new XMLHttpRequest();
  if(crossxhr.overrideMimeType) {
   crossxhr.overrideMimeType('text/xml');
  }
 } else if(window.ActiveXObject) {
  try {
   crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
  } catch(e) {
   try {
    crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
   } catch(e) {
    crossxhr = false;
   }
  }
 }
 return crossxhr;
}

