//preload and change imate functions
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
	  document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}

function newWindow(link, width, height, toolbars)
{
   var swidth = screen.width;
   var sheight = screen.height;
   var popup = null;
   var left = (swidth/2) - (width/2);
   var top = (sheight/2) - (height/2);
   var over = "";
   var tlbs = 'no';
   if (toolbars!=null)
   {
		tlbs = toolbars;
   }
   popup = window.open(link,"msg","scrollbars="+tlbs+",resizable=yes,height="+height+",width="+width+",left="+left+",top="+top);
   popup.focus();

}

function listWindow() {
        newWin = window.open('','lWindow','width=520,height=490,scrollbars=no,resizable=no');
        return true;
}

function submitSearch(form){
	var submitUrl = 'http://' + document.domain + '/search/search.php?zoom_query=' + escape(form.elements['zoom_query'].value);
	document.location = submitUrl;
}

// indextools wrapper
function pageView(document_group, action) {
	var YWATracker = YWA.getTracker("1000681782912");
    YWATracker.setAction(action);
    YWATracker.setDocumentGroup(document_group);
	YWATracker.submit();
}

Array.prototype.random = function() {
    return this[Math.floor((Math.random()*this.length))];
}

function screenshots() {
    if (dialogActive) return false;
    dialogActive = true;

	var width = 580;
	var height = 589;
	
	//content div
	var content = '';
	content += '<div id="windowBar" style="cursor: default;"><a href="javascript:;" onclick="windowDestroy();dialogActive=false;return false;">x</a></div>';
	content += '<div style="margin-bottom: 15px;"><iframe id="screenshots_frame" scrolling="no" src="/tour_screenshots.php?' + (new Date().getTime()) + '" style="width: 550px; height: ' + height + 'px; margin: 0 0 0 15px" border="0" frameborder="0" scroll="no"></iframe></div>';
	
    // draw the window in the center
	windowAnimate(false);
    windowDraw(width);
	
	if ( !(/ppc/.test(navigator.userAgent.toLowerCase()) ) && !(/firefox\/1\.0/.test(navigator.userAgent.toLowerCase())) ) {
		$('centerTable').style.background = "#fff url(/i/icons/progress.gif) no-repeat";
		$('centerTable').style.backgroundPosition = parseInt(width/2) + 'px ' + parseInt(height/2) + 'px';
	}

    var windowWidth  = 582;
    var windowHeight = Element.getHeight($(windowGetDivName()));
    var pageWidth = Math.min(document.documentElement.clientWidth, window.innerWidth ? window.innerWidth : Infinity);
    var newLeft = ((pageWidth / 2) - Math.round(windowWidth / 2)).toString();

	$('centerTable').style.top = '10px';
	$('centerTable').style.position = 'absolute';
	$('centerTable').style.zIndex = "998";
	$('centerTable').style.left = (newLeft) + 'px';
	$('centerTable').style.width = (width) + 'px';
	$('centerTable').style.padding = '0';
	$('centerTable').innerHTML = content;
	
	windowAnimate(false);
	var disableUpdateScroll = true;
    windowAppear(disableUpdateScroll);
}

///////////////////////////////////////////// Window Code
var dialogActive;
var div_name = 'centerTable';
//var container_name = 'screenshotWindowContainer';
//var bar_name = 'screenshotWindowBar';

var msg_displayed = false;
var enable_animation = true;

function windowGetDivName() {
    return div_name;
}

function windowAnimate(animation_on) {
    enable_animation = animation_on;
}

function windowDraw(fromTop) {
	var pixelsFromTop = fromTop || 0;

    msg_displayed = false;

    // black out the background
    windowFadeBlack();
    windowSwitchForms(true);

    // draw the window
    var timeWindow = document.createElement('div');

	var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
    var pageWidth = Math.min(document.documentElement.clientWidth, window.innerWidth ? window.innerWidth : Infinity);


    timeWindow.setAttribute('id',windowGetDivName());
	/*
    timeWindow.style.left = '50%';
    timeWindow.style.marginLeft = '-200px';
    timeWindow.style.top = eval("'" + (scrollTop + pixelsFromTop) + "px';");
    timeWindow.style.display = 'none';
	*/
    //timeWindow.style.left = ((pageWidth / 2) - cwith).toString() + 'px';
    timeWindow.style.top = (scrollTop + pixelsFromTop).toString() + 'px';
    timeWindow.style.display = 'none';
    timeWindow.style.zIndex = 1001;


    document.body.appendChild(timeWindow);
}

