var runflag = 0;
var http_request = false;

function ar(url, data, opt_objChoice){
        var opt;
        var xmlhttp  =false;
        var xmlhttp2 = false;
        var _targObject=null;
        var _do=null;
        var noC=0;

        opt  = opt_objChoice;
        type = 'ga';

        if( type =='ga' )
        {
                switch( opt )
                {
                        case 1: _do = 1;
                                document.getElementById(data).innerHTML = "<div align = 'center'><div align='center' style='height: 100px; width: 100px; margin-top: 225px;'><img src='load.gif'></div></div>";
                                _targObject = document.getElementById(data);
                                break;
                        case 2: _do = 1;
                                _targObject = document.getElementById(data);
                                break;
                }
        }

        if(window.XMLHttpRequest)
                xmlhttp2 = new XMLHttpRequest();
        else if(window.ActiveXObject)
                xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
        else alert('Please upgrade your browser.');

        xmlhttp2.open("POST",url,true);
        xmlhttp2.onreadystatechange = function(){

        if( xmlhttp2.readyState == 4 ){
                if(  xmlhttp2.status == 200 ){
                        if( _targObject )
                                _targObject.innerHTML = xmlhttp2.responseText;
                        }       runflag = 0;
                }
        }

        xmlhttp2.send(null);
}

function sfm(holder,e,v){
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

        if (keycode == 13){
                if (v == 1){
                        ar('ajax_login.php?em='+document.getElementById('email').value+'&pw='+document.getElementById('pass').value,'',2);
                        coRedir();
                }
                else{
	                holder.form.submit();
                }	return false;
        }
        else return true;
}

function coRedir(){
	setTimeout("window.location.href='checkout.php?la=1'",1000);
}

function sbox(h,w){
	Shadowbox.open({
		content: 	'<div style="float:left; width:'+(w-50)+'px; height:'+(h-50)+'px; padding-left:50px;"><span style="float:left; width:100%; cursor:pointer;" onclick="Shadowbox.close();"><span style="float:right; padding-right:10px;">x</span></span><form method="POST"><span style="float:left; width:100%; margin-top:40px;"><span style="float:left; width:140px;">Email Address:</span><span style="float:left;"><input type="text" id="email" maxlength="40" size="20"></span></span><span style="float:left; width:100%; margin-top:10px;"><span style="float:left; width:140px;">Password:</span><span style="float:left;"><input onkeypress="return sfm(this,event,1);" type="password" id="pass" maxlength="40" size="20"></span></span><span style="float:left; width:100%; margin-top:10px;"><span style="float:left; width:230px;">&nbsp;</span><span style="float:left;"><a href="javascript:void(0);" onclick="ar(\'ajax_login.php?em=\'+document.getElementById(\'email\').value+\'&pw=\'+document.getElementById(\'pass\').value,\'\',2); coRedir();">Login</a></span></span></form></div>',
		player:		"html",
		title:		"",
		height:		h+20,
		width:		w
	});
}

function sto(){
        var str = document.getElementById('str');
        if( str.value > 0 && str.value < 5 ){
                setTimeout("sto()",10000);
                document.getElementById('str').value=0;
        }
        else{
                document.getElementById('sl'+document.getElementById('sn').value).setAttribute('class','is'+document.getElementById('sn').value);
                document.getElementById('sn').value++;

                if( document.getElementById('sn').value == 5 )
                        document.getElementById('sn').value=1;

                document.getElementById('sl'+document.getElementById('sn').value).setAttribute('class','is'+document.getElementById('sn').value+'_active');

                ar('slide.php?is='+document.getElementById('sn').value,'slide',2);
                setTimeout("sto()",4500);
        }
}

function dit(){
        return false;
        document.getElementById('sn').value=1;
        setTimeout("sto()",4500);
}

function stb(v,c){
        var val = document.getElementById('sn').value;
        document.getElementById('sl'+val).setAttribute('class','is'+val);
        document.getElementById('sl'+v).setAttribute('class','is'+v+'_active');

        document.getElementById('sn').value=v;
        ar('slide.php?is='+v,'slide',2);

        if( c )
		document.getElementById('str').value=v;
}

function sht(v,id){
	switch(v){
		case 1:	document.getElementById('sh1').setAttribute('class','pdh_active');
			document.getElementById('sd1').style.display='';
			document.getElementById('sh2').setAttribute('class','pdh');
			document.getElementById('sd2').style.display='none';
			document.getElementById('sh3').setAttribute('class','pdh');
			document.getElementById('sd3').style.display='none';
				break;

                case 2: document.getElementById('sh1').setAttribute('class','pdh');
                        document.getElementById('sd1').style.display='none';
                        document.getElementById('sh2').setAttribute('class','pdh_active');
                        document.getElementById('sd2').style.display='';
                        document.getElementById('sh3').setAttribute('class','pdh');
                        document.getElementById('sd3').style.display='none';
                                break;

                case 3: document.getElementById('sh1').setAttribute('class','pdh');
                        document.getElementById('sd1').style.display='none';
                        document.getElementById('sh2').setAttribute('class','pdh');
                        document.getElementById('sd2').style.display='none';
                        document.getElementById('sh3').setAttribute('class','pdh_active');
                        document.getElementById('sd3').style.display='';
                                break;
	}
}

