// JavaScript Document
function check_validate() {
	if (document.form_one.validate.checked == true) {
		return true;
	}
	else {
		alert("Please read section: \"Read Carefully Before Submitting\" and accept the terms!");
		document.form_one.validate.focus();
		return false;
	}
}
function popupWindows() {
	
    if(!document.getElementsByTagName) {
         return;
    }
    var scrW = screen.availWidth;
    var scrH = screen.availHeight;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
			//alert('here');
         var anchor = anchors[i];
         var linkDest = anchor.getAttribute("href");
         var relIndex = anchor.getAttribute("rel");
         var relSplit = relIndex.split("|");
         var windowAttributes = "";
         if(relSplit[0] == "popup") {
              if (relSplit[1] > scrW) {
                 pW = scrW - 10;
              }
              else {
                 pW = relSplit[1];
              }
              if (relSplit[2] > scrH) {
                 pH = scrH - 40;
              }
              else {
                 pH = relSplit[2];
              }
              scrX = (scrW - pW - 10) * .5;
              scrY = (scrH - pH - 30) * .5;
              var windowAttributes = "width=" + pW + ",height=" + pH + ",left=" + scrX + ",top=" + scrY + ",screenX=" + scrX + ",screenY=" + scrY;
              windowAttributes += ",location=" + relSplit[4] + ",resizable=" + relSplit[4] + ",scrollbars=" + relSplit[4];
              anchor.setAttribute("href", "javascript:popupWin('" + linkDest + "','" + windowAttributes + "')");
         }
    }
}
function popupWin(link,attribs) {
    var popupWin = null;
    popupWin = window.open(link,'winPopup',attribs);  
}

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 = "_blank";
 }
}

function initialize() {
    externalLinks();
	popupWindows();
	//date();
	//nav_active();
	//parent_nav_active();
	//user_focus();
}
window.onload = initialize;

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);	
}

function acc_close() {
	document.getElementById('accolade_more').style.display = 'none';
}
function acc_open() {
	document.getElementById('accolade_more').style.display = 'block';
}
/*
function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);	
}
*/
//email validate
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

function validate_contact(){
	var email=document.forms['contact'].email	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email")
		email.focus()
		return false
	}
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	return true
 }
 //end email validate
// validate order
function validate_order() {	
	
	if (document.forms[0].wood_type.value=="0"){
	alert("Please Select a Wood Type")
	document.forms[0].wood_type.focus()
	return false
	}
	if (document.forms[0].finish.value=="0"){
	alert("Please Select a Finish")
	document.forms[0].finish.focus()
	return false
	}
	if (document.forms[0].quantity.value=="0"){
	alert("Please Select a Quantity")
	document.forms[0].quantity.focus()
	return false
	}	
}