function windowAppear() {
	// make it do its Blinddown effect,
	if (enable_animation) {
        new Effect.BlindDown(windowGetDivName(), {duration: 0.7});
	} else {
	    $(windowGetDivName()).show();
	}

	if ( arguments.length ) {
		window.onscroll = function () {
			return false;
		}
	} else {
		window.onscroll = windowLocationOnScrollEvent;
	}
}

function windowDestroy() {
	// get rid of events
    window.onscroll = null;
    window.calendar = null;
	if ( arguments.length ) {
		// an argument exists to skip blind up
		if (enable_animation) {
            new Effect.Fade(windowGetDivName());
		} else {
		    $(windowGetDivName()).hide();
		}
	} else {
	    if (enable_animation) {
            new Effect.BlindUp(windowGetDivName(), {duration: 0.5});
	    } else {
		    $(windowGetDivName()).hide();
	    }
	}
    if (enable_animation) {
        new Effect.Fade('windowBackground', {duration: 0.5, afterFinish: function() {
    		windowDestroyComplete();
    	}});
    } else {
        $('windowBackground').hide();
        windowDestroyComplete();
    }

}

function windowDestroyComplete() {
	$('centerTable').style.background = '';
    if ($('windowBackground')) $('windowBackground').parentNode.removeChild($('windowBackground'));
    if ($(windowGetDivName())) $(windowGetDivName()).parentNode.removeChild($(windowGetDivName()));
    windowSwitchForms(false);
}

function windowFadeBlack() {

    var background = document.createElement("table");
    background.setAttribute('id', 'windowBackground');
    background.setAttribute('width', '100%');
    background.setAttribute('height', windowGetScreenHeight() + 40);
    background.style.display = 'none';
    var backgroundTr = background.insertRow(-1);
    var backgroundTd = backgroundTr.insertCell(-1);
    document.body.insertBefore(background, document.body.firstChild);

    if (enable_animation) {
        new Effect.Appear('windowBackground', {to: 0.4});
    } else {
		$('windowBackground').setStyle({opacity: 0.4});
        $('windowBackground').show();
    }
}

function windowSwitchForms(in_disable) {
	// only do this for IE6 ...
	if ( (/msie 5\.5/gi.test(navigator.userAgent) || /msie 6\.0/gi.test(navigator.userAgent)) && !/opera/gi.test(navigator.userAgent) ) {
		for (var i = 0; i < document.forms.length; i++) {
			if (document.forms[i].name == 'ajaxWindow') continue;
			for (var j = 0; j < document.forms[i].elements.length; j++) {
				document.forms[i].elements[j].style.visibility = in_disable ? 'hidden' : 'visible';
			}
		}
	}
}

function windowGetScreenHeight() {
    var height = 0;
    var heightPropertiesArray = new Array(document.body.clientHeight,document.documentElement.clientHeight,window.innerHeight);
    for (var i = 0; i < heightPropertiesArray.length; i++) {
        if (heightPropertiesArray[i] != undefined && heightPropertiesArray[i] > height) height = heightPropertiesArray[i];
    }
    return height;
}

function windowGetInnerHeight() {
    var height = 0;
    var heightPropertiesArray = new Array(document.documentElement.clientHeight,window.innerHeight);
    for (var i = 0; i < heightPropertiesArray.length; i++) {
        if (heightPropertiesArray[i] != undefined && heightPropertiesArray[i] > height) height = heightPropertiesArray[i];
    }
    return height;
}

function windowDisplayMsg(in_msg) {
    $('windowMsg').innerHTML = in_msg;
    $('windowMsg').style.display = 'block';
    $('windowMsgError').style.display = 'none';
    if (!msg_displayed) {
        new Effect.BlindDown('windowMsgContainer', {duration: 0.7});
    }
    msg_displayed = true;
}
function windowDisplayErrorMsg(in_msg) {
    $('windowMsgError').style.display = 'block';
    $('windowMsgError').innerHTML = in_msg;
    if (!msg_displayed) {
        new Effect.BlindDown('windowMsgContainer', {duration: 0.7});
    }
    msg_displayed = true;
}

function windowClearMsg() {
    if (msg_displayed) {
        new Effect.BlindUp('windowMsgContainer', {duration: 0.7, afterFinish: windowClearComplete});
    } else {
        windowClearComplete();
    }
    msg_displayed = false;
}
function windowClearComplete() {
    $('windowMsg').innerHTML = '';
    $('windowMsg').style.display = 'none';
    $('windowMsgError').innerHTML = '';
    $('windowMsgError').style.display = 'none';
}

function windowLocationOnScrollEvent() {
    var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);

    $(windowGetDivName()).style.top = eval("'" + (scrollTop + 100) + "px';");
}

function windowGetMsgArea() {
    return '<div id="windowMsgContainer" style="display: none;"><div id="windowMsg"></div><div id="windowMsgError"></div><div class="pinstripe">&nbsp;</div></div>';
}


