// friendly popup
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable=no,toolbar=no,location=no,scroll=yes,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}


function printFlash(source, width, height, id, bg_color) {
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');
document.write('width="'+width+'" height="'+height+'" id="'+id+'" align="middle" />');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="'+source+'" />');
document.write('<param name="menu" value="false" />');
document.write('<param name="wmode" value="transparent" />');
document.write('<param name="quality" value="high" />');
document.write('<param name="bgcolor" value="'+bg_color+'" />');
document.write('<embed src="'+source+'" menu="false" wmode="transparent" quality="high" bgcolor="'+bg_color+'" width="'+width+'" height="'+height+'" name="'+id+'" align="middle" ');
document.write('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
}




// remove/replace input text
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}




// IE hack for dropdowns
sfHover = function() {
  if (document.getElementById("nav")) {
	  var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	  for (var i=0; i < sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		  this.className+=" sfHover";
		}
		sfEls[i].onmouseout=function() {
		  this.className=this.className.replace(new RegExp(" sfHover\\b"), "");
		}
	  }
   }
 }
 if (window.attachEvent) window.attachEvent("onload", sfHover);




// show/hide
function toggleDisplay(obj_id,vis) 
  { 
    if (document.getElementById){ 
      var obj = document.getElementById(obj_id); 
       if (vis!=null) { 
          var state = (vis ? 'block' : 'none'); 
       } else { 
            if (obj.style.display == '' || obj.style.display == 'none'){ 
               var state = 'block'; 
//            } else {
//               var state = 'none';
            } 
       }
      obj.style.display = state; 
    } 
  }




