//var emailExp = /^[w+\.\_\-]\@[\w+\.\w{2,3}]+$/;
var emailExp = /^[a-zA-Z0-9\-\_]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/;
function Validate_Search() {
  with (document.frmSearch) {
	if (cate.options[cate.selectedIndex].value == "0") {
	  if (Trim(item_no.value) == "") {
		alert("You must provide keywords to perform a search.");
		//item_no.focus();
		cate.focus();
		return false;		
	  }	
	}  
	
	return true;
  }
}

function Validate_Contact() {
  with (document.frmContact) {
  // realname
	if (Trim(realname.value) == "") {
	  alert("Please provide us your name.");
	  realname.focus();
	  return false;
	}  
	// store name
	if (Trim(storename.value) == "") {
	  alert("Please provide us your store name.");
	  storename.focus();
	  return false;
	}  
	// address 1
	if (Trim(addr1.value) == "") {
	  alert("Please provide us the address.");
	  addr1.focus();
	  return false;
	}
	// city  
	if (Trim(city.value) == "") {
	  alert("Please provide us your city.");
	  city.focus();
	  return false;
	}  
	// state
	if (states.options[states.selectedIndex].value == "0") {
	  alert("Please select the States");
	  states.focus();
	  return false;
	}
	// zipcode  
	if (Trim(zip.value) == "") {
	  alert("Please provide us your zipcode.");
	  zip.focus();
	  return false;
	}  
	// email
	if (Trim(email.value) == "") {
	  alert("Please provide us your email address.");	
	  email.focus();
	  return false;
	}
	/*else if (!emailExp.test.value) {
	  alert("The email address you have entered is incorrect, please try again.");	
	  email.focus();
	  return false;
	}*/
	// comment
	if (Trim(comment.value) == "") {
	  alert("Please provide your comment.");
	  comment.focus();
	  return false;
	}
	
	return true;
  }
}

function Reset_Contact() {
  with (document.frmContact) {
	realname.value = "";
	storename.value = "";
	addr1.value = "";
	addr2.value = "";
	city.value = "";
	states.options[state.selectedIndex].value = 0;
	zip.value = "";
	phone.value = "";
	email.value = "";
	comment.value = "";
	
	return false;	
  }
}

// this function trims the string - called as a subroutine later
function Trim(arg) {
    var trimvalue = "";
    arglen = arg.length;
    if (arglen < 1) {
        return trimvalue;
    }
    // trim from the left
    i = 0;
    pos = -1;
    while (i < arglen) {
        if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
            pos = i;
            break;
        }
        i++;
    }

   // trim from the right
    var lastpos = -1;
    i = arglen;
    while (i >= 0) {
        if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
            lastpos = i;
            break;
        }
        i--;
    }
    // return the trimmed value
    trimvalue = arg.substring(pos,lastpos + 1);
    return trimvalue;
}

var curSelected = null;
function selectRow(row, id) {
  row.style.backgroundColor = '#316AC5';
  row.style.color = '#FFFFFF';

  if (curSelected != null) {
    curSelected.style.backgroundColor = '#FFFFFF';
    curSelected.style.color = '#000000';
  }

  curSelected = row;

  document.frmProduct.product_id.value = id;
  //alert(document.frmProduct.product_id.value);
}

function changeColor(Item, rowid, prevColor, simg) {
  var tdColor='#EBEBEB';
  var trColor = '#66AAFF';
  var bothColor='#000000';

  var thisTable = Item.parentElement;
	
	var oldColor  = null;
	var oldId = null;

	with (document.frmList) {
		oldId = rid.value;
		oldColor = pvcolor.value;
		rid.value = rowid;
		pvcolor.value = prevColor;
		img.value = simg;
		
		if (Trim(simg) == "") { // || simg.substring(simg.length - 3, simg.length) <> "jpg") {
			eval('document.picbox.src = "images/unavailable.jpg"');
		}
		else {
			eval('document.picbox.src = simg');
		}
	}

  /* Reset bgColor of the previous rows */
  for (i=1; i<=thisTable.rows.length; i++) {
    if (i != rowid) {
				if (parseInt(oldId,10) != parseInt(rowid, 10)) {
						thisTable.rows[oldId].style.backgroundColor = oldColor;
						//thisTable.rows[i].setAttribute('bgColor', oldColor);
				}
    }
    else {
      thisTable.rows[i].style.backgroundColor = trColor;
	  //thisTable.rows[i].setAttribute('bgColor', trColor);

    }
  }

  if (Item.tagName == 'TR') {
    if(Item.getAttribute('bgColor').toUpperCase() == trColor) {
      Item.setAttribute('bgColor');
    } 
    else {
      Item.setAttribute('bgColor',trColor);
      for(i=1; i<Item.cells.length; i++){
        if(Item.cells(i).getAttribute('bgColor') == tdColor){
          Item.cells(i).setAttribute('bgColor',bothColor);
        }
      }
    }
  } 
}

function popupwin(oU) {
  //alert('The information is not yet available.');
  Win = window.open('','','top='+((screen.height - 545) / 2)+',left='+((screen.width - 642) / 2)+'+,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=642,height=545'); 
  Win.location.href = oU;
  //return false;
  
}

var IE = false;
var NS=false;
var browser_version = parseInt(navigator.appVersion);
var browser_type = navigator.appName;if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) { IE = true; } else if (browser_type == "Netscape" && (browser_version >= 4) && (browser_version < 5)) { NS = true; }else if (browser_type == "Netscape" && (browser_version >= 5)) { NS = false; }

function createLayer(vimg) { 
  if (NS) {
    document.write('<ILAYER>');
    document.write('<LAYER id="bpicbox" visibility="hide" z-index="10" onMouseOver="showLayer(bpicbox);" onMouseOut="hideLayer(bpicbox);">');
    document.write('<IMG src="' + vimg + '" border="0">');
    document.write('</LAYER>');
    document.write('<LAYER visibility="show" z-index="5" onMouseOver="showLayer(bpicbox);" onMouseOut="hideLayer(bpicbox);">');
    document.write('<IMG src="' + vimg + '" border="0" width="240" height="242">');
    document.write('</LAYER>');
    document.write('</ILAYER>');
  }
  if (IE) {
    document.write('<DIV id="bpicbox" style="position: absolute; visibility: hidden; z-index: 10" onMouseOver="showLayer(bpicbox);" onMouseOut="hideLayer(bpicbox);">');
    document.write('<IMG src="' + vimg + '" border="0">');
    document.write('</DIV>');
    document.write('<IMG src="' + vimg + '" border="0" onMouseOver="showLayer(bpicbox);" width="240" height="242">');
  }
}

var name = new Image();
function showLayer(name) {
  if (IE) { name.style.visibility = "visible"; }
  if (NS) { name.visibility = "show"; }
}

function hideLayer(name) {
  if (IE) { name.style.visibility = "hidden"; }
  if (NS) { name.visibility = "hide"; }
}

function blockerror() {
  return true;
}

var statusTxt = "Welcome to Embassy International Company. We are one of the country's elite suppliers of bedroom furniture.";
window.defaultStatus = statusTxt;
window.status = statusTxt;

window.onerror = blockerror;