var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(element) {		
		var options = Object.extend({
			top: 24,
			left: 24,
			icon: '/i/icons/tooltip.gif',
			iconOver: '/i/icons/tooltip_on.gif',
			labelStyle: {color: 'blue'},
			labelStyleHover: {color: 'red'},
			zIndex: 999
		}, arguments[1] || {});
		
		this.mask			= null; 
		this.timer			= null; 
		this.options		= options;
		this.element		= $(element);
		this.comment		= this.options.comment;
		this.options.useIcon = this.element.className.indexOf('icon') != -1;
		var dimensions 		= Element.getDimensions(this.comment);
		this.dimSize		= [dimensions.width, dimensions.height];
		this.eventMouseOver = this.show.bindAsEventListener(this);
		this.eventMouseOut  = this.hide.bindAsEventListener(this);
		this.registerEvents();
		this.draw();
	},
	
	draw: function(){ // prepare the trigger
		
		Element.makePositioned(this.comment);
		Element.hide(this.comment);
		Element.setStyle(this.comment, {position: "absolute",MozBorderRadius: "8px 8px 8px 8px"});
		this.removeAlt(this.element);
		this.removeAlt(this.element.getElementsByTagName('IMG')[0]);
		this.cloak();
	},

	removeAlt: function(element) {
		try {element.removeAttribute('alt');}catch (e) {}
		try {element.removeAttribute('title');}catch (e) {}
	},
	
	show: function(event) { // show the tooltip
		var pointer	= [Event.pointerX(event), Event.pointerY(event)];
		var options = this.options;
		var dimSize	= this.dimSize;
		var winSize	= this.getWindowSize();
		Position.prepare();
		pointer[0] += options.left;
		pointer[1] += options.top;
		
		// messy: do not take window scroll dimensions into account when the add time window is active.
		if ( this.comment.id == 'ttAddTime' ) {
			if (!event) var event = window.event;
			if (event.pageY) 	{
				pointer[0] -= event.pageX;
				pointer[1] -= event.pageY;
			} else if (event.clientY) 	{
				pointer[0] -= event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				pointer[1] -= event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
			pointer[0] += 190;
			pointer[1] += 70;
		}

		//side scroll
		if ( winSize[0] < (pointer[0] + options.left + dimSize[0] - Position.deltaX) ) {
			pointer[0] -= Math.abs(winSize[0] - (pointer[0] + options.left + dimSize[0]));
		}
		//top scroll
		if ( winSize[1] < (pointer[1] + options.top + dimSize[1]) - Position.deltaY) {
			pointer[1] -= dimSize[1] + options.top + 20;
		}
		//finalize
		pointer[0] = (pointer[0] > 0 ? pointer[0] : Event.pointerX(event) + options.left);
		pointer[1] = (pointer[1] > 0 ? pointer[1] : Event.pointerY(event) + options.top);

		//position
		Element.setStyle(this.comment, {left: pointer[0] + 'px',top: pointer[1] + 'px',zIndex: options.zIndex});
		if ( this.mask != null ) {
			Element.setStyle(this.mask, {left: pointer[0] + 'px',top: pointer[1] + 'px', zIndex: (options.zIndex - 1)})
		}
		
		//appear
		this.comment.style.display = 'block';
		if ( options.useIcon ) {
			var i = this.element.getElementsByTagName('IMG')[0];
			if (i != null) {
				i.src = options.iconOver;
			}
		} else {
			Element.setStyle(this.element, this.options.labelStyleHover);
		}
		if ( this.mask != null ) {	
			this.mask.style.display = 'block';	
		}
	},
	
	hide: function(event) {
		Element.hide(this.comment);
		if ( this.mask != null ) {
			Element.hide(this.mask);		
		}
		if ( this.options.useIcon ) {
			var i = this.element.getElementsByTagName('IMG')[0];
			if ( i != null ) {
				i.src = this.options.icon;
			}
		} else {
			Element.setStyle(this.element, this.options.labelStyle);
		}
	},
	
	getWindowSize: function(w) {
        w = w ? w : window;
        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        return [width, height];
	},
	
	cloak: function(){
		var ua = navigator.userAgent; // WCH: aplus.co.yu
		if ( (/msie 5\.5/gi.test(ua) || /msie 6\.0/gi.test(ua)) && !/opera/gi.test(ua) ) {
			var style = "position:absolute;left:0;top:0;display:none;width:0;height:0;filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0)";
			var id = this.comment.id + "-mask";
			document.getElementsByTagName('body')[0].insertAdjacentHTML('afterBegin', '<iframe id="' + id + '" scroll="no" frameborder="0" src="javascript:false;" style="'+style+'"></iframe>');
			this.mask = $(id);
			Element.setStyle(this.mask,{width: (this.dimSize[0]+2) + 'px',height: this.dimSize[1] + 'px'});
			Element.makePositioned(this.mask);
		}	
	},
	
	registerEvents: function() {
		Event.observe(this.element, "mouseover", this.eventMouseOver);
		Event.observe(this.element, "mouseout", this.eventMouseOut);
	} 
}

