var base_url = 'http://www.georgestreetalehouse.com/';
function clearForm(formIdent) 
{ 
  	var form, elements, i, elm; 
  	form = document.getElementById ? document.getElementById(formIdent) : document.forms[formIdent]; 
	if (document.getElementsByTagName)
	{
		elements = form.getElementsByTagName('input');
		for( i=0, elm; elm=elements.item(i++); )
		{
			if (elm.getAttribute('type') == "text")
			{
				elm.value = '';
			}
		}
	}

	// Actually looking through more elements here
	// but the result is the same.
	else
	{
		elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.type == "text")
			{
				elm.value ='';
			}
		}
	}
}

function captcha(){
	ajax.update('./handlers/register.php?action=captcha', 'captcha_div');
}

function Msg(message){
	document.getElementById('err_message').innerHTML=message;
  	document.getElementById("err_message_container").style.display = "block";
	var pattern=/SUCCESS!!/i;
	if(pattern.test(message)){
		scroll(0,0);
	}	
}

function submitTestimonial(form){
	ajax.post('./handlers/testimonial.php',testimonialResponse,ajax.serialize(form));
}

function loginResponse(response){
	var pattern=/ERROR/i;
	if(pattern.test(response)){
		Msg('<font color="red"><b>' + response + '</b></font>');
	}else{
		window.location = response;
	}
}

function transBody(){
	document.getElementById('main_body').style.filter='alpha(opacity=30)'; 
	document.getElementById('main_body').style.mozOpacity='0.3'; 
	document.getElementById('main_body').style.opacity='0.3';
	document.getElementById('main_body').style.khtmlOpacity='.3'; 

}

function passRecoverForm(rtype){
	document.getElementById('pass_recovery_div').style.display='block';
	document.getElementById('login_div').style.display='none';
	transBody();
	scroll(0,0);
		// Open PHP script for requests
   		httpu2.open('get', base_url + 'handlers/pass_recovery.php?rtype=' + rtype, false);
		httpu2.send(null);
		if(httpu2.status == 200){
			// Text returned FROM the PHP script
      		var response = httpu2.responseText;
			if(response) {
				document.getElementById("pass_recovery_div").innerHTML = response;
      		}
		}
}

function recoverPass(rtype,form){
	transBody();
	document.getElementById('pass_recovery_div').style.display='block';
	scroll(0,0);
	// Open PHP script for requests
   	httpu2.open('POST', base_url + 'handlers/pass_recovery.php', false);
    httpu2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     httpu2.send('remail=' + form.remail.value + '&rtype=' + rtype);
		if(httpu2.status == 200){
			// Text returned FROM the PHP script
      		var response = httpu2.responseText;
			if(response) {
				document.getElementById("pass_recovery_div").innerHTML = response;
      		}
		}
}

function editWindow(url, width, height){
var str="";
 str += "height=" + height;
  str += ",innerHeight=" + height;
  str += ",width=" + width;
  str += ",innerWidth=" + width;
 str += ",menubar=1";
  str += ",resizable=1";
  str += ",scrollbars=1";

 window.open (url,"editwindow",str);
}

function preloadGlobal(){
	imgCheck=new Image(); 
	imgCheck.src=img_url + "images/check.gif";
	imgBang=new Image(); 
	imgBang.src=img_url + "images/bang2.gif";				
			
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getElementHeight(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	} else if (document.layers) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	}
	if ((navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1)) { 
		xPos = elem.style.pixelHeight;
	} else {
		xPos = elem.offsetHeight;
	}
	return xPos;
}

function setElementHeight(Elem, Elem2) {
	var elemHeight = getElementHeight(Elem);
	var newHeight = elemHeight/1.3;
		if(document.getElementById) {
			document.getElementById(Elem2).style.height=newHeight;
		} else if (document.all){
			document.all[Elem2].style.height=newHeight;
		} else if (document.layers) {
			document.layers[Elem2].style.height=newHeight;
		} else {
			Elem2.style.height= newHeight;
		} 
}

function PopupPic(sPicURL) {
	window.open( "http://www.shoptangerineboutique.com/store/popup.htm?"+sPicURL, "",  
	"resizable=1,HEIGHT=200,WIDTH=200");
} 

$('#facebox').livequery(function() {
	//seat form...more forms can be added after this
	$(this).find('#facebox_seat_form').livequery(function() {
      	$(this).ajaxForm({
			target: '#saved_div',
			beforeSubmit: setAdminSeatColor,
        	success: function(html) {
      			$.facebox.close();
        	}
		});
    });
	//another form starts after here
});

function setAdminSeatColor(formData, jqForm, options) {  
    var form = jqForm[0]; 
    if (form.seat_price.value > 0.00) { 
		$("#seat_image" + form.seat_id.value).attr("src", base_url + "images/Priced/" + form.seat_id.value + ".jpg");
		$("#seat_href" + form.seat_id.value).attr("title", "Seat " + form.seat_id.value + "|" + (form.seat_price.value > 0.00 ? 'The seat has a price of $' + form.seat_price.value  + '|' : '') + "Click The Seat To Edit").cluetip({
  			cluetipClass: 'jtip', 
  			hoverClass: 'highlight',
  			dropShadow: false, 
  			splitTitle: '|', 
		});
    }  
}

//jquery slide menu stuff

/*********************
//* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/

//Update: April 12th, 10: Fixed compat issue with jquery 1.4x

//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'down.gif', 23], right:['rightarrowclass', 'right.gif']}

var jqueryslidemenu={

animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
			$curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myslidemenu" on page:
jqueryslidemenu.buildmenu("myslidemenu", arrowimages)
