//***************************************************************************************************************
//Xondu Inc. Alrights reserved.
//***************************************************************************************************************

function Search( sUrl)
{
	newwindow=window.open( sUrl,'DownloadLeads');
	if (window.focus) {newwindow.focus()} 	
}

function toggleDisplay( sname,  sstatus )
{
	with (document)
	{
		
		var x=1;
		obj = document.getElementById(sname + x);
		while ( obj != null ) 
		{
   			obj.style.display = sstatus;
   			x++;
			obj = document.getElementById( sname + x);
		
		}

	} 
}

function toggleCheckBoxes( sname, bChecked)
{
	with (document)
	{
		
		var x=1;

		obj = getElementById(sname + x);
		while ( obj != null ) 
		{
   			obj.checked = bChecked;
   			x++;
			obj = getElementById( sname + x);
			
		}

	} 
}




function getindustrytype( bShow )
{
	with (document)
	{
		
		var obj = document.getElementById('siclist');
		var obj2 = document.getElementById('siclistinfo');
		if ( bShow )
		{
			obj.style.display = 'block';
			obj2.style.display = 'block';

		}
		else
		{
			obj.style.display = 'none';
			obj2.style.display = 'none';

		}
	} 
}



function ItemClick( sname )
{
	with ( document )
	{
		ACheckBox = getElementById(sname);
		if (ACheckBox ) 
		{
			var bOneChecked = AtLeastOneChecked(sname);
			ACheckBox.checked = (! bOneChecked);
		}
	
	}
	
}

function toggleChecked( sname, bChecked )
{
	with ( document)
	{
		obj = getElementById(sname);
		if (obj ) 
		{
			obj.checked = bChecked;	
		}
	}

}


function get_tenanttype( ACheckBox, sname )
{
	
	if ( ACheckBox.value='all')  
	{
		//toggle all of the items
		toggleCheckBoxes( sname, ACheckBox.checked );

	}
	else	
	{
		ACheckBox.checked = false;
	}

}


function AtLeastOneChecked( sname)
{
	with (document)
	{
		
		var x=1;
		obj = getElementById(sname + x);
		while ( obj != null ) 
		{
   			if (obj.checked) 
   			{
   				return true;
   			};
   			x++;
			obj = getElementById( sname + x);
			
		}
		return false;

	} 
}



function Trim(value) {
    value = String(value);
    return value.replace(/^\s+/ig, "").replace(/\s+$/ig, "");
}

function IsValidUrl(objId){
    obj = document.getElementById(objId);
    if(obj.value == '') {
        return false;
    }
    obj.value = Trim(obj.value);
    var re = new RegExp("^https?://", "i");
    if(!re.test(obj.value)) {
        obj.value = 'http://' + obj.value;
    }
}

// width, heigh, left, top
function newWindow(file, windowname, w, h, l, t) {

	windowname = (windowname == '') ? 'popup' : windowname;

	w = (!w) ? 640 : w;
	h = (!h) ? 640 : h;

	l = (!l) ? 200 : l;
	t = (!t) ? 80  : t;

    msgWindow=window.open(file,windowname,'resizable=yes,scrollbars=1,width=' + w + ',height=' + h + ',left=' + l + ',top=' + t);
	if (msgWindow.opener == null) msgWindow.opener = self;
	msgWindow.focus();
}                

function helpWindow(file) {
	newWindow(file, 'help',660,550);
}                

function PrinterFriendly(url) {
	newWindow(url, 'PrinterFrienly',660,550);
}  

function displayDescription(desc){

  var docElement = document.all['description']
  var xPos
  var yPos

  xPos = window.event.clientX + 10
  yPos = window.event.clientY

  if (yPos > 400)
  {
    yPos = 400;
  }
  docElement.style.left = 200;
  docElement.style.top = yPos
  docElement.innerHTML = desc
  if (desc == '')
    docElement.style.display = "none"
  else
    docElement.style.display = ""
  
}

// Javascript function that mimics VB Trim function *********************************
	// **********************************************************************************
	function Trim(strValue) {
	//	remove leading spaces
		while ('' + strValue.charAt(0) == ' ') {
			strValue = strValue.substring(1, strValue.length);
		}
	//	remove trailing spaces
		while ('' + strValue.charAt(strValue.length - 1) == ' ') {
			strValue = strValue.substring(0, strValue.length - 1)	
		}	
		return strValue;
	}

function WaitFor(sObj )
  {
  
    Hide( sObj );
    Show ('WaitFor');
    //fix the body
    //var docElement = document.all['main_content'];
    var docElement = document.getElementById('main_content');	
    if (docElement != null) {
      	docElement.style.cursor = "wait";
  }
   
  }

function PerformSearch() 
	{
		//check that some value has been entered
		
		//display the wait form and then submit
		WaitFor('SearchForm');
		//frmSearch.submit();
		return( true);
	}

function CheckDocumentsForm( bCheckFile ) 
{
		
	with (document)
	{	

	if ( Trim( frmDocument.txtdocumentname.value) == '' ) {
   		alert('Please specify a name or identifier for this document.');
   		frmDocument.txtdocumentname.focus();
   		return (false);
	};

	//check the file type
		if ( bCheckFile ) 
		{
			if ( ( navigator.userAgent.indexOf("Mac") == -1 ) && ( Trim( frmDocument.filedata.value) != '' ) 
		     		&& ( frmDocument.filedata.value.indexOf(".txt") == -1 ) && ( frmDocument.filedata.value.indexOf(".rtf") == -1 ) )  
   			{
   		
   				alert('Only Rich Text (*.rtf) and plain text (*.txt) files are accepted.');
   				frmDocument.txtdocumentname.focus();
   				return (false);
			};
		};
		
		frmDocument.submit();
		return(true);
	}
}

