
	CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
	function IsIE() { return CSAg.indexOf("MSIE") > 0;}
	function CSIEStyl(s) { return document.all.tags("div")[s].style; }
	function CSNSStyl(s) { return CSFindElement(s,0); }

	function CSFindElement(n,ly) { 
		if (CSBVers < 4) return document[n];
		var curDoc = ly ? ly.document : document; var elem = curDoc[n];
		if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
			elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
		return elem;
	}

	function CSURLPopupShow(formName, popupName, target) {
		var form  = CSFindElement(formName);
		var popup = form.elements[popupName];
		window.open(popup.options[popup.selectedIndex].value, target);
		popup.selectedIndex = 0;
	}

	var tab = "";
	
	function getTab(){return tab;}
	function setTab(d){tab = d;}
			
	function expandContract(tbodyid){	
		document.getElementById(getTab()).style.display = "none";
		document.getElementById(tbodyid).style.display = "";
		setTab(tbodyid);
	}
	
	var banners = new Array(
		'Images/mainImage.jpg',
		'Images/mainImage.jpg',
		'Images/511Banner.jpg',
		'Images/apparelBanner.jpg');
	var linx = new Array(
		'default.asp',
		'default.asp',
		'flyers/flyer511.html',
		'sanmar/product_overview.html');
	var old = 0;
	var current = 0;
	
	function init()
	{
		if (!document.images) return
		while (current == old){
			//current = Math.floor(Math.random()*banners.length);
			if (current < 3 ){
				current = current + 1;
			}
			else
				current = 0;
		}
		old = current;
		document.images['banner'].src = banners[current];
		setTimeout('init()',4000);
	}

	function sendPage()
	{
		location.href = linx[current];
	}

	moz=document.getElementById&&!document.all
	mozHeightOffset=20
	
	hmFactor=4 // iframe size increases by 4 every click ??????
			
	function resize_iframe2(){
		document.getElementById("iframe_id").height=null // required for Moz
		document.getElementById('iframe_id').height=window.frames["iframe_name"].document.body.scrollHeight+(moz?mozHeightOffset:0)
		document.getElementById('iframe_id').width=document.getElementById('td1').offsetWidth - hmFactor
	}
	
	var currentpage;
	function changeIt() {
		newpage = (currentpage-1) ? 1 : 2;
		return "iframe_page" + newpage + ".html";
	}
	
	function getObj(name) {
	  if (document.getElementById) {
	  	this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	  }
	  else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	  }
	  else if (document.layers) {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	  }
	}

	function validateRegistrationForm(regForm){
		errorString="";
		errorNum=0;
		if (regForm.rName.value == '') {
			errorString = "Name\n";
			errorNum++;
		}
		if (regForm.rAgency.value == '') {
			errorString = errorString + "Agency\n";
			errorNum++;
		}
		if (regForm.rEmailAddress.value == '') {
			errorString = errorString + "Email\n";
			errorNum++;
		}
		if (regForm.rBusinessPhone.value == '') {
			errorString = errorString + "Business Phone\n";
			errorNum++;
		}
		if (regForm.rBusinessFax.value == '') {
			errorString = errorString + "Business Fax";
			errorNum++;
		}
		if (errorNum){
			alert("Please enter the following information:\n" + errorString);
			return false;
		}
		else
			return true;
	}

	function validateContactForm(emailForm){
		errorString="";
		errorNum=0;
		if (emailForm.contactName.value == '') {
			errorString = "Name\n";
			errorNum++;
		}
		if (emailForm.contactEmail.value == '') {
			errorString = errorString + "Email\n";
			errorNum++;
		}
		if (emailForm.subject.value == '') {
			errorString = errorString + "Subject\n";
			errorNum++;
		}
		if (emailForm.message.value == '') {
			errorString = errorString + "Message";
			errorNum++;
		}
		if (errorNum){
			alert("Please enter the following information:\n" + errorString);
			return false;
		}
		else
			return true;
	}



function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field (" + fld.name + ")  has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}



function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}


function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}   


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value); // value of field with whitespace trimmed off
    
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address. ie: user@domain.com\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address. ie: user@domain.com\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters. ie: user@domain.com\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter a phone number. ie: 8012345789\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code. ie: 8012345789\n";
        fld.style.background = 'Yellow';
    } 
    return error;
}
