/*
Sean Hecking
brulant
sean.hecking@brulant.com
*/


// navigation
sfHover = function() {
	return;
	var ul = document.getElementById("cabinetLinks");
	if (!ul)
		return;
	var sfEls = ul.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);


function hideCustomizationOptions()
{
	document.write("<style type='text/css'>.customizationOptions h3 { display: none !important; }</style>");
}

// toggle popup
var _currentId = -1;

function closePopup(evt)
{
	var srcElement;
	if (!evt)
	{
		evt = window.event;
		srcElement = evt.srcElement;
	}
	else
		srcElement = evt.target;
	
	togglePopup3(null, srcElement.parentNode.parentNode.id, "", "");
	
}

function togglePopup3(sourceElement, id, title, imageUrl, description)
{
	var element = document.getElementById(id);
	if (element)
	{
			var h3 = document.getElementById("displayTitle");
			var img = document.getElementById("displayImg");
			var fp = document.getElementById("displayDescription");
			
			if (h3  && h3.innerHTML != title)
				h3.innerHTML = title;
				
			if (img.src != imageUrl && imageUrl != "")
			{
				img.alt = title;
				img.src = imageUrl; 
			}
			
			if (fp)
			{ 
				if (description)
					fp.innerHTML = description;
			}
								
			element.className = (element.className == "popUpActivated popUpWindow") ? "popUpDeactived" : "popUpActivated popUpWindow"; 
	}
	else
	{
		var idtitle = id + title;
		var div = document.createElement("div");
		div.className = "popUpActivated popUpWindow";
		div.id = id;
		var p = document.createElement("p");
		var h3 = document.createElement("h3");
		h3.id = "displayTitle";
		h3.innerHTML = title;
		var a = document.createElement("a");
		a.className = "closePopUp";
		a.innerHTML = "Close";
		a.onclick = closePopup;
		var img = document.createElement("img");
		img.id = "displayImg";
		img.alt = title;
		img.src = imageUrl; 
		
		var contentDiv = document.createElement("div");
		
		var fp = document.createElement("p");
		fp.id = "displayDescription";
		fp.className = "popUpContent";
		if (description)
			fp.innerHTML = description;
		
		contentDiv.appendChild(h3);
		contentDiv.appendChild(fp);
		
		p.appendChild(a);
		div.appendChild(p);
		div.appendChild(img);
		div.appendChild(contentDiv);
		
		document.body.appendChild(div);
		
		setInterval("centerIt('" + id + "')", 10);
		
	}
}


function togglePopup(id){

	//var myPopup = document.getElementById(id);
	var myWindow = document.getElementById('popUpWindow');

	if(!(_currentId == id)){
		//myWindow.innerHTML = myPopup.innerHTML;
		//var myImg = myPopup.getElementsByTagName('img');
		//var myPopUpImg = myWindow.getElementsByTagName('img');
		//var myClasses = document.getElementsByClassName('popUpWindow');

		//Checks if classname is set to popupOn
		window.setInterval("centerIt('popUpWindow')", 10);
		myWindow.style.display = 'block';
		myWindow.className='popUpActivated';
		//if(window.XMLHttpRequest) myPopUpImg[0].src=myImg[0].getAttribute('name')+'_lg.jpg';
		//else myPopUpImg[0].src=myImg[0].attributes('name').value+'_lg.jpg';
		_currentId = id;
	} else {
		myWindow.className='popUpDeactived';
		myWindow.style.display = 'none';
		_currentId = -1;
	}
}

// center popup
function centerIt(Idname){
	var my_width  = 0;
	var my_height = 0;

	if ( typeof( window.innerWidth ) == 'number' ){
		my_width  = window.innerWidth;
		my_height = window.innerHeight;
	}else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
		my_width  = document.documentElement.clientWidth;
		my_height = document.documentElement.clientHeight;
	}
	else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
		my_width  = document.body.clientWidth;
		my_height = document.body.clientHeight;
	}

	var scrollY = 0;

	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
		scrollY = window.scrollY;
	}

	var setX = ( my_width  - document.getElementById(Idname).style.width  ) / 2;
	var setY = ( my_height - document.getElementById(Idname).style.height ) / 2 + scrollY;

	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;


	//checks popupWindow2, popupWindow
	if(Idname=='popUpWindow2'){
		document.getElementById(Idname).style.left = setX - 392 + "px";
		document.getElementById(Idname).style.top  = setY - 300 + "px";
	}else{
		document.getElementById(Idname).style.left = setX - 140 + "px";
		document.getElementById(Idname).style.top  = setY - 200 + "px";
	}
}


/*function closePopUp(id){
	document.getElementById(id).style.display = 'none';
	document.getElementById(id).className='popUpDeactived';
}*/

function openFooter(footerName){
	//set the page name
	var myUrl = '/pages/'+footerName+'.html';
	//check to see if the right pages are called
	if(myUrl == 'terms' || 'privacy' || 'warranty'){
		window.open(myUrl, 'footerWin', 'left=20,top=20,width=525,height=400,scrollbars=1,toolbar=0,resizable=0,status=0');
	}else{
		return false
	}
}

function loadUrl(url)
{
	location.href = url;
}



function submitcontactus()
{
	if(validateContactUs())
	{
		var frm = document.forms[0];
		transfervalue("vName","hName");
		transfervalue("vEmail","hEmail");
		transfervalue("vAddress","hAddress");
		transfervalue("vCity","hCity");
		transfervalue("vState","hState");
		transfervalue("vZip","hZip");
		transfervalue("vPhone","hPhone");
		transfervalue("vComments","hComments");
		frm.action = "/Pages/ContactUsResults.aspx";
		frm.method = "post";		
		frm.submit();
	}
}


function transfervalue(from, to)
{
	document.getElementById(to).value = document.getElementById(from).value;
}

function validateContactUs()
{
	var str = " is a required field.\n"
	var msg = ""
	if(!validate_required("vName")){msg = msg + "Name" + str;}
	if(!validate_required("vEmail")){msg = msg + "Email" + str;}
	if(!validateEmail("vEmail")){msg = msg + "Please enter a valid email address.\n";}
	if(!validate_required("vPhone")){msg = msg + "Phone Number" + str;}	
	if(!validate_phone("vPhone")){msg = msg + "Please enter phone number in the following format: (555) 555-1234.\n";}
	var zipStr = validateZIP("vZip");
	if(zipStr.length > 0){msg = msg + zipStr;}
	if(!validate_required("vComments")){msg = msg + "Please enter your inquiry.";}
	
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	return true;
}

function validate_required(obj)
{
	var field = document.getElementById(obj);
	with (field)
	{
		if (value==null||value=="")
		  {return false}
		else {return true}
	}
}
function validate_phone(obj) 
{
 	var s = document.getElementById(obj).value;
 	if(s.length > 0)
 	{
	     // Check for correct phone number
	     rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
	 
	     if (!rePhoneNumber.test(s)) {
	          //alert("Phone Number Must Be Entered As: (555) 555-1234");
	          return false;
	     }
	} 
	return true;
} 
function validateZIP(obj) {

	var valid = "0123456789";
	var field = document.getElementById(obj).value;
	if (field.length!=5) {
		return "Zip code must be 5 digits.\n";
	}
	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			return "Invalid characters in your zip code.\n";
		}
	}
	return "";
}
function validateEmail(obj) {	
	var field = document.getElementById(obj).value;
	if(field.length > 0)
	{
		return (field.indexOf(".") > 2) && (field.indexOf("@") > 0); 
	}
	return true;
}

