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 f.getElementsByTagName(n)
	};
	var nv=function(e){
		if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(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.gets=function(url){
	var x=ajax.x();
	x.open('GET',url,false);
	x.send(null);
	return x.responseText
};
ajax.post=function(url,func,args){
	ajax.send(url,func,'POST',args);
};
ajax.update=function(url,elm){
	var e=$$$(elm);
	var f=function(r){
		e.innerHTML=r
	};
	ajax.get(url,f)
};
ajax.submit=function(url,elm,frm){
	var e=$$$(elm);
	var f=function(r){
		e.innerHTML=r;
	};
	ajax.post(url,f,ajax.serialize(frm));
};

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 dismissErrMsg(){
	document.getElementById('err_message').innerHtml='';
  	document.getElementById("err_message_container").style.display = "none";	
}

function windowClose(elm){
	document.getElementById(elm).innerHtml='';
  	document.getElementById(elm).style.display = "none";	
}

function alertMsg(msg){
	alert(msg);
}

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

function testimonialForm(){
	ajax.update('./handlers/testimonial.php', 'testimonial_div');
}

function rateBlock(id){
	document.getElementById('rate_div').innerHTML='';
  	document.getElementById("rate_div").style.display = "block";
	ajax.update('../handlers/vendor_rate.php?id=' + id, 'rate_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 testimonialResponse(response){
	document.getElementById('testimonial_div').innerHTML=response;
}

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);
}

//Forum Stuff

    function confirmDelete(start, del, mNr, tNr, show) {
      var check = confirm("<? echo $message[14]; ?>");
      if(check) {
        var param = '?start=' + start + '&delete=' + del;
        if(mNr) param += '&mNr=' + mNr + '&tNr=' + tNr;
        if(show) param += '&date_show=' + show;
        document.location.href = '<? echo $PHP_SELF; ?>' + param;
      }
    }

function insertSmilie(txt) {
  var el = document.f1.sfText;
  if(!el.value) el.value = txt + ' ';
  else el.value += ((el.value.charAt(el.value.length-1) == ' ') ? '' : ' ') + txt + ' ';
  el.focus();
}

function countdown(cnt) {
  var obj = 0;

  if(document.getElementById) obj = document.getElementById('divSubmit');
  else if(document.all) obj = document.all.divSubmit;

  if(obj) {
    if(cnt < 1) {
      obj.innerHTML = '[ <a href="javascript:document.f1.submit()" class="cssLink3">Submit</a> ]';
    }
    else {
      obj.innerHTML = '[ ' + cnt + ' ]';
      cnt--;
      setTimeout('countdown(' + cnt + ')', 1000);
    }
  }
}

function delete_mail(type, id)
{
	if (!confirm("\nAre you sure you wish to delete this mail?")){
	}
	else
	{
		location.href="./mail.php?action=delete_mail&type=" + type + "&id=" + id;
	}
}

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 addComment(id){
	document.getElementById('add_comment_div').style.display='block';
	document.getElementById('blog_id').value=id;
}

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");
} 