// form validation
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 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 MM_validateForm() { //v4.0
  if (document.getElementById){
    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=document.getElementById(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 formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}


//calculator - seller
function calculate(){
	var cost1 = .06 * document.calculator.price.value;
	var cost2 = .03 * document.calculator.price.value + 299;
	var cost3 = 299;
	
	var savings1 = 0;
	var savings2 = .03 * document.calculator.price.value - 299;
	var savings3 = cost1 - 299;

	var convertCost1=formatCurrency(cost1);
	var convertCost2=formatCurrency(cost2);
	var convertCost3=formatCurrency(cost3);

	document.calculator.cost1.value = convertCost1;
	document.calculator.cost2.value = convertCost2;
	document.calculator.cost3.value = convertCost3;
	
	var convertSavings1=formatCurrency(savings1);
	var convertSavings2=formatCurrency(savings2);
	var convertSavings3=formatCurrency(savings3);

	document.calculator.savings1.value = convertSavings1;
	document.calculator.savings2.value = convertSavings2;
	document.calculator.savings3.value = convertSavings3;
}


//calculator - buyer
function calculate2(){
	var rebate1 = (document.calculator2.price.value * .025) * .25;
	var rebate2 = (document.calculator2.price.value * .0275) * .25;
	var rebate3 = (document.calculator2.price.value * .03) * .25;
	
	var convertRebate1=formatCurrency(rebate1);
	var convertRebate2=formatCurrency(rebate2);
	var convertRebate3=formatCurrency(rebate3);
	
	document.calculator2.rebate1.value = convertRebate1;
	document.calculator2.rebate2.value = convertRebate2;
	document.calculator2.rebate3.value = convertRebate3;
}


function getURL(){
	var url = window.location.href.slice(window.location.href.indexOf('?') + 1);
	document.signUp.State.value = url;
	if(url=='AL'){
		document.getElementById('state-name').innerHTML = 'Alabama';
	}
	if(url=='AK'){
		document.getElementById('state-name').innerHTML = 'Alaska';
	}
	if(url=='AZ'){
		document.getElementById('state-name').innerHTML = 'Arizona';
	}
	if(url=='AR'){
		document.getElementById('state-name').innerHTML = 'Arkansas';
	}
	if(url=='CA'){
		document.getElementById('state-name').innerHTML = 'California';
	}
	if(url=='CO'){
		document.getElementById('state-name').innerHTML = 'Colorado';
	}
	if(url=='CT'){
		document.getElementById('state-name').innerHTML = 'Connecticut';
	}
	if(url=='DE'){
		document.getElementById('state-name').innerHTML = 'Deleware';
	}
	if(url=='DC'){
		document.getElementById('state-name').innerHTML = 'District of Columbia';
	}
	if(url=='FL'){
		document.getElementById('state-name').innerHTML = 'Florida';
	}
	if(url=='GA'){
		document.getElementById('state-name').innerHTML = 'Georgia';
	}
	if(url=='HI'){
		document.getElementById('state-name').innerHTML = 'Hawaii';
	}
	if(url=='ID'){
		document.getElementById('state-name').innerHTML = 'Idaho';
	}
	if(url=='IL'){
		document.getElementById('state-name').innerHTML = 'Illinois';
	}
	if(url=='IN'){
		document.getElementById('state-name').innerHTML = 'Indiana';
	}
	if(url=='IA'){
		document.getElementById('state-name').innerHTML = 'Iowa';
	}
	if(url=='KS'){
		document.getElementById('state-name').innerHTML = 'Kansas';
	}
	if(url=='KY'){
		document.getElementById('state-name').innerHTML = 'Kentucky';
	}
	if(url=='LA'){
		document.getElementById('state-name').innerHTML = 'Louisiana';
	}
	if(url=='ME'){
		document.getElementById('state-name').innerHTML = 'Maine';
	}
	if(url=='MD'){
		document.getElementById('state-name').innerHTML = 'Maryland';
	}
	if(url=='MA'){
		document.getElementById('state-name').innerHTML = 'Massachusetts';
	}
	if(url=='MI'){
		document.getElementById('state-name').innerHTML = 'Michigan';
	}
	if(url=='MN'){
		document.getElementById('state-name').innerHTML = 'Minnesota';
	}
	if(url=='MS'){
		document.getElementById('state-name').innerHTML = 'Mississippi';
	}
	if(url=='MO'){
		document.getElementById('state-name').innerHTML = 'Missouri';
	}
	if(url=='MT'){
		document.getElementById('state-name').innerHTML = 'Montana';
	}
	if(url=='NE'){
		document.getElementById('state-name').innerHTML = 'Nebraska';
	}
	if(url=='NV'){
		document.getElementById('state-name').innerHTML = 'Nevada';
	}
	if(url=='NH'){
		document.getElementById('state-name').innerHTML = 'New Hampshire';
	}
	if(url=='NJ'){
		document.getElementById('state-name').innerHTML = 'New Jersey';
	}
	if(url=='NM'){
		document.getElementById('state-name').innerHTML = 'New Mexico';
	}
	if(url=='NY'){
		document.getElementById('state-name').innerHTML = 'New York';
	}
	if(url=='NC'){
		document.getElementById('state-name').innerHTML = 'North Carolina';
	}
	if(url=='ND'){
		document.getElementById('state-name').innerHTML = 'North Dakota';
	}
	if(url=='OH'){
		document.getElementById('state-name').innerHTML = 'Ohio';
	}
	if(url=='OK'){
		document.getElementById('state-name').innerHTML = 'Oklahoma';
	}
	if(url=='OR'){
		document.getElementById('state-name').innerHTML = 'Oregon';
	}
	if(url=='PA'){
		document.getElementById('state-name').innerHTML = 'Pennsylvania';
	}
	if(url=='RI'){
		document.getElementById('state-name').innerHTML = 'Rhode Island';
	}
	if(url=='SC'){
		document.getElementById('state-name').innerHTML = 'South Carolina';
	}
	if(url=='SD'){
		document.getElementById('state-name').innerHTML = 'South Dakota';
	}
	if(url=='TN'){
		document.getElementById('state-name').innerHTML = 'Tennessee';
	}
	if(url=='TX'){
		document.getElementById('state-name').innerHTML = 'Texas';
	}
	if(url=='UT'){
		document.getElementById('state-name').innerHTML = 'Utah';
	}
	if(url=='VT'){
		document.getElementById('state-name').innerHTML = 'Vermont';
	}
	if(url=='VA'){
		document.getElementById('state-name').innerHTML = 'Virginia';
	}
	if(url=='WA'){
		document.getElementById('state-name').innerHTML = 'Washington';
	}
	if(url=='WV'){
		document.getElementById('state-name').innerHTML = 'West Virginia';
	}
	if(url=='WI'){
		document.getElementById('state-name').innerHTML = 'Wisconsin';
	}
	if(url=='WY'){
		document.getElementById('state-name').innerHTML = 'Wyoming';
	}
}