function ucfirst(str,val){
	var f = str.charAt(0).toUpperCase() + str.substr(1);
	if( val )
		return f + val.toString();
		return f;
}

function dis(v){
	var $a = new Array('Black','Green','Herbal','Rooibos','Flavored','Unflavored');
	for(x=0;x<=5;x++){
		if( $a[x] == v ){
			document.getElementById('z'+$a[x]).setAttribute('class','s'+v);
			document.getElementById('m'+$a[x]).style.display='';
		}
		else{
			document.getElementById('z'+$a[x]).setAttribute('class','t'+v);
			document.getElementById('m'+$a[x]).style.display='none';
		}

		for(y=1;y<=5;y++){
			var str = $a[x] + y.toString();

			if( $a[x] == v )
				document.getElementById(str).style.display='';
			else	document.getElementById(str).style.display='none';
		}
	}

	/*document.getElementById('sul').setAttribute('class','s'+v);*/
}

function sis(v){
	if( v != 1 ) document.getElementById('featured').setAttribute('class','unselected');
	if( v != 2 ) document.getElementById('specials').setAttribute('class','unselected');
	if( v != 3 ) document.getElementById('teagifts').setAttribute('class','unselected');
	switch(v){
		case 1: var a = 'Featured';	var b = 'Specials';	var c = 'Teagifts';
			document.getElementById('featured').setAttribute('class','selected'); break;

		case 2: var a = 'Specials';	var b = 'Featured';	var c = 'Teagifts';
			document.getElementById('specials').setAttribute('class','selected'); break;

		case 3:	var a = 'Teagifts';	var b = 'Featured';	var c = 'Specials';
			document.getElementById('teagifts').setAttribute('class','selected'); break;
	}

	for(i=1;i<=5;i++){
		var d = a+i;
		var e = b+i;
		var f = c+i;
		document.getElementById(d).style.display='';
		document.getElementById(e).style.display='none';
		document.getElementById(f).style.display='none';
	}
}

function cQ(form)
{
    var elements = document.getElementById(form).elements;
    var pairs = new Array();
    for (var i = 0; i < elements.length; i++) {
        if ((name = elements[i].name) && (value = elements[i].value))
            pairs.push(name + "=" + encodeURIComponent(value));
    }
    var tastypairpear = pairs.join("&");
    return tastypairpear;
}

function $m(theVar){
        return document.getElementById(theVar)
}

function remove(theVar){
        var theParent = theVar.parentNode;
        theParent.removeChild(theVar);
}

function addEvent(obj, evType, fn){
        if(obj.addEventListener)
            obj.addEventListener(evType, fn, true)
        if(obj.attachEvent)
            obj.attachEvent("on"+evType, fn)
}

function removeEvent(obj, type, fn){
        if(obj.detachEvent){
                obj.detachEvent('on'+type, fn);
        }else{
                obj.removeEventListener(type, fn, false);
        }
}

function isWebKit(){
        return RegExp(" AppleWebKit/").test(navigator.userAgent);
}

function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){
        var detectWebKit = isWebKit();
        form = typeof(form)=="string"?$m(form):form;
        var erro="";
        if(form==null || typeof(form)=="undefined"){
                erro += "The form of 1st parameter does not exists.\n";
        }else if(form.nodeName.toLowerCase()!="form"){
                erro += "The form of 1st parameter its not a form.\n";
        }
        if($m(id_element)==null){
                erro += "The element of 3rd parameter does not exists.\n";
        }
        if(erro.length>0){
                alert("Error in call ajaxUpload:\n" + erro);
                return;
        }
        var iframe = document.createElement("iframe");
        iframe.setAttribute("id","ajax-temp");
        iframe.setAttribute("name","ajax-temp");
        iframe.setAttribute("width","0");
        iframe.setAttribute("height","0");
        iframe.setAttribute("border","0");
        iframe.setAttribute("style","width: 0; height: 0; border: none;");
        form.parentNode.appendChild(iframe);
        window.frames['ajax-temp'].name="ajax-temp";
        var doUpload = function(){
                removeEvent($m('ajax-temp'),"load", doUpload);
                var cross = "javascript: ";
                cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
                $m(id_element).innerHTML = html_error_http;
                $m('ajax-temp').src = cross;
                if(detectWebKit){
                remove($m('ajax-temp'));
        }else{
                setTimeout(function(){ remove($m('ajax-temp'))}, 250);
        }
    }
        addEvent($m('ajax-temp'),"load", doUpload);
        form.setAttribute("target","ajax-temp");
        form.setAttribute("action",url_action);
        form.setAttribute("method","post");
        form.setAttribute("enctype","multipart/form-data");
        form.setAttribute("encoding","multipart/form-data");
        if(html_show_loading.length > 0){
                $m(id_element).innerHTML = html_show_loading;
        }
        form.submit();
}

