// JavaScript Document
//document.domain="bear.com";


//********************************************************************************************************/
// use openWindow function to open all windows
// if you load an htm or remote website, fill in 'theURL' and leave 'thePDF' an empty string ''
//     i.e. <a href="javascript:openWindow('template_body1.htm','html','','')">
// if you load a pdf, fill in "thePDF" and leave 'theURL' an empty string ''
//     i.e. <a href="javascript:openWindow('','pdf','','pressreleases/1998pressreleasescatalog.pdf')">
// the 'features' variable is optional.  To use the default settings (see below) leave an empty string ''
//     i.e. <a href="javascript:openWindow('template_body1.htm','html','width=640,height=480','')">
//********************************************************************************************************/
function openWindow(theURL, winName, features, thePDF) {
	if (features == "") features = 'toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=400';
	var newWin;
	var agt=navigator.userAgent.toLowerCase();
	theURL = unescape(theURL);
	thePDF = unescape(thePDF);
	if (thePDF != "") {
		//if (agt.indexOf("mac")!=-1) {
		//	location = thePDF;
		//} else {
			newWin = window.open(thePDF,winName,features);
			//newWin = window.open(theURL,winName,features);
			//newWin.document.open("text/html", "replace");
			//newWin.document.open("application/pdf");
			//newWin.document.open(thePDF);
			//newWin.document.writeln("<html><head>");
			//newWin.document.writeln("</head><body onLoad=\'document.location.replace(\""+thePDF+"\")\'>");
			//newWin.document.writeln("</head><body onLoad=\'location.replace(\""+thePDF+"\")\'>");
			//newWin.document.writeln("</head><body onLoad=\'location(\""+thePDF+"\")\'>");
			//newWin.document.writeln("</body></html>");
			//newWin.document.close();
		//}
	} else {
		newWin = window.open(theURL,winName,features);
		newWin.focus();
	}
	
	//newWin.focus();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Read Cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
}

//This function will bypass the dreaded MS ActiveX Focus issue.
function flashActiveX(Movie, Width, Height, Alt) {
	var str = '<div>';
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + Width + '" height="' + Height + '" title="' + Alt + '">';
	str += '  <param name="movie" value="'+ Movie +'"><param name="loop" value="false"><param name="wmode" value="opaque"><param name="menu" value="false"><param name="quality" value="high">';
	str += '  <embed src="'+ Movie +'" width="' + Width + '" height="' + Height + '" loop="false" wmode="opaque" menu="false" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="' + Alt + '" swLiveConnect="true"></embed>';
	str += '</object></div>';
	
	document.write(str);
}

//Preload Images
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];}}
}
// Swaps Images
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];}
}
// Opens Windows
function MM_openBrWindow(theURL,winName,features) { //v2.0
  theURL = unescape(theURL);
  window.open(theURL,winName,features);
}

// Swap Image Restore
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;
}

// find obj
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;
}
//reloads the window if Nav4 resized
function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//Creates On, Off and Active states to images
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 MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

// to use function:  MM_showHideLayers('Layer1','','hide') or MM_showHideLayers('Layer1','','show')
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

 
function sentenceCase(a) {
	a = a.replace(/_/g, " ");
    var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
    var a = a.split(/\s+/g); // split the sentence into an array of words
    for (var i=0; i<a.length; i++) {     
	 //var firstLetter = a[i].substring(0, 1).toUpperCase();
     //  var restOfWord = a[i].substring(1, a.length).toLowerCase();
	 var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
	 if (parts == null) {
		 // & character
		a[i] = a[i]; 
	 } else {
     	var firstLetter = parts[1].toUpperCase();		
     	var restOfWord = parts[2] //.toLowerCase();
		
		var combined = firstLetter+restOfWord; // additions by Darren 8/17/05
		if (a[i].length != combined.length) { 
			// missing character detected add it back
			
			if (a[i].slice(0,1) == "'") {
				// fix problem when ' is the first character
				firstLetter = '';
				restOfWord = a[i].slice(0,a[i].length);
			} else {
			 for (var d=1; d<a[i].length; d++) {  
			 	if (a[i].slice(d,d+1) != restOfWord.slice(d-1,d)) {
					restOfWord = restOfWord + a[i].slice(d,a[i].length);
					break;
				}			 
			 }
		  }
		}

     	a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
	 }
    }
	
    return(a.join(' '));
}

