// JavaScript Document
// Author : Nay Lwin
// Date : 2007/09/22
// Copyright : Woodcraftsrus.com

// used in header search box
function got_focus(elm){
	if( elm && elm!='' ){
		elm.value='';
		elm.className=elm.className.replace(" gr", " bk");
	}
		
} 
function got_blur(elm){
	if( elm && elm!='' ){
		if(!elm.value){
			elm.className=elm.className.replace(" bk", " gr");
			elm.value='Keyword(s) or Item #';
		}
	}
}
function do_search_form(f){
	var k = "";
	if(typeof f != 'undefined')
		if(typeof f.keywords != 'undefined')
			if(f.keywords.value != "")
				k = '?k='+escape(f.keywords.value);
				
	pageTracker._trackPageview('/submit_search_keywords.html'+k);
}

function CVVPopUpWindow(){
 var feat = 'toolbar=no,location=no,directories=no,status=no,menubar=no,' + 
			'scrollbars=no,resizable=no,copyhistory=no,' +
			'width=600,height=240,screenX=150,screenY=150,top=150,left=150';	
 var newwin = window.open('/cvv.php','popupWindow',feat);	
}

/* AHAH Functions */
function pop_up_new(filename, tall, wide){
    var mywin = window.open(filename,'special','top=20,screenx=20,left=20,screeny=20,width=' + wide + ',height=' + tall + ',buttons=no,scrollbars=no,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no');
	mywin.focus();
	return false;
}
function pop_up_new_scroll(filename, tall, wide){
    var mywin = window.open(filename,'special','top=20,screenx=20,left=20,screeny=20,width=' + wide + ',height=' + tall + ',buttons=no,scrollbars=yes,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no');
	mywin.focus();
	return false;
}
function pop_up_new_scroll_name(filename, tall, wide, name){
	if(name != "") 
		pname = name;
	else 
		pname = 'special';
    var mywin = window.open(filename,pname,'top=20,screenx=20,left=20,screeny=20,width=' + wide + ',height=' + tall + ',buttons=no,scrollbars=yes,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no');
	mywin.focus();
	return false;
}
/* End AHAH */

 function switch_div_content(id,idToShow,numOfLoop) {
	var eById = isGetElementByIdDefined();
	var ie4 = (document.all)? true:false;
	var ns6 = (!document.all && document.getElementById) ? true : false;
	var loopCount = parseInt(numOfLoop);
  
  if(eById){
  	document.getElementById(id).style.display = 'none';
	for(var i=2; i<=loopCount; i++){
		document.getElementById(id+i).style.display = 'none';
	}
	if(idToShow!=""){	
  		document.getElementById(idToShow).style.display = 'block';
	}
  }else if (ns6) {
  	document.getElementsByTagName("*").namedItem(id).style.display = 'none';
	for(var i=2; i<=loopCount; i++){
		document.getElementsByTagName("*").namedItem(id+i).style.display = 'none';
	}
	if(idToShow!=""){
    	document.getElementsByTagName("*").namedItem(idToShow).style.display = 'block';
	}
  }else if (ie4) {
  	document.all[id].style.display = 'none';
	for(var i=2; i<=loopCount; i++){
		document.all[id+i].style.display = 'none';
	}
	if(idToShow!=""){
  		document.all[idToShow].style.display = 'block';
	}	
  }
 }// End switch_div_content
 
 /*
 We re-use this function from old version ajax_functions.js
 */
 function isGetElementByIdDefined(){
	 if(typeof document.getElementById != 'undefined')
		return true;
	 else
		return false;
 }
 
 /* Validation */
function Trim(x) {
	var i;
	if (x.length == 0) {return "";};
	i = x.length - 1;
	while (x.substring(i,i+1) == " " && i > 0 )  {
		x = x.substring(0,i);
		i--;
	}
	if (x.length == 0) {return "";};
	while (x.substring(0,1) == " " && x != "" )  {
		x = x.substring(1,x.length);
		i++;
	}
	return x;
}// end Trim

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){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
}//echeck

// Encoding/Decoding functions
function encode_utf8( s ){  return unescape( encodeURIComponent( s ) );}
function decode_utf8( s ){  return decodeURIComponent( escape( s ) );}