// JavaScript Document
function newWindow(){
cookies=document.cookie;
startpos=cookies.indexOf("visited")+8;
if(startpos<8){
	bWindow = window.open("quote.html", "bWin", "width=470,height=370,scrollbars=no,resizable=no")
	bWindow.focus()
	d=new Date();
	d.setMinutes(d.getMinutes()+60*24*30);
	expires="expires=" +d.toGMTString();
	document.cookie="visited=yes; "+expires;
	}
}
function quote(){
	bWindow = window.open("quote.php", "bWin", "width=470,height=370,scrollbars=no,resizable=yes")
	bWindow.focus()
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  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);
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
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_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];}
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function setText(words){
if(document.all){
document.all.testing.innerHTML = words;
}else{
document.getElementById("testing").innerHTML = words
}
}
function openWindow(url, features){
	newWin = window.open(url, 'newWid', features)
	newWin.focus()
}
function randomNum(num){
num1 = Number(num)
num = Math.ceil(Math.random()*num1)
	str = "<img src=\"images/masthead_image"+num+".jpg\" alt=\"website design new york\" width=\"477\" height=\"101\" />"
	document.write(str)
}
////start experiment//////
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function checkRandomNum(base, array){
	num = Math.ceil(Math.random()*base)
	for(var i=0; i<array.length; i++){
		if(Number(array[i])==num){
			checkRandomNum(base, array)
		}
		
	}
	return(num)
}

function randomNumber(){
	num = 8 //total number of images
	casheLimit = 4 //how many to keep in memory
	
	if(getCookie("randomCookie")){
		cookie_array = getCookie("randomCookie")
		cookie_array = cookie_array.split("|")
		if(cookie_array.length>=casheLimit){
			cookie_array.shift()
		}
		randomNum = checkRandomNum(num, cookie_array)
		
	}else{
		
		randomNum = Math.ceil(Math.random()*num)
		cookie_array = Array()
	}
	
	cookie_array[cookie_array.length]=randomNum
	//cookie_array.push(randomNum)
	cookiestring=""
	
	for(var i=0; i<cookie_array.length; i++){
		cookiestring +=cookie_array[i]
		if(i<cookie_array.length-1){
			cookiestring +="|"
		}
	}
	
	setCookie("randomCookie", cookiestring)
	//alert(cookie_array.toString())
	str = "<img src=\"images/masthead_image"+randomNum+".jpg\" alt=\"website design new york\" width=\"477\" height=\"101\" />"
	document.write(str)
}
////////end experiment//////////
/******************************************************************************
 This is the flash detection script.
 ******************************************************************************/
var required = 6;
var hasFlash = false;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") != -1){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	// AFAIK creating an instance of an older version of the Flash object 
	// will return succeed even if the actual installed version is newer.
	document.write('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & required))) \n');  
	document.write('<'+'/scr' + 'ipt\> \n');
	}
else {
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])?navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin:0;
	if (plugin) {
		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		hasFlash = flashVersion >= required;
		}
	}


/******************************************************************************
 This classes the <html> element as `hasFlash` if flash is found. This style
 hook can be used to hide our to-be-replaced content before it even comes down
 the datapipe and eliminate the FOPSC ("Flash of Partially Styled Content")
 
 I've determined that the lighter the page weight the greater chance of a FOPSC.
 ******************************************************************************/
if (hasFlash && document.getElementsByTagName && document.getElementsByTagName('html')[0]) {
	document.getElementsByTagName('html')[0].className += (document.getElementsByTagName('html')[0].className=='')?'hasFlash':' hasFlash';
	}
	
	
/******************************************************************************
 Some utility functions. Look at them--aren't they useful?
 ******************************************************************************/
 
function SI_normalizeWhiteSpace(txt) {
	var rE = /\s+/gi;
	return txt.replace(rE,' ');
	}
function SI_forceRedraw() {
	// Corrects a margin-bottom sum bug in Mozilla
	var d = document;
	if (d.body && d.body.style) {
		d.body.style.height = "1px";
		d.body.style.height = "auto";
		}
	}
	

/******************************************************************************
 This is the function that finds and replaces the appropriate elements.
 
 
 SI_replaceElement(elem,swf,w,h,afv)
 
	elem (string) :
		`div#header` will replace the `div` with the id of header
		`div#primary-content>h1` will replace any `h1` tag whose direct parent is a `div` with an id of `primary-content`
		`h2.replaceme` will replace any `h2` tag with a className of `replaceme`
	swf (string) :
		full path to the swf
	w (int) :
		width
	h (int) :
		height
	afv (string) :
		used to pass additional flashVars to the movie
	 
 The new replaced element will be placed in a div 
 with a className of `'replaced-'+r.e.tagName`
 ******************************************************************************/
