function mark_row(t) {
t.style.backgroundColor = '#F6ECE2';
}
function unmark_row(t) {
t.style.backgroundColor = 'transparent';
}

//usage onmouseover="mark_row(this)" onmouseout="unmark_row(this)"


//this nice javascript will open external links in a new window - http://www.sitepoint.com/article/standards-compliant-world/3
//usage rel="external"

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     {anchor.target = "new";
		 anchor.title = anchor.title+" in a new window";}
	 else
	 	 {anchor.title = anchor.title;} 
 } 
} 
window.onload = externalLinks;

// for textareas to not get too long
// the markup is: onkeyup="textLimit(this.form.fieldid, 250);"
function textLimit(field, maxlen) {
if (field.value.length > maxlen + 1)
alert('Your input has been truncated!');
if (field.value.length > maxlen)
field.value = field.value.substring(0, maxlen);
}
//also for textareas to not get too long and adds a little box showing how many characters are left
// markup - onKeyDown="textCounter(this.form.fieldname,this.form.remLen,125);" onKeyUp="textCounter(this.form.fieldname,this.form.remLen,125);
// markup for little box - <input type="readonly" type="text" name="remLen" size="3" maxlength="3" value="125" /><br /> characters left
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
//advances from one field to another - may be a PITA we'll see
//usage onKeyUp="advance(this,'fieldname',numberofcharacters)"
function advance(currentField,nextField, fieldLength) {
	if (currentField.value.length == fieldLength)
	{
		document.editprofile[nextField].focus();
	}
}
//accepts on numeric characters - may be okay for some things like phone numbers
//usage onkeypress="return numeralsOnly(event)"
function numeralsOnly(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
    ((evt.which) ? evt.which : 0));
	if (charCode < 48 || charCode > 57)
	{	return false; }
	return true;
}

//this is for opening the pop-up style boxes, I'm going to include scrolling and menu 
function callurl(passURL)
{
	window.open(passURL, 'ProductDetails', config='height=500,width=500, resizable=yes, left=200, top=200, scrollbars=1, menubar, location, status')
}

// to check email - usage onblur="if(!validEmail(this.value)) this.focus();"
var chkDot = true;
var usEmail = true;
function validEmail(eAddr) 
{ 
   var lenSuffix = (usEmail) ? 4: 3;
   var goodAddr = false;
   var ndxAt = ndxDot = 0;

   ndxAt  = eAddr.indexOf("@");
   ndxDot = eAddr.indexOf(".");
   ndxDot2 = eAddr.lastIndexOf(".");

   if ( (ndxDot < 0) || (ndxAt < 0) )
      alert("Your email address lacks '.' or '@'.\n\nThe format is 'you@dom.suf'");  
   else if (chkDot  && (ndxDot < ndxAt) )
        chkDot =!( confirm("You entered a 'dot' before the '@'\n Are you sure that is right?"));
   else if ( (ndxDot2 - 3) <= ndxAt)
        alert("You may be missing your domain name.\n\nThe format is 'you@dom.suf'");
   
   else if ( eAddr.length < (ndxDot2 + lenSuffix) )
      usEmail =!( confirm("You have fewer than 3 characters as a domain suffix.\nAre you sure that is right?"));
   else
      goodAddr = true;


   return (goodAddr);                       
} 

// the following scripts are mostly from the old site any may not be compliant
function GoToPage(URLwithQryString)
	{	strReferrer = new String()
		strReferrer = URLwithQryString
		
		if (strReferrer.search("searchresult.asp") > 0)
		{
			window.location.href = URLwithQryString + "&shoplistids=" + window.shoplistids.value
		} 
		else
		{
			window.location.href = URLwithQryString 
		}
	}
	
function subpop(s)
		{
			//function called to open the calendar object in a new window .
		     var addWindow = window.open(s,"cal","width=275,height=200,left=10,top=35,resizable=1,status=1,menubar=0,scrollbars=0,fullscreen=0");
		     addWindow.focus() 
		}
		
//this allows all things in the list to be checked/unchecked
function checkAll(chkid)
{ 
for (i = 0; i < chkid.length; i++)
	chkid[i].checked = true ;
	
}

function uncheckAll(chkid)
{
for (i = 0; i < chkid.length; i++)
	chkid[i].checked = false ;
}

//this is probably a better version of the above
function selectAll(obj) { 
var checkBoxes = document.getElementsByTagName('input'); 
for (i = 0; i < checkBoxes.length; i++) { 
if (obj.checked == true) { 
checkBoxes[i].checked = true; // this checks all the boxes 
} else { 
checkBoxes[i].checked = false; // this unchecks all the boxes 
} 
} 
} 

//This is to make IE format all the input boxes the same way 
//got this from http://cf-bill.blogspot.com/2005/05/styling-all-input-typetext-webpage.html
function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 


function prepareTextBoxes(){
 if (!document.getElementsByTagName) return;
 var oi=0;
 var thisObj;
 var objs = document.getElementsByTagName("input");


 for (oi=0;oi<objs.length;oi++) {
  thisObj = objs[oi];
  if(thisObj.getAttribute('type') == 'submit'){
   thisObj.className = 'text ' + thisObj.className;
  }
 }
}

addEvent(window, "load", prepareTextBoxes);

