// JavaScript Document

var newWin=0;

function popUpWin(page,popup)
{
	var Opt;

	switch (popup) {
		case "1":
			Opt = 'personalbar=no,toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=350,height=300,left=100,top=100,screenX=100,screenY=100';
			break;
		case "2":
			Opt = 'personalbar=no,toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=500,height=300,left=100,top=100,screenX=100,screenY=100';
			break;
		case "3":
			Opt = 'personalbar=no,toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=200,left=100,top=100,screenX=100,screenY=100';
			break;
		case "4":
			Opt = 'personalbar=no,toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=500,height=425,left=100,top=100,screenX=100,screenY=100';
			break;
		default:
			page = "popup.html?" + page;
			Opt = 'resizeable=1,width=200,height=200,top=100,left=100,screenX=100,screenY=100';
			break;
	}
	
  	if(newWin)
  	{
    	if(!newWin.closed) newWin.close();
  	}
	
	newWin = window.open(page,'newWin',Opt);
}


var photoWindow = 0; 

function photo_open(url, width, height)
{
	if(photoWindow)
  	{
    	if(!photoWindow.closed) photoWindow.close();
  	}
	
	width = parseInt(width) + 20;
	height = parseInt(height) + 75;
	
    photoWindow = window.open(url,"photo",'statusbar=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + width + ',height=' + height);
	photoWindow.focus();
}

function place_menu()
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="490" height="90">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="flash/menu.swf" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
    document.write('<embed src="flash/menu.swf" quality="high" menu="false" wmode="transparent" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="490" height="90"></embed>');
	document.write('</object>');
}

function place_header()
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="490" height="195">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="flash/header.swf" />');
    document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
    document.write('<param name="menu" value="false" />');
	document.write('<embed src="flash/header.swf" quality="high" menu="false" wmode="transparent" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="490" height="195"></embed>');
	document.write('</object>');
}

function place_video()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="320" height="290" id="duct_video" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="flash/duct_video.swf" />');
    document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
    document.write('<embed src="flash/duct_video.swf" quality="high" menu="false" wmode="transparent" name="duct_video" align="middle" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="320" height="290"></embed>');
	document.write('</object>');
}

function place_slideshow()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="165" height="123" id="ad" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="flash/ad.swf" />');
    document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="flash/ad.swf" quality="high" wmode="transparent" name="ad" align="middle" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="165" height="123"></embed>');
	document.write('</object>');
}

// contact form field info
var dfname = "First Name";
var dlname = "Last Name";
var demail = "Email";
var dphone = "Phone (No Dashes!)";
var dmessage = "Describe your problem or send request for free estimate";

function validate_contact_data()
{
	var frm = document.forms[0];
	
	if (frm.FirstName.value == "" || frm.FirstName.value == dfname)
	{
		alert("Your name is required!");
		frm.FirstName.style.backgroundColor = '#ffff00';
		frm.FirstName.focus();
	} else {
			if (frm.LastName.value == "" || frm.LastName.value == dlname) 
			{
				alert("Your last name is required!");
				frm.LastName.style.backgroundColor = '#ffff00';
				frm.LastName.focus();
			} else {
				if (frm.Phone.value == "" || isNaN(frm.Phone.value) || frm.Phone.value == dphone)
				{
					alert('Please enter a valid contact number!');
					frm.Phone.style.backgroundColor = '#ffff00';
					frm.Phone.focus();
				} else {
					if (check_email(frm.Email.value) == false || frm.Email.value == "" || frm.Email.value == demail)
					{
						alert('Email format is invalid!');
						frm.Email.style.backgroundColor = '#ffff00';
						frm.Email.focus();
					} else {
						if (frm.Message.value == "" || frm.Message.value == dmessage)
				   		{
							alert("Please input a message!");
							frm.Message.style.backgroundColor = '#ffff00';
							frm.Message.focus();
						} else {
							popUpWin('','3');
							frm.action = "sendinfo.php";
							frm.target = "newWin";
							frm.submit();
							frm.reset();
						}
					}
				}
			}
	}
	return false;
}

function validate_testimonial_data() 
{
	var frm = document.forms[0];
	
	if (frm.testimonial_name.value == "")
	{
		alert("Please enter your full name!");
		frm.testimonial_name.style.backgroundColor = '#ffff00';
		frm.testimonial_name.focus();
	} else {
		if (check_email(frm.testimonial_email.value) == false || frm.testimonial_email.value == "")
		{
			alert('Email format is invalid!');
			frm.testimonial_email.style.backgroundColor = '#ffff00';
			frm.testimonial_email.focus();
		} else {
			if (frm.testimonial_message.value == "")
	   		{
				alert("Please enter your testimonial!");
				frm.testimonial_message.style.backgroundColor = '#ffff00';
				frm.testimonial_message.focus();
			} else {
				popUpWin('','3');
				frm.action = "sendinfo.php";
				frm.target = "newWin";
				frm.submit();
				frm.reset();
			}
		}
	}
	return false;
}

function validate_service_data() 
{
	var frm = document.forms[0];
	
	if (frm.service_name.value == "")
	{
		alert("Please enter your full name!");
		frm.service_name.style.backgroundColor = '#ffff00';
		frm.service_name.focus();
	} else {
		if (check_email(frm.service_email.value) == false)
		{
			alert('Email format is invalid!');
			frm.service_email.style.backgroundColor = '#ffff00';
			frm.service_email.focus();
		} else {
			if (frm.service_phone.value == "")
	   		{
				alert("Please enter your phone number!");
				frm.service_phone.style.backgroundColor = '#ffff00';
				frm.service_phone.focus();
			} else {
				if (!frm.service_online.checked && !frm.service_online.checked)
		   		{
					alert("Please choose a FREE consultation!");
				} else {
					popUpWin('','3');
					frm.action = "sendinfo.php";
					frm.target = "newWin";
					frm.submit();
					frm.reset();
				}
			}
		}
	}
	return false;
}

function check_email(email)
{
		var at_pos = email.indexOf("@");
		if (at_pos == -1)
		{
			return false;
		}
		
		var dot_pos = email.indexOf(".");
		if (dot_pos == -1)
		{
			return false;
		}
		
		var valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789@_-.";
		var len = email.length;
		
		for (var i=0; i < len; i++)
		{
			var letter = email.charAt(i).toLowerCase();
			if (valid_chars.indexOf(letter) != -1) 	continue;
			return false;
		}
}

function welcome() {
	if (readCookie("firstvisit") == null) {
		createCookie("firstvisit","yes",1);
		popUpWin("free_services.html","4");
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}