﻿/*
 * By Sallar Kaboli (© 2007 - SallarKaboli.com)
 */
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
ajax.serialize=function(f){var g=function(n){return document.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+e.value;else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
ajax.get=function(url,func){ajax.send(url,func,'GET')};
ajax.mySend=function(url){var f=function(r){};ajax.get(url,f)};

function loader(URL, container, msg, indicator){

	var notice = $(container);
		
	new Ajax.Request(URL, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(transport) {
				notice.update(transport.responseText);
				Effect.Appear(notice);
		}
	});
	var myGlobalHandlers = {
		onCreate: function(){
			$(indicator).update(msg);
			Effect.Appear(indicator);
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide(indicator);
			}
			
		}
	};
	
	Ajax.Responders.register(myGlobalHandlers);
	
}

function procceed(URL, container, fade, msg, indicator){

	var notice = $(container);
		
	new Ajax.Request(URL, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(transport) {
				Effect.Fade(fade,{queue:{scope:'newscope', position:'end'}});
				notice.update(transport.responseText);
				Effect.Appear(notice,{queue:{scope:'newscope', position:'end'}});
		}
	});
	var mix = {
		onCreate: function(){
			step_pro();
			$(indicator).update(msg);
			Effect.Appear(indicator);
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide(indicator);
			}
			
		}
	};
	
	Ajax.Responders.register(mix);
	
}


function procceed2(URL, container, msg, indicator){

	var notice = $(container);
		
	new Ajax.Request(URL, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(transport) {
				notice.update(transport.responseText);
				Effect.Appear(notice);
		}
	});
	var mix2 = {
		onCreate: function(){
			$(indicator).update(msg);
			Effect.Appear(indicator);
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide(indicator);
			}
			
		}
	};
	
	Ajax.Responders.register(mix2);
	
}


function striper(parentElementTag, parentElementClass, childElementTag, styleClasses)
{
	var i=0,currentParent,currentChild;
	// capability and sanity check
	if ((document.getElementsByTagName)&&(parentElementTag)&&(childElementTag)&&(styleClasses)) {
		// turn the comma separate list of classes into an array
		var styles = styleClasses.split(',');
		// get an array of all parent tags
		var parentItems = document.getElementsByTagName(parentElementTag);
		// loop through all parent elements
		while (currentParent = parentItems[i++]) {
			// if parentElementClass was null, or if the current parent's class matches the specified class
			if ((parentElementClass == null)||(currentParent.className == parentElementClass)) {
				var j=0,k=0;
				// get all child elements in the current parent element
				var childItems = currentParent.getElementsByTagName(childElementTag);
				// loop through all child elements
				while (currentChild = childItems[j++]) {
					// based on the current element and the number of styles in the array, work out which class to apply
					k = (j+(styles.length-1)) % styles.length;
					// add the class to the child element - if any other classes were already present, they're kept intact
					currentChild.className = currentChild.className+" "+styles[k];
				}
			}
		}
	}
}

function domain_register()
{
	$('domain_year').hide;
	$('domain_reg_desc').hide;
}

function step_pro(){
	$('submit').hide();
}


var dolphintabs={
	subcontainers:[], last_accessed_tab:null,

	revealsubmenu:function(curtabref){
	this.hideallsubs()
	if (this.last_accessed_tab!=null)
		this.last_accessed_tab.className=""
	if (curtabref.getAttribute("rel")) //If there's a sub menu defined for this tab item, show it
	document.getElementById(curtabref.getAttribute("rel")).style.display="block"
	curtabref.className="current"
	this.last_accessed_tab=curtabref
	},

	hideallsubs:function(){
	for (var i=0; i<this.subcontainers.length; i++)
		document.getElementById(this.subcontainers[i]).style.display="none"
	},


	init:function(menuId, selectedIndex){
	var tabItems=document.getElementById(menuId).getElementsByTagName("a")
		for (var i=0; i<tabItems.length; i++){
			if (tabItems[i].getAttribute("rel"))
				this.subcontainers[this.subcontainers.length]=tabItems[i].getAttribute("rel") //store id of submenu div of tab menu item
			if (i==selectedIndex){ //if this tab item should be selected by default
				tabItems[i].className="current"
				this.revealsubmenu(tabItems[i])
			}
		tabItems[i].onmouseover=function(){
		dolphintabs.revealsubmenu(this)
		}
		} //END FOR LOOP
	}

}