

////////////////////////////////////////////////////////////////
var browser_name = navigator.appName;
var browser_version = navigator.appVersion;

var locate_version = browser_version.indexOf('MSIE');
var parsed_version = parseInt (browser_version.substring (locate_version + 5, locate_version + 8));

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 1000
ypSlideOutMenu.minCPUResolution = 10

// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
	this.ie  = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0
	this.css = "";

	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id
		this.dir		 = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
		this.dim		 = this.orientation == "h" ? width : height
		this.hideTimer	 = false
		this.aniTimer	 = false
		this.open		 = false
		this.over		 = false
		this.startTime	 = 0

		// global reference to this object
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")

		// add this menu object to an internal list of all menus
		ypSlideOutMenu.Registry[id] = this

		var d = document

		var strCSS = "";
		strCSS += '#' + this.id + 'Container { visibility:hidden; '
		strCSS += 'left:' + left + 'px; '
		strCSS += 'top:' + top + 'px; '
		strCSS += 'overflow:hidden; z-index:10000; }'
		strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
		strCSS += 'width:' + width + 'px; '
		strCSS += 'height:' + height + 'px; '
		strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
		strCSS += '}'

		this.css = strCSS;

		this.load()
	}
}

ypSlideOutMenu.writeCSS = function() {
	document.writeln('<style type="text/css">');

	for (var id in ypSlideOutMenu.Registry) {
		document.writeln(ypSlideOutMenu.Registry[id].css);
	}

	document.writeln('</style>');
}

ypSlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container	= obj1
		this.menu		= obj2
		this.style		= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos		= 0
		this.accelConst	= (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide()
	}
}
	
ypSlideOutMenu.showMenu = function(id)
{
	var reg = ypSlideOutMenu.Registry
	var obj = ypSlideOutMenu.Registry[id]
	
	if (obj.container) {
		obj.over = true

		// close other menus.
		for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
}

ypSlideOutMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
	
}

ypSlideOutMenu.hideAll = function()
{
	var reg = ypSlideOutMenu.Registry
	for (menu in reg) {
		ypSlideOutMenu.hide(menu);
		if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
	}
}

ypSlideOutMenu.hide = function(id)
{
	var obj = ypSlideOutMenu.Registry[id]
	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	
	// flag that this scheduled event has occured.
	obj.hideTimer = 0

	// if this menu is open, close it.
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
		if ((browser_name == "Microsoft Internet Explorer") && (parsed_version < 7))	{
			if ((browser_name == "Microsoft Internet Explorer") && (parsed_version < 7))	{
				var doc = document.getElementsByTagName('select');
				for (var i = 0; i < doc.length; i++){
 					doc[i].style.visibility = "visible";
				}
			}
		}
}

ypSlideOutMenu.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime()	
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-")		d = -d
		else if (this.open && this.dirType == "+")	d = -d
		else if (!this.open && this.dirType == "-")	d = -this.dim + d
		else										d = this.dim + d

		this.moveTo(d)
	}
}

ypSlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}

// events
ypSlideOutMenu.prototype.onactivate		= function() { }
ypSlideOutMenu.prototype.ondeactivate	= function() { }


			//POSITION HORIZONTAL, VERTICAL, WID HEIGHT
			var myMenu1 = new ypSlideOutMenu("menu1", "down", 295, 115, 340, 236);
			var myMenu2 = new ypSlideOutMenu("menu2", "down", 375, 115, 340, 202);
			var myMenu3 = new ypSlideOutMenu("menu3", "down", 465, 115, 340, 236);
			var myMenu4 = new ypSlideOutMenu("menu4", "down", 550, 115, 340, 236);
			var myMenu5 = new ypSlideOutMenu("menu5", "down", 385, 115, 340, 236);
			var myMenu6 = new ypSlideOutMenu("menu6", "down", 475, 115, 340, 236);
			var myMenu7 = new ypSlideOutMenu("menu7", "down", 615, 115, 340, 94);
			ypSlideOutMenu.writeCSS();
////////////////////////////////////////////////////////////////////////////////////////////



function checkReturn ()	{
	if (document.getElementById('return_customer').checked == true)	{
		document.getElementById('returning').style.display = 'none';
	}else{
		document.getElementById('returning').style.display = 'block';
	}
}

//////////////////////////////////////////////

