var tips = {
  myConn:      false,
  body:        false,
  holder:     false,
  rform:     false,
  div:     false,
  init:        function(){

  if( !document.getElementById ||
  	!document.getElementsByTagName ) return;

    tips.myConn = new XHConn();
	tips.body = document.getElementsByTagName('body')[0];
    if( !tips.myConn ) return;


	tips.holder = document.getElementById('tip_a_friend');
	tips.rform = tips.holder.getElementsByTagName('form')[0];
	tips.div = tips.holder.getElementsByTagName('div')[0];
	
	tips.div.removeChild(tips.div.getElementsByTagName('input')[0]);

	var lnk = document.createElement('a');
	addEvent(lnk, 'click', function(){ tips.send(); });
	lnk.innerHTML='<img src="/objects/Tip_friend/images/skicka.gif">';
	tips.div.appendChild(lnk);

  },
  send:  function() {


	if(tips.rform.to_email.value == "" || tips.rform.to_email.value.indexOf("@") == -1) {
		alert("Du m&aring;ste fylla i din kompis e-postadress!");
		tips.rform.to_email.focus();
		return false;
	}
	if(tips.rform.from_name.value == "") {
		alert("Du m&aring;ste fylla i ditt namn!");
		tips.rform.from_name.focus();
		return false;
	}
	if(tips.rform.from_email.value == "" || tips.rform.from_email.value.indexOf("@") == -1) {
		alert("Du m&aring;ste fylla i din e-postadress!");
		tips.rform.from_email.focus();
		return false;
	}





//	loader.buildLoader();
    var fnWhenDone = function(oXML) {
   // 	loader.killLoader();
		tips.htmlsave = tips.holder.innerHTML;
        tips.holder.innerHTML = oXML.responseText;        
   };
    tips.myConn.connect("/o.o.i.s?id=7&template=.ajax.t", "POST", "t=1&func=tip&from_email="+tips.rform.from_email.value+"&from_name="+tips.rform.from_name.value+"&to_email="+tips.rform.to_email.value+"&rid="+tips.rform.id.value+"&vid="+tips.rform.vid.value, fnWhenDone);
    return false;
  }
};
addEvent( window, 'load', function(){ tips.init(); } );