function tooltipPrepare(){
	$$(".tooltip").each( function(element) { 
		var relation = element.getAttribute('rel') || element.attributes['rel'].value;
		if ( $(relation) != null ) {
			new Tooltip(element, {comment: $(relation)});
		}
	});
}

//loop all elements with class name tooltip and assign
Event.observe(window, "load", tooltipPrepare);


//+--------------------------------------------------------------------------+
//| xtabs                                                                    |
//| ×›opyleft [jprado@layer51.com]    									     |
//| todo: remove redundant code					                             |
//| todo: add customizability					                             |
//+--------------------------------------------------------------------------+

function xTabs() {

	if ( !document.getElementById || !document.getElementsByTagName ) {
		return;
	}
	var tables = document.getElementsByClassName('xtabs');
	for (var i=0;i<tables.length;i++ ) {
		var tBody = tables[i].getElementsByTagName("TBODY")[0];
		var y=0;
		for (var j=0;j< tBody.childNodes.length;j++ ) {
			var row = tBody.childNodes[j];
			var x,y;
			x = 0;
			if( row.nodeName.toLowerCase() == 'tr' && row.className.indexOf('nohover') == -1) {
				row.onmouseover = xtOver;
				row.onmouseout = xtOut;
				for (var k=0;k<row.childNodes.length;k++ ) {
					if( row.childNodes[k].nodeName.toLowerCase() == 'td' ) {
						var cell = row.childNodes[k];
						cell.x = x;
						cell.y = y;
						cell.onmouseover = xtVertOver;
						cell.onmouseout = xtVertOut;
						x++;
					}
				}
				y++;
			}
		}
	}
}

function xtOver() {
	//this.style.backgroundColor = '#E0E0C9';
	//this.style.backgroundColor = (this.className == 'odd' ? '#DEDECC' : '#D0D0BE');
	//this.style.backgroundColor = (this.className == 'odd' ? '#D1EEB0' : '#B9D999');
	//this.style.backgroundColor = (this.className == 'odd' ? '#D4DCEC' : '#BBC8E0');
	this.style.backgroundColor = (this.className == 'odd' ? '#FFFFCC' : '#EEEEAA');
}

function xtOut() {
	this.style.backgroundColor = '';
}

function xtVertOver(){
	var tBody = this.parentNode.parentNode;
	
	var rowIndex = 0;
	for (var i=0;i<tBody.childNodes.length;i++) {
		var row = tBody.childNodes[i];
		if( row.nodeName.toLowerCase() == 'tr' && row.className.indexOf('nohover') == -1 ) {
			var columnIndex = 0;
			for (var j=0;j<row.childNodes.length;j++ ) {
				if( row.childNodes[j].nodeName.toLowerCase() == 'td' ) {
					var cell = row.childNodes[j];
					if( columnIndex == this.x && rowIndex != this.y ) {
						cell.style.backgroundColor = (rowIndex % 2 == 0 ? '#EEEEAA' : '#FFFFCC');
					}
					columnIndex++;
				}
			}
			rowIndex++;
		}
	}
}

function xtVertOut(){
	var tBody = this.parentNode.parentNode;
	var rowIndex = 0;
	for (var i=0;i<tBody.childNodes.length;i++) {
		var row = tBody.childNodes[i];
		if( row.nodeName.toLowerCase() == 'tr' && row.className.indexOf('nohover') == -1) {
			var columnIndex = 0;
			for (var j=0;j<row.childNodes.length;j++ ) {
				if( row.childNodes[j].nodeName.toLowerCase() == 'td' ) {
					var cell = row.childNodes[j];
					if( columnIndex == this.x ) {
						cell.style.backgroundColor = '';
						cell.style.color = '';
					}
					columnIndex++;
				}
			}
			rowIndex++;
		}
	}
}

Event.observe(window, 'load', xTabs, false);




//function to submit the final process
var oForm;
var bRequestSubmitted = false;
var intervalTimer;

function disableButton(btn,form) {
	if (!bRequestSubmitted){
		var submitMessage = "  PLEASE WAIT...  ";
		btn.value = submitMessage;
		oForm = form;
		//oForm.action = ""
		btn.disabled = true;
		bRequestSubmitted = true;
		setTimeout("submitForm()", 250);
	} else {
		return false;
	}
}