function ValidateSignUpForm () {
	if (document.sign_up_form.project_title.value == '') {
		alert ('Please contact KingWebmaster and note that the project\'s title is missing');
		document.sign_up_form.project_title.focus();
		return false;
	}

//	if (document.sign_up_form.project_desc.value == '') {
//		alert ('Please enter a short description for the project');
//		document.sign_up_form.project_desc.focus();
//		return false;
//	}

	if (document.sign_up_form.project_cost.value == '') {
		alert ('Please contact KingWebmaster and note that the project\'s cost is missing');
		document.sign_up_form.project_cost.focus();
		return false;
	}

	if (document.sign_up_form.recipient.value == '') {
		alert ('Please contact KingWebmaster and note that the project manager\'s name is missing');
		document.sign_up_form.recipient.focus();
		return false;
	}

///////////////////////

	if (document.sign_up_form.full_name.value == '') {
		alert ('Please enter your full name');
		document.sign_up_form.full_name.focus();
		return false;
	}

	if (document.sign_up_form.email_address.value == '') {
		alert ('Please enter your email address');
		document.sign_up_form.email_address.focus();
		return false;
	}

	if ((document.sign_up_form.website_url.value == '') || (document.sign_up_form.website_url.value == 'http://')) {
		alert ('Please enter the website\'s URL this project is in reference to');
		document.sign_up_form.website_url.focus();
		return false;
	}

	if (document.sign_up_form.company_name.value == '') {
		alert ('Please enter your company\'s name as you want it to appear on our invoice');
		document.sign_up_form.company_name.focus();
		return false;
	}
	
	if (document.sign_up_form.phone.value == '') {
		alert ('Please enter the best phone number you can be reached at');
		document.sign_up_form.phone.focus();
		return false;
	}

///////////////////////

	if (document.sign_up_form.return_customer.checked == false) {
		if (document.sign_up_form.address_1.value == '') {
			alert ('Please enter your billing address');
			document.sign_up_form.address_1.focus();
			return false;
		}
	
		if (document.sign_up_form.city.value == '') {
			alert ('Please enter your billing city');
			document.sign_up_form.city.focus();
			return false;
		}
	
		if (document.sign_up_form.state.value == '') {
			alert ('Please enter your billing state');
			document.sign_up_form.state.focus();
			return false;
		}
	
		if (document.sign_up_form.zip_code.value == '') {
			alert ('Please enter your billing zip code');
			document.sign_up_form.zip_code.focus();
			return false;
		}

///////////////////////

		if (document.sign_up_form.payment_type[0].checked == true) {
			if (document.sign_up_form.cc_name.value == '') {
				alert ('Please enter the name of the credit card holder');
				document.sign_up_form.cc_name.focus();
				return false;
			}
		
			if (document.sign_up_form.cc_number.value == '') {
				alert ('Please enter the credit card\'s number');
				document.sign_up_form.cc_number.focus();
				return false;
			}
		
			if (document.sign_up_form.expiration.value == '') {
				alert ('Please enter the credit card\'s expiration date');
				document.sign_up_form.expiration.focus();
				return false;
			}
		
			if (document.sign_up_form.cvv2.value == '') {
				alert ('Please enter the credit card\'s security code');
				document.sign_up_form.cvv2.focus();
				return false;
			}
		}
	}

///////////////////////

	if (document.sign_up_form.contract_agree.checked == false) {
		alert ('Please check the box that you agree to our terms and conditions');
		document.sign_up_form.contract_agree.focus();
		return false;
	}

	return true;
}

//////////////////////////////////////////////

function createCookie (name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime (today.getTime());
	
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date (today.getTime() + (expires));
	document.cookie = name + "=" +escape( value ) + ((expires) ? ";expires=" + expires_date.toGMTString() : "" ) + ((path) ? ";path=" + path : "" ) + ((domain) ? ";domain=" + domain : "" ) + ((secure) ? ";secure" : "" );
}

function readCookie (check_name) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if (cookie_name == check_name) {
			b_cookie_found = true;

			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}

			return cookie_value;
			break;
		}

		a_temp_cookie = null;
		cookie_name = '';
	}

	if (!b_cookie_found) {
		return null;
	}
}

function log_affiliates () {
	var affiliate_code;

	var affiliate_var = "ac=";
    var affiliate_start = window.location.href.indexOf (affiliate_var, 0);
	if (affiliate_start != -1) {
		affiliate_code = window.location.href.substring (affiliate_start + affiliate_var.length, window.location.href.length);

		createCookie ('PM-Affiliate', affiliate_code, 1, '/', 'promomanager.com', '');
	}

	affiliate_code = readCookie ('PM-Affiliate');

	if (affiliate_code) {
		if (document.sign_up_form)
			document.sign_up_form.referred.value = affiliate_code;
	}
}
