﻿function DE(el){return document.getElementById(el);}

function checkForm(which) {

var pass=true;
var msg="";
var errNum=0;

if (document.images) {
	for (i=0;i<which.length;i++) {
		var tempobj=which.elements[i];
	
		if(tempobj.name=="name" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter your name.\n";
		//break;
		
			}
			
		if(tempobj.name=="company" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter your company's name.\n";
		//break;
		
			}
			
		if(tempobj.name=="email" && tempobj.value!="" && checkEmail(tempobj.value)==false){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a valid email or leave blank.\n"
		//break;
		
			}
			
		if((tempobj.name=="number" || tempobj.name=="phone") && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a phone number.\n"
		//break;
			}
			
		if(tempobj.name=="caption" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a caption.\n"
		//break;
			}
			
		if(tempobj.name=="timeStamp" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a valid date (mm//dd/yyyy).\n"
		//break;
			}
		
		if(tempobj.name=="description" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a description.\n"
		//break;
			
	      }
	      
	    if(tempobj.name=="storename" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a name for this store.\n"
		//break;
			
	      }
	      
	    if(tempobj.name=="city" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a city name.\n"
		//break;
			
	      }
	      
	    if(tempobj.name=="region" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please select a state or province.\n"
		//break;
			
	      }
	      
	    if(tempobj.name=="country" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please select a country.\n"
		//break;
			
	      }
	       
	    if(tempobj.name=="groups" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please select at least one product group.\n"
		//break;
			
	    }   
	     
	    if(tempobj.name=="program" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please select the program type of this location.\n"
		//break;
			
	    }   
	   
	    if(tempobj.name=="my_name" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter your name.\n"
		//break;
			
	    }
	    
	    if(tempobj.name=="my_email" && checkEmail(tempobj.value)==false){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a valid email for yourself.\n"
		//break;
			
	    }
	    
	    if(tempobj.name=="friend_name" && tempobj.value==""){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter your friend's name.\n"
		//break;
			
	    }
	    
	    if(tempobj.name=="friend_email" && checkEmail(tempobj.value)==false){
		pass=false;
		errNum++;
		msg=msg+"  "+errNum+". Please enter a valid email for your friend.\n"
		//break;
			
	    }   
      }
   }
   
 


if (!pass) {
	//tempobj.value="";
	//tempobj.focus();
	alert("ERROR! We found "+errNum+" problem(s) with your submission!\n\n"+msg+"\n\nPlease review and try again.");
	return false;
	
	
		}
		
else{
	return true;
	
	}	

} 

function showThankYou(){
	alert("Thank you!<br />Your form has been submitted successfully.");
	return;
	}
	
//open a sizable window with scroll optional
//------------------------------------------
function openWin (URL, width, height, scroll, resize) {
		OpenedWin = window.open(URL, "_blank", "width="+width+",height="+height+", status=no,menubar=no,location=no,toolbar=no,directories=no,scrollbars="+scroll+",resizable="+resize);
		
		var NewX = (screen.availWidth/2)-(width/2);
		var NewY = (screen.availHeight/2)-(height/2);
		OpenedWin.moveTo(NewX, NewY);
		NewX = null;
		NewY = null;
		
		}
//degha function to launch decorator
//-----------------------------------
function launchDegha(vId,vlbhb, s, p){
	var site;
	var webAddress;
	
	if(s=="lamwood" || s==""){
		site="lw";
		webAddress="lamwoodproducts";
	}	
	if(s=="silverwood"){
		site="sw";
		webAddress="silverwoodflooring";
	}
	if(p!="" && p!=null){
		site=site+"_"+p;
	}
	//http://www.silverwoodflooring.degha.com/deghaweb/deghamlweb.php?Idioma=1&lbhb=1&Empresa=sw_tb
	if (screen.height < 768)
	r = window.open("http://"+webAddress+".degha.com//deghaweb/deghamlweb.php?Idioma="+vId+"&lbhb="+vlbhb+"&Empresa="+site, "Digital_Decorator", ' resizable=0, fullscreen=1,menubar=0,toolbar=0,location=0,status=0,status=0')
	else

	r = window.open("http://"+webAddress+".degha.com//deghaweb/deghamlweb.php?Idioma="+vId+"&lbhb="+vlbhb+"&Empresa="+site, "Digital_Decorator", ' resizable=0, fullscreen=0,menubar=0,toolbar=0,location=0,status=0,status=0 , width=' + 800 +' ,height='+ 670)
}

// only allow numbers or characters
//---------------------------------
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place

function checkChar(e, type)
{
	var key;
	var keychar;
	var charString;
	
	//handle both cases - any character expect quotes, or just numbers
	if (type=="chars")
		charString="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^*()_+-=<>?,./:;~ ";
	else if (type=="nums")
		charString="0123456789.";
	else
		charString="";
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;
	
	// alphas and numbers
	else if (((charString).indexOf(keychar) > -1))
	   return true;
	else
	   return false;
}


//---------------------------------
// show OR hide funtion depends
// on if element is shown or hidden
//----------------------------------
function shoh(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
			//filter(("img"+id),'imgin');			
		} else {
			//filter(("img"+id),'imgout');
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				//filter(("img"+id),'imgin');
			} else {
				//filter(("img"+id),'imgout');	
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				//filter(("img"+id),'imgout');
				document.all.id.style.display = 'none';
			}
		}
	}
}