//submit the form
function submitForm() {
	oForm.submit();
	return false;
}

var stateIndex = 0;
function countrySelector(o) {
	country = o.options[o.selectedIndex].value;
	var stateDrop = document.getElementById('billingState');
	if ( stateDrop.selectedIndex > 0 ) {
		stateIndex = stateDrop.selectedIndex;
	}
	if ( country == 'USA' || country == 'Canada' ) {
		stateDrop.selectedIndex = stateIndex;
		stateDrop.disabled = false;
	} else {
		stateDrop.selectedIndex = 0;
		stateDrop.disabled = true;
	}
	populateStates();
}

function suggestDomain(val) {
   $('domain_automatic').style.display = (val.length) ? 'block' : 'none';
   $('domain_automatic_help').style.display = (val.length) ? 'block' : 'none';
   $('domain_automatic_start').style.display = (val.length) ? 'none' : 'block';
   var new_subdomain = val.toLowerCase().replace(/^(\-|\W)+|\W+/g,"").substring(0,25);
   if (val.length && new_subdomain != g_subdomain) {
       // build the list of options
       g_subdomain = new_subdomain;
       g_selected = '';
       if (intervalTimer) {
           // destroy the current one, reset it
           clearInterval(intervalTimer);
           intervalTimer = null;
       }
       intervalTimer = setInterval(buildList,750);
       $('f_automatic').value = '1';
   }
}
function buildList() {
   var tmp_currentTime = new Date();
   var tmp_timestamp = tmp_currentTime.getTime();
   if (tmp_timestamp < timestamp + 750) {
       return true;
   } else {
       clearInterval(intervalTimer);
       intervalTimer = null;
   }
   if (!g_subdomain.length) return;
   document.body.style.cursor = 'wait';
   g_curr = {};
   // clear out the list
   if ($('domain_automatic').hasChildNodes()) while ($('domain_automatic').childNodes.length) $('domain_automatic').removeChild($('domain_automatic').firstChild);
   var uri = '/xml/suggest_domains.php';
   $H(g_arr).each(function(item) {
		var jx = new Ajax.Request(
		uri,
		{
			method: 'get',
			parameters: 'f_subdomain=' + encodeURIComponent(g_subdomain) + '&f_domain=' + encodeURIComponent(item.key),
			onSuccess: function(response) { 
                var xmlObj = response.responseXML;
                buildOption(g_subdomain, item.key, parseInt(xmlObj.getElementsByTagName('item')[0].firstChild.nodeValue));},
			onFailure: Prototype.emptyFunction
		});
   });
   document.body.style.cursor = 'default';
}

function buildOption(subdomain, val, dsbld) {
   var g_curr_idx = subdomain + val.toString();
   g_curr[g_curr_idx] = {'subdomain': subdomain, 'domain': val};

   var slctd = false;
   if (g_selected.length) {
       slctd = (g_selected == g_curr_idx);
   } else if (!dsbld) {
       slctd = true;
       g_selected = g_curr_idx;
   }

   // if subdomain and val aren't available, try to get a different one
   if (dsbld) {
       // try to get a new subdomain by appending a number
       var re_sub = /(.*)(\d+)$/;
       var tmp_subdomain = '';
       if (subdomain.match(re_sub)) {
           var matches = re_sub.exec(subdomain);
           tmp_subdomain = matches[1] + (parseInt(matches[2]) + 1).toString();
       } else {
           tmp_subdomain = subdomain + (1).toString();
       }
       var uri = '/xml/suggest_domains.php';
		var jx = new Ajax.Request(
		uri,
		{
			method: 'get',
			parameters: 'f_subdomain=' + encodeURIComponent(tmp_subdomain) + '&f_domain=' + encodeURIComponent(val),
			onSuccess: function(response) {
                var xmlObj = response.responseXML;
                buildOption(tmp_subdomain, val, parseInt(xmlObj.getElementsByTagName('item')[0].firstChild.nodeValue));},
			onFailure: Prototype.emptyFunction
		});
   } else {
       // if not selected and not disabled
       var elem = document.createElement('li');
       if (!dsbld && !slctd) elem.onclick = function() {g_selected = g_curr_idx;buildList();};
       elem.style.backgroundColor = slctd ? '#eed' : '#f5f5f5';
       elem.style.backgroundImage = 'url(' + location.protocol + '//' + location.host + '/i/icons/domain_' + (slctd ? 'selected' : (dsbld ? 'not_available' : 'available')) + '.gif)';
       elem.style.cursor = (slctd || dsbld) ? 'default' : 'pointer';
       elem.style.fontWeight = (slctd && !dsbld) ? 'bold' : 'normal';
       elem.style.fontStyle = !dsbld ? 'normal' : 'italic';
       elem.style.color = slctd ? '#000' : '#999';
       elem.style.textDecoration = dsbld ? 'line-through' : 'none';
       elem.appendChild(document.createTextNode(g_http + '://' + subdomain + '.' + g_arr[val]));

       // if it's selected, insert it at the top, if not, the bottom
       if (slctd && $('domain_automatic').childNodes.length) {
           $('domain_automatic').insertBefore(elem,$('domain_automatic').firstChild);
       } else {
	       $('domain_automatic').appendChild(elem);
       }
       if (slctd) assignDomain(g_curr_idx);
   }
}
function assignDomain(idx) {
   $('f_account_subdomain').value = g_curr[idx]['subdomain'];
   $('f_account_domain').value = g_curr[idx]['domain'];
}
function useManualDomain() {
   $('domain_automatic_container').hide();
   $('domain_automatic_help').hide();
   $('domain_manual').show();
   $('f_automatic').value = '0';
   $('firm_domain').onkeyup = null;
   $('firm_domain').onblur = null;
   $('f_account_subdomain').focus();
   checkDomain();
}