function readstrUid() {
	var strUid = "notlogged";
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("BSCidCookie");
	if (pos != -1) {
		var start = pos + 12;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
			var value = allcookies.substring(start, end);
		strUid = value;
	}
	return strUid;
}
	
function titleCap() {
	document.write(document.title.toUpperCase());
}

function sentenceCap() {
	document.write(sentenceCase(document.title));
}


//allows for a pop up message
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//used in streetview faq's - allows for expanding and closing of links
function P7_autoLayers() { //v1.1 PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;}
 for(k=0; k<p7c.length; k++) {
  if((g=MM_findObj(p7c[k]))!=null) {
   b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=0; k<args.length; k++) {
  if((g=MM_findObj(args[k])) != null) {
   b=(document.layers)?g:g.style;b.visibility="visible";f=false;
   for(j=0;j<p7c.length;j++) {
    if(args[k]==p7c[j]) {f=true;}}
  if(!f) {p7c[p7c.length++]=args[k];}}}
}

function P7_JumpMenu(selObj,restore){ //v1.3 by Project Seven
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {theUrl = theFullString.substring(0,endPos);}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {theTarget = theFullString.substring(endPos,theLength)}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {window.open(theUrl);}
	else if (theTarget == "window:Main") {eval("parent.location='"+theUrl+"'");}
	else {eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");}
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}   

function stripe(id) {
	// the flag we'll use to keep track of 
	// whether the current row is odd or even
	var even = false;

	// if arguments are provided to specify the colours
	// of the even & odd rows, then use the them;
	// otherwise use the following defaults:
	var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
     }
   }
}

function resetErrorFields(arrayCheck) {
	// this will changes all fields if they were red back to white
	firstErrorArray = new Array();
	 for (i = 0; i < arrayCheck.length; i++) {
	 	divError(arrayCheck[i], 1);
 	}
}

function divError(divID, returnState) {
	// this function will change the field to a red color to show an error	
  if (document.getElementById(divID)) {
	if (returnState) {
		document.getElementById(divID).style.background = "#FFFFFF"
	} else {
		firstErrorArray.push(divID);
		document.getElementById(divID).style.background = "#FFCCFF"
	}
  }
}

function findPosY(obj) {
    var curtop = 0;
   if(!obj) {
	 return 0
   } else {
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
	if (curtop) {
   	 return curtop-50;
	} else {
	 return curtop;
	} 	
  }
}

function validateTypes(formValue, vType, alertMessage) {
  var validReturn = 1;
  if (formValue) {
   if (formValue != "") {
	if (vType == "email") {
		var emailExp=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
		if(!emailExp.test(formValue)) {
	 		validReturn = 0;
		}
	} else if (vType == "number") {
		if(isNaN(formValue)){
			validReturn = 0;
		}
	} else if (vType == "zip") {
		// Check for correct zip code
		
		//sep = this.setArg( sep, "- " );
		//var regex = new RegExp( "^[0-9]{5}(|[" + sep.toPattern() + "][0-9]{4})?$" );

     	var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 		if(!reZip.test(formValue)) {
			validReturn = 0;
		}
	 }
    }	
  }
  
  if (alertMessage) {
	  if (!validReturn) {
	  	alert(alertMessage);
	  }
  } else {
  	return validReturn;
  }
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

function getThankyouPage() {
	var urlArray = String(location.href);
	urlArray = urlArray.split("/");
	var thankyouUnite = '';
	for (var i=0; i < urlArray.length-1; i++) {
		thankyouUnite += urlArray[i] + '/';
	}	
	
	return thankyouUnite;
}


// for loading bear.com pages into MyEMC

function setLinks(){
	
	var lnks = document.links;
	var newhref;
	
	for (i = 0; i < lnks.length; i++) {
		lnks[i].onclick = function() {
			var hrf = this.href;
			//alert("setLinks script: " + hrf);
			parent.loadIframe(hrf);
			return false;
			//newhref = "javascript:parent.loadIframe(" + hrf + ")";
			//this.href = newhref;  // loads new href back onto the link that is being clicked
		}
	}
}

function writeHeaderFooter(){
	var str = '';
	str+='PRINTING HOUSE FITNESS + SQUASH CLUB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;421 Hudson St., New York, NY 10014&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tenpoint">212.</span><span class="phoneFooter">243.7600</span> x2';
	document.write(str);
}
//window.onload = setLinks;