var expanded = false;

//------------------------------
// display element by ID
//------------------------------
function show(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
			
	} else { 
		if (document.layers) {	
				document.id.display = 'block';
				
		} else {
				document.all.id.style.display = 'block';
			}

		}
}

//------------------------------
// hide element by ID
//------------------------------
function hide(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
			
	} else { 
		if (document.layers) {	
				document.id.display = 'none';
				
		} else {
				document.all.id.style.display = 'none';
			}
		}
}

//--------------AJAX-------------------
//function to update page with content
//-------------------------------------

	var req;
	var cBox;
	var special_func;
	var ajax_url;

	function loadXMLDoc(url) 
	{
	    // branch for native XMLHttpRequest object
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = processReqChange;
	        req.open("GET", url, true);
	        req.send(null);
	    // branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = processReqChange;
	            req.open("GET", url, true);
	            req.send();
	        }
	    }
	   ajax_url = url;
	}
	
	
	function loadAjax(url, contentBox, waitMsg) {
		
		
		//check where we want data loaded
		if (contentBox=="" || contentBox==null)
			cBox = "content";
		else
			cBox = contentBox;	
			
		// show 'working'
		if (cBox!="alert"){
			show(cBox);
			
			var cBoxContent = document.getElementById(cBox);
			var img = "<img src='"+depth+"images/loading.gif' border='0' /> "
			
			if(waitMsg=="" || waitMsg==null){
				if(cBoxContent.innerHTML=="")
					cBoxContent.innerHTML = img+ "loading your request";
				else
					cBoxContent.innerHTML = "<div class='loading'>"+img+"loading your request</div>" + cBoxContent.innerHTML;
			}
			else{
			
				cBoxContent.innerHTML = "<div style='padding:4px;'>"+waitMsg+"</div>";
			}
		}
		// Build the URL to connect to
		//var url = escape(prod) + "/" + escape(page)+ "?";
		
		//check queryString
		//if ((q1!="") && (q1!=null))
		//	url = url + q1 + "=" + v1 + "&";
		
		//add language	
		//url = url  + "lang=" + escape(lang);
		
		//check for case of a special function
		//if(page == "show_colours.asp" || page == prod+"_products.asp" || page == "colour_details.asp" || page == "product_details.asp" || page == prod+"_search.asp" || page =="show_samples.asp")
		//	special_func = "lightbox";
			
		
		loadXMLDoc(url);
		//document.write(url);
	}
	
	
	function processReqChange() 
	{
	    // only if req shows "complete"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
	          
	            var response = req.responseText;
   				//load ccode only if not blank
   				if(response != "")
   					
   					
   					if (cBox=="alert"){
   						
   						alert(response);
   						return true;
   					}
   					
   					else{
   					
   						document.getElementById(cBox).innerHTML=response;
	   					//document.getElementById("error_check").value=response;
	   					
		        		//attempt fix for lighbox effect
		        		//load after images are loaded
		        		//if(special_func=="lightbox")
		        		initLightbox();
		        		//call initialize function 
		        		//(in most cases does nothing, unless overriden by set function)
		        		initialize();
	        		}
	        		
	        } else {
	        	
	        	if(cBox=="alert")
	        	
	        		alert("There was a problem retrieving the XML data:\n" + req.statusText)
	        	
	        	else{
					// show 'error'
					document.getElementById(cBox).innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText;
					alertBox("error check url: <a href='"+ajax_url+"'>go</a>");
	       		}
	        }
	    }
	}
	//if a website is innactive, alert user
	function showInactive(){
		alert("The website for this product is currently under development. Once it's ready, you'll be able to see all products and store availability.\n\nPlease check back soon!");
	}
	//empty initialize function that can be overriden
	function initialize(){
		return;
	}
	function preload(){
		return;
	}
	
//--------------------------------------------------------------------
// END OF AJAX FUNCTIONS
//--------------------------------------------------------------------	

/*function to replace all occurances of a substring in a string*/

function replaceAll(s, f, r){
	while (s.indexOf(f) > -1)
		s = s.replace(f,r);
	//return the replaced string
	return s;
}
	
function checkEmail (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|ca|tv|uk|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Please enter a valid e-mail address.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("E-mail address contains invalid characters!");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("E-mail address contains invalid characters!");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The e-mail username appears invalid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("E-mail destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("E-mail address appears invalid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The e-mail address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This e-mail address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}