function checkDomain() {
	var txt = document.getElementById('f_account_subdomain');
	var lst = document.getElementById('f_account_domain');
	var s = txt.value;
	var d = lst.value || lst.options[lst.selectedIndex].value;
	if( s != '' && d > 0 ) {
       var uri = '/xml/validate_domain.php';
		var jx = new Ajax.Request(
		uri,
		{
			method: 'get',
			parameters: 'f_subdomain=' + encodeURIComponent(s) + '&f_domain=' + encodeURIComponent(d),
			onSuccess: function(response) {
                var xmlObj = response.responseXML;
                $('domainChecked').innerHTML = xmlObj.getElementsByTagName('item')[0].firstChild.nodeValue;},
			onFailure: Prototype.emptyFunction
		});
	}
}

function cvv_win() {
	var thewin = window.open("/cvv.php","cvv","height=400,width=500,toolbar=no,statusbar=no,scrollbars=yes");
	thewin.focus();
}

//pops up an image
function TC(url){
	var windowWidth = 600;
	var windowHeight = 500;
   	var left = Math.floor( (screen.width - windowWidth) / 2);
    var top = Math.floor( (screen.height - windowHeight) / 2);
	newWindow = window.open(url,"pop","width="+windowWidth+",height="+windowHeight+",left="+left+",top="+top+",scrollbars=yes,status=yes");
	newWindow.focus();
}

document.observe('dom:loaded', function() { 
    var viewport = document.viewport.getDimensions();
    if(!viewport.width) {
        $$('.screenshot-image').each(function(el) {
            el.setStyle({cursor: 'default'});
            el.removeAttribute('onclick');
            el.removeAttribute('href');
            if(el.down('span')) el.down('span').remove();
            if(el.down('label')) el.down('label').remove();
        });
    }
});

function imageWindow(src) {
    
    var w = 800, h = 618, view = document.viewport.getDimensions();
    
    if(!view.width) { 
        return;
    }

    // for smaller monitors width is always 95% of viewport height (based on 800x618) 
    if (view.width - w < 10) {
        w = parseInt(view.width * .90);
        h = parseInt(618*w/800); 
    }
    
    if (view.height - h < 10) {
        h = parseInt(view.height * .90);
        w = parseInt(800*h/618);  
    }
     
    $(document.body).insert({top: new Element('div', {id: 'overlay'}).setStyle({
        display: 'none',
        position: 'fixed',
        background: '#fff',
        border: '1px solid #6688CC',
        marginLeft: '-'+ parseInt(w/2) +'px', 
        left: '50%',
        top: (view.height / 2 - h / 2) + 'px',
        zIndex: 1000
    }).update(
        '<div style="width: '+w+'px; height: '+h+'px; background: url('+siteCfg.cdn+'/i/icons/indicator.gif) no-repeat 50% 50%">'
            + '<div style="position: absolute; right: 0; margin-right: -23px; margin-top: -2px;">'
                + '<a id="close-overlay" style="display: inline-block; cursor:pointer"><img src="/i/icons/close.gif" /></a>'
            + '</div>'
            + '<img id="overlay-img" src="'+ src +'" onload="$(this).show()" style="display:none; width: '+w+'px; height: '+h+'px"  />'
        + '</div>'
    )});

    $(document.body).insert({top: new Element('div', {
        id: 'bg-overlay', 
        display: 'none'
    }).setStyle({
        opacity: 0.4,
        position: 'fixed',
        background: '#000000',
        width: '100%', height: '100%',
        zIndex: 999
    })});
    
    // appear
    new Effect.Appear('bg-overlay', {to: 0.4});
    new Effect.Appear('overlay', {duration: 0.2});
    
    // events
    var close = function() { $$('#overlay,#bg-overlay').invoke('remove'); }
    $$('#close-overlay,#bg-overlay,#overlay-img').each(function(el){
        el.observe('click', close);
    });
    
    return false;
}