function SI_replaceElement(elem,swf,w,h,afv) {
	var d = document;
	
	if (!hasFlash || !d.getElementsByTagName) return;
	
	var r = new Object();
	r.p = new Object();
	r.e = new Object();
	
	if (elem.indexOf('>')!=-1) {
		// alert('Reference to parent found...');
		elemArray = elem.split('>');
		elem = elemArray[1];
		if (elemArray[0].indexOf('#')!=-1) {
			// alert('Reference to parent's id found...');
			parentArray = elemArray[0].split('#');
			r.p.id 		  = parentArray[1];
			r.p.tagName	  = parentArray[0];
			r.p.className = false;
			}
		else if (elemArray[0].indexOf('.')!=-1) {
			// alert('Reference to parent's className found...');
			parentArray = elemArray[0].split('.');
			r.p.id 		  = false;
			r.p.tagName	  = parentArray[0];
			r.p.className = parentArray[1];
			}
		else {
			r.p.id		  = false;
			r.p.tagName	  = elemArray[0];
			r.p.className = false;
			}
		}
	else {
		// alert('No reference to parent found...');
		r.p.id		  = false;
		r.p.tagName	  = false;
		r.p.className = false;
		}
	
	if (elem.indexOf('#')!=-1) {
		// alert('Reference to element's id found...');
		elemArray = elem.split('#');
		r.e.id 		  = elemArray[1];
		r.e.tagName	  = elemArray[0];
		r.e.className = false;
		}
	else if (elem.indexOf('.')!=-1) {
		// alert('Reference to element's className found...');
		elemArray = elem.split('.');
		r.e.id 		  = false;
		r.e.tagName	  = elemArray[0];
		r.e.className = elemArray[1];
		}
	else {
		r.e.id		  = false;
		r.e.tagName	  = elem;
		r.e.className = false;
		}
	
	if (afv!='') {
		afv = SI_normalizeWhiteSpace(afv);
		afv = '&'+afv;
		}
	
	var elems = d.getElementsByTagName(r.e.tagName);
	var count = elems.length;
	for (var i=0; i<count; i++) {
		e = elems[i];
		
		if (!r.p.tagName || (((r.p.tagName && !r.p.id && !r.p.className && e.parentNode.nodeName==r.p.tagName.toUpperCase()) || ((r.p.id && e.parentNode.id==r.p.id) || (r.p.className && e.parentNode.className==r.p.className))))) {
			if ((r.e.tagName && !r.e.id && !r.e.className) || (r.e.id && e.id==r.e.id) || (r.e.className && e.className==r.e.className)) {
				
				// alert('Make replacement');
				var txt;
				txt = SI_normalizeWhiteSpace(e.innerHTML);
				var c = d.createElement('div');
				c.className = 'replaced-'+r.e.tagName;
				
				e.parentNode.replaceChild(c,e);
				// The replaceChild acts like shift() on the
				// array that holds all of our elems. Meaning it
				// removes the first index and the remaining indexes
				// move up one.
				// The length or our elems array decreases by one
				count--;
				// Override the increment on loop index too.
				// We could just use e = elems[0]; above if we knew that
				// every instance of this particular element was going 
				// to be replaced--but there's no way of knowing that's
				// how it will play out.
				i--;
				var fv	= 'txt='+escape(txt)+afv;
				
				var swfHTML;
				swfHTML  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'">';
				swfHTML += '	<param name="movie" value="'+swf+'" />';
				swfHTML += '	<param name="flashvars" value="'+fv+'" />';
				swfHTML += '	<embed src="'+swf+'" flashvars="'+fv+'" width="'+w+'" height="'+h+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
				swfHTML += '<'+'/object>';
				c.innerHTML = swfHTML;
				txt='';
				}
			}
		
		}
	}
	
	
/******************************************************************************
 This is where the magic happens. This should really be the only part of this
 script you need to modify. Just add the necessary SI_replaceElement() calls 
 and make sure this sucker is called onload.
 ******************************************************************************/
function SI_flashReplacement() {
	// Replace all `<h1>` tags inside `<div id="primary-content">`
	SI_replaceElement('div.introtext>h1','txt.swf',300,23,'');
	SI_replaceElement('div.featured>h1','txt.swf',300,23,'');
	SI_replaceElement('div#main>h1','txt.swf',400,23,'');
	SI_replaceElement('div.showcase>h1','txt.swf',170,23,'');
	SI_replaceElement('div.news>h1','txt.swf',170,23,'');
	SI_replaceElement('div.showcase>h2.noblock','txt2.swf',170,18,'');
	SI_replaceElement('div.news>h2.noblock','txt2.swf',170,18,'');
	
	// Another Sample:
	// Replace all occurances of `<h3 class="author">` inside `<div class="comment">`
	// Also pass the additional variable `type` a value of `2` to Flash
	// SI_replaceElement('div.comment>h3.author','swf/txt.swf',236,18,'type=2');
	
	SI_forceRedraw();
	}


/******************************************************************************
 This sets the entire thing in motion. Place any other scripts that need to run
 onload in the SI_onload() function or add SI_flashReplacement to your own 
 onload handler.
 ******************************************************************************/
function SI_onload() {
	SI_flashReplacement();
	} 
	window.onload = SI_onload;