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_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_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_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 doPopupForSearch(urlString)
{
	window.open(urlString, "Search", "width=900,height=400,menubar=no,status=no,location=no,scrollbars=yes,resizable=yes,toolbar=no,locationbar=no");
}

function doPopup( strURL )
{
	window.open(strURL, "VendorPartner", "width=900,height=400,menubar=yes,status=no,location=yes,scrollbars=yes,resizable=yes,toolbar=yes,locationbar=yes");
}

function doPDFPopup( strURL )
{
	window.open(strURL, "PDFPopup", "width=900,height=400,menubar=yes,status=no,location=yes,scrollbars=yes,resizable=yes,toolbar=yes,locationbar=yes");
}

function validateContactForm (form)
{
    var isValid = true;
    var errors = "Please complete the following required fields:";
    if(form.Firstname.value.length < 1)
    {
        isValid = false;
        errors = errors + "\n\t* Firstname";        
    }
    if(form.Lastname.value.length < 1)
    {
        isValid = false;
        errors = errors + "\n\t* Lastname";        
    }
    if(form.email.value.length < 1 && (form.StreetAddress.value + form.City.value + form.ZipCode.value).length < 1)
    {
        isValid = false;
        errors = errors + "\n\t* Email or address";
    }
    if(!isValid)
    {
        alert(errors);
        return false;
    }
    return true;
}

function validateSearchForm(form)
{
 	var isValid = true;
	var errors = "Please fix the following issues:";

	if(form.streetAddress.value == "")
	{
		isValid = false;
        	errors = errors + "\n\t* street Address is required";        
	}

	if( form.zipCode.value.length < 5 )
	{
		isValid = false;
        	errors = errors + "\n\t* Zip Code is required and has to be 5 digits.";        
	}
 	if(!isValid)
    {
        alert(errors);
        return false;
    }
    return true;
 }

function validateUserName(form)
{
	var uname= form.userName.value;
	if(!validEmail(uname))
	{
		alert("*** not a valid username ***");
		form.userName.focus();
		return;
	}
	form.submit();
}


function validateCreditCardForm(form)
{
	if(form.creditCardNumber.value == "")
	{
		alert("Please enter your credit card number");
		form.creditCardNumber.focus();
		return false;
	}
	if(form.nameOnAccount.value == "")
	{
		alert("Please enter your name");
		form.nameOnAccount.focus();
		return false;
	}
	if(form.streetAddress.value == "")
	{
		alert("Please enter your address");
		form.streetAddress.focus();
		return false;
	}
	if(form.zipCode.value == "")
	{
		alert("Please enter your zip code");
		form.zipCode.focus();
		return false;
	}
	return true;
}


function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random")
	{
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):160;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):160;
	}
	if(pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-w)/2:160;TopPosition=(screen.height)?(screen.height-h)/2:160;
	}
	else if((pos!="center" && pos!="random") || pos==null)
	{
		LeftPosition=5;TopPosition=160
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
	if(win.focus)
	{
		win.focus();
	}
}

function removeMSWordSmartQuotes()
{
	var text = document.forms[0].content.value;
//alert("found tab: " + text.indexOf('\u00bd') );	
	text  = text.replace('\u201c', '"');
	text  = text.replace('\u201d', '"');
	text  = text.replace('\u2018', '\'');
	text  = text.replace('\u2019', '\'');
	text  = text.replace('\u0009', '\t');
	text  = text.replace('\u00bd', '&frac12;'); 
	text  = text.replace('\u00bc', '&frac14;'); 
	text  = text.replace('\u00be', '&frac34;'); 
		
	//alert("trimed text: " + text );
 	document.forms[0].content.value = text;
 	document.forms[0].submit();
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function TestFileType( fileName, fileTypes ) {

 
//if (!fileName) return;
if (fileName == "") 
{
    alert('please select a file to upload');
    event.returnValue = false;
  return;
}

dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
if(fileTypes.join(".").indexOf(fileType) == -1)
{
     event.returnValue = true;
}
if(fileTypes.join(".").indexOf(fileType) != -1)
{     
	alert("Please do not upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.") ;
   	event.returnValue = false;
}

}

function validateAssociationSelection(form) 
{
 var association_Id = form.association_Id.value;
 //alert(" association_Id " +  association_Id );
 if (association_Id == '-1') 
 {
    alert('Please select an association to proceed.');
    return false;
 }
 return true;
}

function validateManagementReportUploadForm()
{
   var isValid = true;

   if(document.forms[0].year.value == "" || document.forms[0].month.value == "" || document.forms[0].day.value == "" )
   {
      isValid = false;
   }
   if(isValid)
 	event.returnValue = true;
   else
   {
           alert('You must select a date. Please try again.'); 
            event.returnValue =false;
   }
}

function testFileType( fileName, fileTypes ) {
//if (!fileName) return;
if (fileName == "") 
{
    alert('please select a file to upload');
    event.returnValue = false;
  return;
}

dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
if(fileTypes.join(".").indexOf(fileType) == -1)
{
     event.returnValue = true;
}
if(fileTypes.join(".").indexOf(fileType) != -1)
{     
alert("Please do not upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.") ;
   event.returnValue = false;
}

}

function validateFileName()
{
	var fileName = document.addAssociationDocumentForm.name.value;
	var illegalChars = new Array(9);
	var isValid = true;
	illegalChars[0] = "<";
	illegalChars[1] = ">";
	illegalChars[2] = "|";
	illegalChars[3] = "\\";
	illegalChars[4] = "/";
	illegalChars[5] = "!";
	illegalChars[6] = "*";
	illegalChars[7] = "?";
	illegalChars[8] = "\"";
	var errorString = "You cannot use the following character(s)... ";
	for (var i = 0; i < illegalChars.length; i++) 
	{	   
		if(fileName.indexOf(illegalChars[i]) != -1)
		{
			errorString += illegalChars[i] + " ";
			isValid = false;
		}
	}

	if( !isValid )
	{
		errorString += "\nPlease remove these character(s) to continue.";		
		alert(errorString );
		return isValid;
	}
	return isValid;
}