function videoWindow(identifier, flv, w, h, youtube) {
    
    var ua = navigator.userAgent;
    if(/(iPad|iPhone|iPod)/i.test(ua) || (/Android/.test(ua) && /Mobile/.test(ua)) && youtube) {
        location = youtube;
        return;
    }
    
    var view = document.viewport.getDimensions();

    // video width is always 93% of viewport height;
    // for smaller monitors width is always 90% of viewport height or width (based on 1224x712) used to be 1264x712, but height of scrubber is taken into account
    
    var ogw = w, ogh = h;
    if (view.width - w < 100) {
        w = parseInt(view.width * .90);
        h = parseInt(ogh*w/ogw); 
    } 
    
    if (view.height - h < 100) {
        h = parseInt(view.height * .90);
        w = parseInt(ogw*h/ogh); 
    }

    $(document.body).insert({top: new Element('div', {id: 'video-content'}).setStyle({
        display: 'none',
        position: 'fixed',
        background: '#fff',
        marginLeft: '-'+ parseInt(w/2) +'px', 
        left: '50%',
        top: (view.height / 2 - h / 2) + 'px'
        ,border: '1px solid #000'
        ,zIndex: 1000
    }).update(
        '<div style="width: '+w+'px; height: '+h+'px; background: url(/i/icons/indicator.gif) no-repeat 50% 50%">'
            + '<div style="position: absolute; right: 0; margin-right: -23px; margin-top: -1px;">'
                + '<a id="video-close" style="display: inline-block; cursor:pointer"><img src="/i/icons/close.gif" /></a>'
            + '</div>'
            + videoHTML(identifier, flv, w, h)
        + '</div>'
    )});

    $(document.body).insert({top: new Element('div', {
        id: 'video-mask', 
        display: 'none'
    }).setStyle({
        opacity: 0.4,
        position: 'fixed',
        background: '#000000',
        width: '100%', height: '100%',
        zIndex: 999
    })});
    
    // appear
    $('video-mask').setStyle({opacity: .7});
    $$('#video-mask,#video-content').invoke('show');
    
    // close event
    $('video-close').observe('click', function() { 
        $$('#video-content,#video-mask').invoke('remove'); 
    });
    
    window.onresize = function() {
        if(!$('video-content')) {
            window.onresize = null;
            return;
        }
        var view = document.viewport.getDimensions();
        $('video-content').setStyle({top: (view.height / 2 - h / 2) + 'px'});    
    }
    
    return false;
}

function videoHTML(identifier, flv, w, h) {
	var swf = new SWFObject("/flash/player.swf","v"+identifier,w,h,"9",'#000000');
	swf.addParam("menu", "false");
	swf.addParam("quality", "high");
	swf.addParam('allowFullScreen','true');
    swf.addVariable("autostart", "true");
	swf.addVariable("file", flv.split('?')[0]);
//	swf.addVariable("image", flv.split('?')[0] + '.png');
	swf.addVariable("bufferlength", "30");
	swf.addVariable("controlbar", 'bottom');
	swf.addVariable("stretching", 'fill');
	swf.addVariable("skin", '/flash/bekle.zip')
    return swf.getSWFHTML();
}