function ValidatePrintRequest( fObj)
//-------------------------------------------------------------------------------
 
	{
		var sTemp;
		
		with  ( fObj ) 
		
		{
   
						
			if (  ( txtprintoption.value == '1' )  && ( Trim( txtdocument.value) == '' ) ) 
			{
   			alert('Please specify the document to use for the merge. You can upload documents by clicking on [My Documents] from the menu.');
   			txtdocument.focus();
   			return (false);
			};
			
			//job function codes
			
						
			//preview format
			//if ( Trim( txtpreviewoption.value) == '' ) 
			//{
			//alert('Please specify a display format to receive your print request.');
   			//txtpreviewoption.focus();
   			//return (false);
			//};
			
			return (true);
		}	//with form



	}
//----------------------------------------------------------------------------
//end validate print request


function ValidateMergeRequest( fObj)
//-------------------------------------------------------------------------------
 
	{
		var sTemp;
		
		with  ( fObj ) 
		
		{
   
			if ( Trim( txtlistid.value) == '' ) 
			{
   			alert('Please specify a list to use with this print request.');
   			txtlistid.focus();
   			return (false);
			};

			
			//job function codes
			
			if ( ( txtexecutivefilter.value == '1' ) && ( Trim( txtjobfunctions.value) == '' ) ) 
			{
   			alert('Please specify at least one executive job function from the list to use with this print request.');
   			txtjobfunctions.focus();
   			return (false);
			};
			
			//preview format
			if ( Trim( txtpreviewoption.value) == '' ) 
			{
   			alert('Please specify a display format to receive your print request.');
   			txtpreviewoption.focus();
   			return (false);
			};
			
			return (true);
		}	//with form



	}
//----------------------------------------------------------------------------
//end validate print request



function CheckSearch( ) 
{
	//verify that at least one search item is selected
	
}

function PrintDocument(url, AForm) {
	win=window.open('','printpreview','toolbars=0' ); 
 	AForm.target='printpreview';
 	AForm.action= url;
	//newWindow( url, 'PrintWindow',660,550);
	AForm.submit();
}

function PrintDocumentEx(url, AForm) {
	win=window.open('','printpreview','toolbars=1' ); 
 	AForm.target='printpreview';
 	AForm.action= url;
	//newWindow( url, 'PrintWindow',660,550);
	AForm.submit();
}

function IsValidCC(s) 
{

  var i, n, c, r, t;

  // First, reverse the string and remove any non-numeric characters.

  r = "";
  for (i = 0; i < s.length; i++) 
  {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }

  // Check for a bad string.

  if (r.length <= 1)
    return false;

  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.

  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }

  // Finally, add up all the single digits in this string.

  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }

  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.

  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}


function HasExpired( month, year ) {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month -1,1);		// create an expired on date object with valid thru expiration date
        	if( now < expiresIn ) 
        		return (false)
        	else
        		return true;        										// then we get the miliseconds, and do a long integer comparison
    }

function DisableDocSelect()
{
   document.onselectstart=new Function ("return false");

}

function IsValidDate( sValue )
///////////////////////////////////////////////////////////////////////////////////////////////////////
//date:		02/11/2007
//desc:		checks and validates dates in various formats.
///////////////////////////////////////////////////////////////////////////////////////////////////////
{
   // Regular expression used to check if date is in correct format
   var pattern = new RegExp('[0-3][0-9]-0|1[0-9]-19|20[0-9]{2}');
   
   sValue.replace('-', '/');
   sValue.replace('.', '/');
   if(sValue.match(pattern))
   {
      var date_array = sValue.split('/');
      var month = date_array[0] - 1;

      // Attention! Javascript consider months in the range 0 - 11
      var day = date_array[1] ;
      var year = date_array[2];

      // This instruction will create a date object
      source_date = new Date(year,month,day);
	//alert( 'month=' +month + ' year=' + year + ' day ='+ day );
      if ( (year != source_date.getFullYear()) || (month != source_date.getMonth()) || (day != source_date.getDate()) )
	  {
      	 alert('Date format is not valid! The proper format is: mm/dd/yyyy');
      	 return false;
   	  }	
   	 return true;
   }
   else
   {
   	alert('Date and/or date format is not valid! The proper format is: mm/dd/yyyy');
      	 return false;

   
   }
}

function IsValidDateRange(from, to) {
	if (Date.parse(from.value) <= Date.parse(to.value)) {
		return true;
	}
	else {
		if (from.value == "" || to.value == "") {
			alert("Both dates must be entered.");
			from.focus();
			return false;
		}
		else {			 
			alert('Either the date format is incorrect,\nor the second date must occur after the first date.');
			from.focus();
			return false;
		}
	}
}

function GetCCInfo( url )
{
	newWindow( url, 'ccInfo',530,350, 30, 20);
}	

function GetTerms( url )
{
	newWindow( url, 'TermsOfUse',640,400, 30, 20);
}