/*dw_main.js*/
/*shared functions for site*/

currentIndx=0;

function buildStateSelect() {
/*this function creates the United States dropdown list*/
var stateList = ["AK","AL","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NY","NV","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY"];
document.write("<option value=\"\"></option>");
for (x = 0; x < stateList.length; x++) {
	document.write("<option value=\""+stateList[x]+"\">"+stateList[x]+"</option>");
	}
}
						
function passvalues() {
/* this function passes the contact email address and order id to the payment form*/
/* set the unique order key */
document.dw_orderform.elements['orderkey'].value =  Math.floor(Math.random()* 999999999 );

/* create redirect query string to pass*/
var urlnew = baseurl + "_secure_pay.html?orderkey=" + document.dw_orderform.elements['orderkey'].value + "&ServiceOrdered=" + escape(document.dw_orderform.elements['ServiceOrdered'].value) + "&ThanksPage=" + document.dw_orderform.elements['ThanksPage'].value + "&ThanksText=" + document.dw_orderform.elements['ThanksText'].value + "&DisplayPrice=" + document.dw_orderform.elements['DisplayPrice'].value;

if (document.dw_orderform.elements['_req,from_Contactemail'])
	{
	urlnew = urlnew + "&_from_Contactemail=" + document.dw_orderform.elements['_req,from_Contactemail'].value;
	}
/* exceptions added for services with no email required */
else if (document.dw_orderform.elements['from_Contactemail'].value != '' )
	{
	urlnew = urlnew + "&_from_Contactemail=" + document.dw_orderform.elements['from_Contactemail'].value;
	}
else 
	{
	urlnew = urlnew + "&_from_Contactemail=none";
	}

/*pass it along*/
document.dw_orderform.elements['_redirectURL'].value = urlnew;
}

function getParams() {
/*this function passes the values posted to the form into an array named params*/
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}


/* change the thumbnail of the web site style selector*/
	function changeStyle() {
	/* split the template number from the file name */
	var splitArray = document.dw_orderform._req_SiteStyle.options[document.dw_orderform._req_SiteStyle.selectedIndex].value.split('|');
	document.styleImage.src = 'images/' + splitArray[1] + '_small.gif';
	currentIndx=document.dw_orderform._req_SiteStyle.selectedIndex; /*required to keep the slideshow functions up to date*/
	}
	

/* slideshow next function for the site styles on the order form*/
function nextStyle() {
if (currentIndx<document.dw_orderform._req_SiteStyle.length-1){
currentIndx=currentIndx+1;
document.dw_orderform._req_SiteStyle.selectedIndex = currentIndx;
changeStyle();
}
else {
currentIndx=1;
document.dw_orderform._req_SiteStyle.selectedIndex = currentIndx;
changeStyle();
}
}

/* slideshow previous function for the site styles on the order form*/
function prevStyle() {
if (currentIndx>1){
currentIndx=currentIndx-1;
document.dw_orderform._req_SiteStyle.selectedIndex = currentIndx;
changeStyle();
}
else {
currentIndx=document.dw_orderform._req_SiteStyle.length-1;
document.dw_orderform._req_SiteStyle.selectedIndex = currentIndx;
changeStyle();
}
}


	/* pop open the appropriate large version from the web site style selector*/
	function popupStyle() {
	/* split the template number from the file name */
	var splitArray = document.dw_orderform._req_SiteStyle.options[document.dw_orderform._req_SiteStyle.selectedIndex].value.split('|');
	
	if (splitArray[1] != 'none_selected') {
	whereToGo = 'images/' + splitArray[1] + '_large.gif' ;
	myWin = window.open( whereToGo, 'dw_styleWin', 'width=690,height=490,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0');
	myWin.focus();
		}
		else {alert('You must select a style from the drop-down menu on the left.');}
	}
	
	
	/* pop open the appropriate large version from the web site style selector*/
	function popupStyle2(num) {
	/* split the template number from the file name */
	whereToGo = 'images/site_examples/style' + num + '_large.gif' ;
	myWin = window.open( whereToGo, 'dw_styleWin', 'width=690,height=490,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0');
	myWin.focus();
	}
	
	function openWin(URL,w,h,WindowName) {
    var build;
    if (document.layers) { //NS4
      var left = window.screenX + ((window.outerWidth - w) / 2);
      var top = window.screenY + ((window.outerHeight - h) / 2);
      build = "screenX=" + left + ",screenY=" + top + ",resizable=yes,scrollbars=yes,width=" + w + ",height=" + h;
    } else if (document.all) { //IE4
      var left = (screen.width - w) / 2;
      var top = (screen.height - h) / 2;
      build = "left=" + left + ",top=" + top + ",resizable=yes,scrollbars=yes,titlebar=no,status=no,width=" + w + ",height=" + h;
    } else {
      build = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes';
    }
    var NewWindow = window.open(URL, WindowName, build);
	NewWindow.focus();
    NewWindow.opener = self;
  }

  	function CheckDomainAvail(fName) {
		document.dw_orderform.DomainChecked.value = 1;
		appDest = "http://preview.i-2.com/:domaincheck?CustomerID=" + document.dw_orderform.elements[fName].value;
		openWin(appDest , 300, 200, "_dw_domain_check");
	}

//calculate cookie expiration - pass it a numbe of days
function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
	}

//thanks to webmonkey for the cookie code foundation
//set the longterm cookie - currently only the referral source
function setLongCookie()
{
	params = getParams();
	if (params["source"]) {
    var the_name = unescape(params["source"]);
    var the_cookie = "dw_session=" + escape("source:" + the_name)+";EXPIRES="+getexpirydate(60);
    document.cookie = the_cookie;
	}
}

//get the longterm cookie - currently only the referral source
function getLongCookie()
{
	if (!document.cookie || document.cookie == '') {
	 // there's no cookie, so go no further
    return 'none';
	} else {
	 // there is a cookie
    var the_cookie = document.cookie;
    var the_cookie = unescape(the_cookie);
    var broken_cookie = the_cookie.split(":");
    var retval = broken_cookie[1];
	return retval;
	}
}

setLongCookie();