//+--------------------------------------------------------------------------+
//| forgont login utility 						                             |
//+--------------------------------------------------------------------------+
function loginWindow() {
    var body = '<div style="padding:20px;">'
            + '<h1 style="color: #444433;font-size: 16px;font-weight: bold;line-height: 125%;font-family:Verdana">Find your Intervals account</h1>'
            + '<div class="pinstripe">&nbsp;</div>'
            + '<div id="msgContainer" style="display: none;">'
            + '    <div></div>'
            + '    <div class="pinstripe" style="clear: left;">&nbsp;</div>'
            + '</div>'
            + '<div id="nbox-form" style="padding: 10px 0 0 0 ">'
            + '    <p style="color:#000;margin-top:0">The first step is to look up your Intervals account domain name. Enter your email address and username to retrieve it and proceed to the login page.</p>'
            + '    <table class="fields stretch" border="0" cellpadding="0" cellspacing="1" style="margin-top:0;padding-top:0;margin-bottom:10px">'
            + '        <colgroup span="2"><col width="25%"><col width="75%"></colgroup>'
            + '        <tr>'
            + '            <td style="color:#000000">Username</td>'
            + '            <td><input type="TEXT" id="lf-username" tabindex="1"></td>'
            + '        </tr>'
            + '        <tr>'
            + '            <td style="color:#000000">Email</td>'
            + '            <td><input type="TEXT" id="lf-email" tabindex="2"></td>'
            + '        </tr>'
            + '    </table>'
            + '    <div class="pinstripe">&nbsp;</div>'
            + '    <div style="margin-top: 4px;">'
            + '      <input type="BUTTON" style="float; left;font:11px/1.5em Lucida Grande,Verdana" value="Retrieve" id="lf-button" class="submit" tabindex="3">'
            + '      <input type="BUTTON" style="float: right;font:11px/1.5em Lucida Grande,Verdana" value="Cancel" id="lf-cancel" class="submit" tabindex="4">'
            + '    </div>'
            + '</div>'
            + '<div id="nbox-results" style="display: none;padding-top:10px;"></div>'
        + '</div>';
        
    // overlay
    $(document.body).insert({top: new Element('div', {
        id: 'window-mask', 
        display: 'none'
    }).setStyle({
        opacity: 0.4,
        position: 'fixed',
        background: '#000000',
        width: '100%', height: '100%',
        zIndex: 999
    })});

    var w = 400, h = 300, view = document.viewport.getDimensions();

    // window html
    $(document.body).insert({top: new Element('div', {id: 'window-content'}).setStyle({
        display: 'none',
        position: 'fixed',
        background: '#fff',
        marginLeft: '-'+ parseInt(w/2) +'px', 
        left: '50%',
        top: '100px'
        ,border: '1px solid #6688CC'
        ,zIndex: 1000
    }).update(
        '<div style="width: '+w+'px;">' + body + '</div>'
    )});
    
    $('lf-button').observe('click',function(){
        $('lf-button').disabled = true;
        
        var email = $('lf-email').value;
        var username = $('lf-username').value;
        var error = [];
        
        if(username.length == 0) {
            error.push('User name is required');
        }
        if(email.length == 0) {
            error.push('Email is required');
        }
        if(error.length) {
            $('msgContainer').down('div').update('<div style="color:#A11;padding:10px 0">'+error.join('<br />')+'</div>')
            new Effect.BlindDown($('msgContainer'), {duration: .7});
            $('lf-button').disabled = false;
            return;
        }
        
        if($('msgContainer').visible())
            new Effect.BlindUp($('msgContainer'), {duration: .7});

        new Effect.BlindUp($('nbox-form'), {afterFinish: function(){
            var uri = '/xml/domains.php';
            var jx = new Ajax.Request(
            uri,
            {
                method: 'get',
                parameters: 'email=' + email + '&username=' + username,
                onSuccess: function(response) {

                    var xmlObj = response.responseXML;
                    var tags = xmlObj.getElementsByTagName('item');

                    // clear the results
                    var html = '<h2 style="color: #444433;font-size: 14px;font-weight: bold;line-height: 125%;font-family:Verdana">Results</h2>';

                    if ( tags.length == 0 ) {
                        html += '<p style="color:#000">No accounts were found using your criteria. Click back and try again.</p>';
                    } else {
                        html += '<p style="color:#000">We were able to find your Intervals account:</p><ul>';

                        for (var i=0;i<tags.length;i++) {
                            var item = tags[i];
                            html += '<li><a href="http://' + item.getElementsByTagName('domain')[0].firstChild.nodeValue + '">' + item.getElementsByTagName('domain')[0].firstChild.nodeValue + '</a></li>';
                        }

                        html += '</ul><p style="color:#000">After clicking on the link please be sure to bookmark the page for speedier logins.</p>';
                    }

                    $('nbox-results').update(html);

                    // search again object
                    var inputButton = document.createElement('INPUT');
                    inputButton.style.marginTop = '10px';
                    inputButton.type = 'BUTTON';
                    inputButton.value = 'Back';
                    inputButton.id = 'lf-again';
                    inputButton.onclick = function() { 
                        new Effect.BlindUp('nbox-results', {duration: .7, afterFinish:
                                function() { 
                                    new Effect.BlindDown('nbox-form', {duration: .7, afterFinish: function() {isToggling = false;}});
                                }});
                    };
                    inputButton.className = 'submit';
                    $('nbox-results').appendChild(inputButton);

                    new Effect.BlindDown($('nbox-results'), {duration: .7});   

                    $('lf-button').disabled = false;
                },
                onFailure: function(response) {
                    var xmlObj = response.responseXML;
                    alert('A request error occurred.');
                }
            });
        }});
    });
    
    // appear
    $$('#window-content').invoke('show');
    
    // close event
    $('lf-cancel').observe('click', function() { 
        $$('#window-content,#window-mask').invoke('remove'); 
    });    
}

