// voting
$(function() {

$(".vote").click(function() 
{

var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);


if(name=='up')
{

$(this).fadeIn(200).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle">');
$.ajax({
   type: "POST",
   url: "http://spodeli.bg-info.info/up_vote.php",
   data: dataString,
   cache: false,

   success: function(html)
   {
    parent.html(html);
  
  }  });
  
}
else
{

$(this).fadeIn(200).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle">');
$.ajax({
   type: "POST",
   url: "http://spodeli.bg-info.info/down_vote.php",
   data: dataString,
   cache: false,

   success: function(html)
   {
       parent.html(html);
  }
   
 });


}
  
  
   
 

return false;
	});

});


// show kategories
$(function() {
    $("#showcats").click(function(){
        var tile = $(this).attr("title");
        var tekst = $(this).text(name);
            $("#cats").slideToggle(100);
        if(tile == "show"){
            //$(this).text(name+'Покажи категории');
            $(this).text(name+'Скрий категории');
            $(this).attr("title" , "hide");
        }else{
            $(this).text(name+'Покажи категории');
            $(this).attr("title" , "show");
        }
        
        return false;
    });
});


// user setings
$(function() {
    $(".seting").click(function(){
        $("#showseting").slideToggle(100);
        return false;
    });
});

// user setings
$(function() {
    $("html").click(function(){
        $("#showseting").hide();
        
    });
});

// show fastshare
$(function() {
    $(".fastlnc").click(function(){
        $("#furlshare").slideToggle(300);
        return false;
    }); 
});

//fast share
$(document).ready(function(){
    $("#goshare").click(function(){
        var url = $("#url").val();
        var dataString = 'url=' + url ;
        if(url != ''){      
            $("#load").show();
            $("#load").fadeIn(400).html('loading please weit.....<img src="http://spodeli.bg-info.info/images/loading1.gif" align="absmiddle" style="border:0px;"> !');
            $("#s1").hide();
                $.ajax({
                type: "POST",
                url: "http://spodeli.bg-info.info/steptwo.php",
                data: dataString,
                cache: false,
                    success: function(html){
                        $("#addtrue").append(html);
                        $("#load").hide();
                        $("#s1").remove();
                    }
                });
        }else{
            alert("Не сте задали урл адрес за публикуване!");
        }        
    return false;
    });
});


//step two
$(function() {
    $('#imageadd').live('change', function(){
        $("#preview").show();
        $("#preview").fadeIn(400).html("Uploading....<img src='http://spodeli.bg-info.info/images/loading1.gif' align='absmiddle' style='border:0px;' /> ");
            $("#imageform").ajaxForm({
                target: "#preview",
                url: "http://spodeli.bg-info.info/stepthre.php",
            }).submit();
    return false;
    });
});


$(function() {
    $("#videourl").live('change', function(){
        var parent = $(this);
        var id = $(this).attr("id");
        var value = $("#videourl").val();
        var dataString = 'id='+ id + '&value=' + value;
        //alert("За да разблокирате този потребител от приятели трябва да сте влезнал в профила си!");
        if(value != ''){
            $("#vualert").show();
            $("#vuailert").fadeIn(400).html("Зареждам....<img src='http://spodeli.bg-info.info/images/loading1.gif' align='absmiddle' style='border:0px;' /> ");
            $.ajax({
               type: "POST",
               url: "http://spodeli.bg-info.info/checkvideourl.php",
               data: dataString,
               cache: false,
            
               success: function(html){
                 $("#vualert").append(html);
                 //$("#videourl").val();
                 $("#vuailert").hide();
                }  
            });
        } 
        return false;
    	});
     
     $("#videourl").live('click', function(){
        $("div.vuinalert").remove();
        $("div.vinfo").remove();
        $("#videourl").val('');
        $("#videocode").val('');
        return false;
    });
});

$(function() {
    $("#videocode").live('click', function(){
        $("div.vuinalert").remove();
        $("div.vinfo").remove();
        $("#videourl").val('');
        return false;
    });
});


// comenting
$(function() {
    $(".submit").click(function(){
        var msid = $("#msid").val();
        var kname = $("#kname").val();
        var aname = $("#aname").val();
        var au = $("#au").val();
        var coment = $("#coment").val();
        //var cookies = getCookie('username');
        var cu = $("#cu").val();
        var dataString = 'msid=' + msid + '&kname=' + kname + '&aname=' + aname + '&au=' + au + '&coment=' + coment;
        if(coment==''){
            alert('Please Give Valid Details');
        }else{
            if(cu==''){
                    document.getElementById('coment').value='';
                    alert("За да коментираш трябва да си регистриран потребител! ");
            }else{
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> Loading Comment...');
                $.ajax({
                type: "POST",
                url: "http://spodeli.bg-info.info/postcoment.php",
                data: dataString,
                cache: false,
                    success: function(html){
                    $("div#update").append(html);
                    $("div#update div:last").fadeIn("slow");
                    $("#flash").hide();
                    document.getElementById('coment').value='';
                    }
                });
            }
        }
        return false;
    }); 
});



// coment
$(document).ready(function(){
    
    $(".comment_button").click(function(){
        var element = $(this);
        var I = element.attr("id");
        var name = element.attr("name");
        var am = element.attr("class");
        var rel = element.attr("rel");
        $("#slidepanel"+I).slideToggle(300);
        $(this).toggleClass("active"); 
        if(am == 'comment_button'){
            if(name != '0'){
                $("#flash"+I).show();
                $("#flash"+I).fadeIn(300).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> Loading Comment...');
                $.ajax({
                    type: "POST",
                    url: "http://spodeli.bg-info.info/commentsviev.php",
                    data: "msg_id="+I,
                    cache: false,
                        success: function(html){
                            //$("#slidepanel"+I).hide();
                            $("#loadplace"+I).append(html);
                            $("#flash"+I).hide();
                        }
                    });
                    
            }
            $(this).text(name+' скрий');
        }else{
            $(this).text(rel);
            //$("#slidepanel"+I).hide();
            $("#two_comments"+I).remove();
            $("#new-coment"+I).remove();
        }
        return false;
    });
});

// post coment
$(document).ready(function(){
    $(".comment_submit").click(function(){
        var element = $(this);
        var Id = element.attr("id");
        var msid = $("#msid"+Id).val();
        var kname = $("#kname"+Id).val();
        var aname = $("#aname"+Id).val();
        var au = $("#au"+Id).val();
        var coment = $("#coment"+Id).val();
        var cu = $("#cu").val();
        var dataString = 'msid=' + msid + '&kname=' + kname + '&aname=' + aname + '&au=' + au + '&coment=' + coment;
            if(coment==''){
                alert("Please Give Valid Details ");
            }else{
                if(cu==''){
                    alert("За да коментираш трябва да си регистриран потребител! ");
                    document.getElementById('coment'+Id).value='';
                }else{
                    $("#flash"+Id).show();
                    $("#flash"+Id).fadeIn(400).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> loading.....');
                        $.ajax({
                        type: "POST",
                        url: "http://spodeli.bg-info.info/postcoment.php",
                        data: dataString,
                        cache: false,
                            success: function(html){
                                $("#loadplace"+Id).append(html);
                                $("#flash"+Id).hide();
                                document.getElementById('coment'+Id).value='';
                            }
                        });
                  }      
            }
    return false;
    });
});


// recomenting
$(function() {
    $(".recomment").click(function(){
        var msid = $("#msid").val();
        var mcid = $("#mcid").val();
        var kname = $("#kname").val();
        var cname = $("#cname").val();
        var aname = $("#aname").val();
        var au = $("#au").val();
        var coment = $("#coment").val();
        //var cookies = getCookie('username');
        var cu = $("#cu").val();
        var dataString = 'msid=' + msid + '&mcid=' + mcid + '&kname=' + kname + '&cname=' + cname + '&aname=' + aname + '&au=' + au + '&coment=' + coment;
        if(coment==''){
            alert('Please Give Valid Details');
        }else{
            if(cu==''){
                    document.getElementById('coment').value='';
                    alert("За да коментираш трябва да си регистриран потребител! ");
            }else{
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> Loading Comment...');
                $.ajax({
                type: "POST",
                url: "http://spodeli.bg-info.info/recomment.php",
                data: dataString,
                cache: false,
                    success: function(html){
                    $("div#update").append(html);
                    $("div#update div:last").fadeIn("slow");
                    $("#flash").hide();
                    document.getElementById('coment').value='';
                    }
                });
            }
        }
        return false;
    }); 
});




// fawolme
$(function() {
    $(".fawolme").click(function(){
    
        var id = $(this).attr("id");
        var name = $(this).attr("name");
        var dataString = 'id='+ id + '&name=' + name;
        var parent = $(this);
    
        if(name != ''){
            $("#aflash"+id).show();
            $("#aiflash"+id).fadeIn(400).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> loading.....');
            $.ajax({
               type: "POST",
               url: "http://spodeli.bg-info.info/fowolme.php",
               data: dataString,
               cache: false,
            
               success: function(html){
                 $("#aflash"+id).append(html);
                 $("#aiflash"+id).hide();
                 $("#"+id).remove();
                }  
            });
        }else{
            alert("За да следваш този потребител трябва да си регистриран потребител!");
        }
    return false;
    	});
});

// unfawolme
$(function() {
    $(".unfawolme").click(function(){
    
        var id = $(this).attr("id");
        var name = $(this).attr("name");
        var dataString = 'id='+ id + '&name=' + name;
        var parent = $(this);
    
        if(name != ''){
            $("#aflash"+id).show();
            $("#aiflash"+id).fadeIn(400).html('<img src="http://spodeli.bg-info.info/loading.gif" align="absmiddle" style="border:0px;"> loading.....');
            $.ajax({
               type: "POST",
               url: "http://spodeli.bg-info.info/unfowolme.php",
               data: dataString,
               cache: false,
            
               success: function(html){
                 $("#aflash"+id).append(html);
                 $("#aiflash"+id).hide();
                 $("#"+id).remove();
                }  
            });
        }else{
            alert("За да блокирате този потребител от приятели трябва да сте влезнал в профила си!");
        }
    return false;
    	});
});

//select all
function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

//facebook
function fbs_click() {
    u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&lt;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
    }

// flash fix
objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
   objects[i].outerHTML = objects[i].outerHTML;
}



//Specify affected tags. Add or remove from list:
var tgs = new Array( 'font');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

//popup wind
function popupwnd(url, toolbar, menubar, locationbar, resize, scrollbars, statusbar, left, top, width, height)
{
   var popupwindow = this.open(url, '', 'toolbar=' + toolbar + ',menubar=' + menubar + ',location=' + locationbar + ',scrollbars=' + scrollbars + ',resizable=' + resize + ',status=' + statusbar + ',left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
}

// go menu
function OnGoMenuFormLink(GoList)
{
   var url = GoList.options[GoList.selectedIndex].value;
   var target = GoList.options[GoList.selectedIndex].className;
   GoList.selectedIndex=0;
   GoList.blur();
   if (url)
   {
      NewWin=window.open(url,target);
      window['NewWin'].focus()
   }
}

// cookie user resolution
writeCookie();

function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 2010");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie

}


// fade image
function FadeImage(id, duration)
{
   var millisec = Math.round(duration / 100);
   var timer = 0;
   for(i = 0; i <= 100; i++)
   {
      setTimeout("SetOpacity('" + id + "'," + i + ")",(timer * millisec));
      timer++;
   }
}
function SetOpacity(id, opacity)
{
   var element = document.getElementById(id).style;
   element.opacity = (opacity / 100);
   element.MozOpacity = (opacity / 100);
   element.KhtmlOpacity = (opacity / 100);
   element.filter = "alpha(opacity=" + opacity + ")";
}




// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
//
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// Update Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
//
// Update Oct 2005: minor tidy-up: unused parameter removed
//
// Update Jun 2006: minor improvements to variable names and layout
// ----------------------------------------------------------------------

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

// --------------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// --------------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}


// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}


// --------------------------------------------
//                  msg
// Display warn/error message in HTML element.
// commonCheck routine must have previously been called
// --------------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message)) 
    dispmessage = String.fromCharCode(nbsp);    
  else  
    dispmessage = message;

  var elem = document.getElementById(fld);
  elem.firstChild.nodeValue = dispmessage;  
  
  elem.className = msgtype;   // set the CSS class to adjust appearance of message
}

// --------------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// --------------------------------------------

var proceed = 2;  

function commonCheck    (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node  

  if (emptyString.test(valfield.value)) {
    if (required) {
      msg (infofield, "error", "ERROR: required");  
      setfocus(valfield);
      return false;
    }
    else {
      msg (infofield, "warn", "");   // OK
      return true;  
    }
  }
  return proceed;
}

// --------------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so 
// --------------------------------------------

function validatePresent(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{
  var stat = commonCheck (valfield, infofield, true);
  if (stat != proceed) return stat;

  msg (infofield, "warn", "");  
  return true;
}

// --------------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// --------------------------------------------

function validateEmail  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    msg (infofield, "error", "ERROR: not a valid e-mail address");
    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld)) 
    msg (infofield, "warn", "Unusual e-mail address - check if correct");
  else
    msg (infofield, "warn", "");
  return true;
}


// objekt by id
function FindObject(id, doc)
{
   var child, elem;
   if(!doc)
      doc=document;
   if(doc.getElementById)
      elem=doc.getElementById(id);
   else
   if(doc.layers)
      child=doc.layers;
   else
   if(doc.all)
      elem=doc.all[id];
   if(elem)
      return elem;
   if(doc.id==id || doc.name==id)
      return doc;
   if(doc.childNodes)
      child=doc.childNodes;
   if(child)
   {
      for(var i=0; i<child.length; i++)
      {
         elem=FindObject(id,child[i]);
         if(elem)
            return elem;
      }
   }
   var frm=doc.forms;
   if(frm)
   {
      for(var i=0; i<frm.length; i++)
      {
         var elems=frm[i].elements;
         for(var j=0; j<elems.length; j++)
         {
            elem=FindObject(id,elems[i]);
            if(elem) return elem;
         }
      }
   }
   return null;
}


function ShowObject(id, flag)
{
   var elem=FindObject(id);
   if(elem)
      elem.style.visibility=flag?'visible':'hidden';
}



function limitText(limitField, limitCount, limitNum) {
  if (limitField.value.length > limitNum) {
    limitField.value = limitField.value.substring(0, limitNum);
  } else {
    limitCount.value = limitNum - limitField.value.length;
  }
}


//comboxes

function change(currentbox) {
	numb = currentbox.id.split("_");
	currentbox = numb[1];

    i=parseInt(currentbox)+1

// I empty all combo boxes following the current one

    while ((eval("typeof(document.getElementById(\"cat_"+i+"\"))!='undefined'")) &&
           (document.getElementById("cat_"+i)!=null)) {
         son = document.getElementById("cat_"+i);
	     // I empty all options except the first one (it isn't allowed)
	     for (m=son.options.length-1;m>0;m--) son.options[m]=null;
	     // I reset the first option
	     son.options[0]=new Option(displaywhenempty,valuewhenempty)
	     i=i+1
    }


// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill

    stringa='data'
    i=0
    while ((eval("typeof(document.getElementById(\"cat_"+i+"\"))!='undefined'")) &&
           (document.getElementById("cat_"+i)!=null)) {
           eval("stringa=stringa+'_'+document.getElementById(\"cat_"+i+"\").selectedIndex")
           if (i==currentbox) break;
           i=i+1
    }


// filling the "son" combo (if exists)

    following=parseInt(currentbox)+1

    if ((eval("typeof(document.getElementById(\"cat_"+following+"\"))!='undefined'")) &&
       (document.getElementById("cat_"+following)!=null)) {
       son = document.getElementById("cat_"+following);
       stringa=stringa+"_"
       i=0
       while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

       // if there are no options, I empty the first option of the "son" combo
	   // otherwise I put "-select-" in it

	   	  if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
	   	      if (eval("typeof("+stringa+"1)=='undefined'"))
	   	         eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
	   	      else
	             eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
	      else
              eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
	      i=i+1
	   }
       //son.focus()
       i=1
       combostatus=''
       cstatus=stringa.split("_")
       while (cstatus[i]!=null) {
          combostatus=combostatus+cstatus[i]
          i=i+1
          }
       return combostatus;
    }
}


// --------------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// --------------------------------------------

function validateTelnr  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/  ;
  if (!telnr.test(tfld)) {
    msg (infofield, "error", "ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +");
    setfocus(valfield);
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) {
    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");
    setfocus(valfield);
    return false;
  }

  if (numdigits>14)
    msg (infofield, "warn", numdigits + " digits - check if correct");
  else { 
    if (numdigits<10)
      msg (infofield, "warn", "Only " + numdigits + " digits - check if correct");
    else
      msg (infofield, "warn", "");
  }
  return true;
}

// --------------------------------------------
//             validateAge
// Validate person's age
// Returns true if OK 
// --------------------------------------------

function validateAge    (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);
  var ageRE = /^[0-9]{1,3}$/
  if (!ageRE.test(tfld)) {
    msg (infofield, "error", "ERROR: not a valid age");
    setfocus(valfield);
    return false;
  }

  if (tfld>=200) {
    msg (infofield, "error", "ERROR: not a valid age");
    setfocus(valfield);
    return false;
  }

  if (tfld>110) msg (infofield, "warn", "Older than 110: check correct");
  else {
    if (tfld<7) msg (infofield, "warn", "Bit young for this, aren't you?");
    else        msg (infofield, "warn", "");
  }
  return true;
}






// Flooble.com's Animated Text script. Will animate a specified 
	// bit of text (determined by the ID of containing tag) by 
	// highlighting it with specified color one character at a time 
	// in a moving pattern.
	//
	// Summary of use: 
	//     call animate(tagID, color); where "tagID" is the ID 
	//     of the tag that contains text to be animated,
	//     and "color" is the color to use to highlight the text with.
	//
	// For more information, and detailed instructions, see 
	//     http://www.flooble.com/scripts/animate.php
	//
	// Copyright (c) 2002 by Animus Pactum Consulting Inc.
	// This script comes with no warranties whatsoever. 
	// Animus Pactum Consulting will not be responsible
	// for any damages resulting from its use.

        var ie4 = false;
        if(document.all) {
                ie4 = true; 
        }       
        function setContent(name, value) {
                var d;  
                if (ie4) { 
                        d = document.all[name];
                } else {
                        d = document.getElementById(name);
                }       
                d.innerHTML = value;    
        }       

	function getContent(name) {
		var d;
                if (ie4) {
                        d = document.all[name];
                } else {
                        d = document.getElementById(name);
                }
                return d.innerHTML;
	}

        function setColor(name, value) {
                var d;  
                if (ie4) { 
                        d = document.all[name];
                } else {
                        d = document.getElementById(name);
                }
                d.style.color = value;  
        }

	function getColor(name) {
                var d;
                if (ie4) {
                        d = document.all[name];
                } else {
                        d = document.getElementById(name);
                }
                return d.style.color;
        }

        function animate(name, col) {
		var value = getContent(name);
		if (value.indexOf('<span') >= 0) { return; }
		var length = 0;
                var str = '';
		var ch;
		var token = '';
		var htmltag = false;	
                for (i = 0; i < value.length; i++) {
			ch = value.substring(i, i+1);
			if (i < value.length - 1) { nextch = value.substring(i+1, i+2); } else { nextch = ' '; }
			token += ch;
			if (ch == '<' && '/aAbBpPhHiIoOuUlLtT'.indexOf(nextch) >= 0) { htmltag = true; }
			if (ch == '>' && htmltag) { htmltag = false; }
			if (!htmltag && ch.charCodeAt(0) > 30 && ch != ' ' && ch != '\n') {		
                        	str += '<span id="' + name + '_' + length + '">' + token + '</span>';
				token = '';
				length++;
			}
                }
                setContent(name, str);
                command = 'animateloop(\'' + name + '\', ' + length + ', 0, 1, \'' + col + '\')';
                setTimeout(command , 100);
        }

        function animateloop(name, length, ind, delta, col) {
		var next = ind + delta;
		if (next >= length) { delta = delta * -1; next = ind + delta; }
		if (next < 0) { delta = delta * -1; next = ind + delta; }
                setColor(name + '_' + ind, getColor(name + '_' + next));
                setColor(name + '_' + next, col);
                command = 'animateloop(\'' + name + '\', ' + length + ', ' + next + ', ' + delta + ', \'' + col + '\')';
                setTimeout(command , 100);
        }
        
        //coments emotions

// Remember the current position.
function storeCaret(text)
{
    // Only bother if it will be useful.
    if (typeof(text.createTextRange) != "undefined")
        text.caretPos = document.selection.createRange().duplicate();
}

function SmileIT(smile,textarea){
    // Attempt to create a text range (IE).
    if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
    {
        var caretPos = textarea.caretPos;

        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? smile + ' ' : smile
        caretPos.select();
    }
    // Mozilla text range replace.
    else if (typeof(textarea.selectionStart) != "undefined")
    {
        var begin = textarea.value.substr(0, textarea.selectionStart);
        var end = textarea.value.substr(textarea.selectionEnd);
        var scrollPos = textarea.scrollTop;

        textarea.value = begin + smile + end;

        if (textarea.setSelectionRange)
        {
            textarea.focus();
            textarea.setSelectionRange(begin.length + smile.length, begin.length + smile.length);
        }
        textarea.scrollTop = scrollPos;
    }
    // Just put it on the end.
    else
    {
        textarea.value += smile;
        textarea.focus(textarea.value.length - 1);
    }
}

function PopMoreSmiles(form,name) {
         link='moresmiles.php?form='+form+'&text='+name
         newWin=window.open(link,'moresmile','height=500,width=300,resizable=yes,scrollbars=yes');
         if (window.focus) {newWin.focus()}
}

function BBTag(opentag, closetag, textarea)
{
    // Can a text range be created?
    if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
    {
        var caretPos = textarea.caretPos, temp_length = caretPos.text.length;

        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? opentag + caretPos.text + closetag + ' ' : opentag + caretPos.text + closetag;

        if (temp_length == 0)
        {
            caretPos.moveStart("character", -closetag.length);
            caretPos.moveEnd("character", -closetag.length);
            caretPos.select();
        }
        else
            textarea.focus(caretPos);
    }
    // Mozilla text range wrap.
    else if (typeof(textarea.selectionStart) != "undefined")
    {
        var begin = textarea.value.substr(0, textarea.selectionStart);
        var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
        var end = textarea.value.substr(textarea.selectionEnd);
        var newCursorPos = textarea.selectionStart;
        var scrollPos = textarea.scrollTop;

        textarea.value = begin + opentag + selection + closetag + end;

        if (textarea.setSelectionRange)
        {
            if (selection.length == 0)
                textarea.setSelectionRange(newCursorPos + opentag.length, newCursorPos + opentag.length);
            else
                textarea.setSelectionRange(newCursorPos, newCursorPos + opentag.length + selection.length + closetag.length);
            textarea.focus();
        }
        textarea.scrollTop = scrollPos;
    }
    // Just put them on the end, then.
    else
    {
        textarea.value += opentag + closetag;
        textarea.focus(textarea.value.length - 1);
    }
}



function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#bannercontact").height();
	var popupWidth = $("#bannercontact").width();
    var popupHeight = $("#bannerbackground").height();
	var popupWidth = $("#bannerbackground").width();
	//centering
	$("#bannercontact").css({
		"position": "fixed",
		//"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
    
	//only need force for IE6
	$("#bannerbackground").css({
		"position": "fixed",
		//"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
}

$(document).ready(function() {
    centerPopup();
 $("#bannerbackground").css({
  "opacity": "0.7"
 });
 $('#bannerbackground, #bannercontact').slideDown('slow', function() {
 });
 setTimeout(function(){
  $("#bannerbackground").slideUp("slow");
  $("#bannercontact").slideUp("slow");
 }, 60000);
});

function hideBanner () 
{
 $("#bannerbackground").stop(true, true).slideUp("slow");
 $("#bannercontact").slideUp("slow");
}

/**
 * X-Team Snow
 * @author Andrew Valums
 *
 * Copyright (c) 2009 X-Team, http://x-team.com
 */
(function(){function k(a,b,c){if(a.addEventListener)a.addEventListener(b,c,false);else a.attachEvent&&a.attachEvent("on"+b,c)}function g(a){if(typeof window.onload!="function")window.onload=a;else{var b=window.onload;window.onload=function(){b();a()}}}function h(){var a={};for(type in{Top:"",Left:""}){var b=type=="Top"?"Y":"X";if(typeof window["page"+b+"Offset"]!="undefined")a[type.toLowerCase()]=window["page"+b+"Offset"];else{b=document.documentElement.clientHeight?document.documentElement:document.body; a[type.toLowerCase()]=b["scroll"+type]}}return a}function l(){var a=document.body,b;if(window.innerHeight)b=window.innerHeight;else if(a.parentElement.clientHeight)b=a.parentElement.clientHeight;else if(a&&a.clientHeight)b=a.clientHeight;return b}function i(a){this.parent=document.body;this.createEl(this.parent,a);this.size=Math.random()*5+5;this.el.style.width=Math.round(this.size)+"px";this.el.style.height=Math.round(this.size)+"px";this.maxLeft=document.body.offsetWidth-this.size;this.maxTop=document.body.offsetHeight- this.size;this.left=Math.random()*this.maxLeft;this.top=h().top+1;this.angle=1.4+0.2*Math.random();this.minAngle=1.4;this.maxAngle=1.6;this.angleDelta=0.01*Math.random();this.speed=2+Math.random()}var j=false;g(function(){j=true});var f=true;window.createSnow=function(a,b){if(j){var c=[],m=setInterval(function(){f&&b>c.length&&Math.random()<b*0.0025&&c.push(new i(a));!f&&!c.length&&clearInterval(m);for(var e=h().top,n=l(),d=c.length-1;d>=0;d--)if(c[d])if(c[d].top<e||c[d].top+c[d].size+1>e+n){c[d].remove(); c[d]=null;c.splice(d,1)}else{c[d].move();c[d].draw()}},40);k(window,"scroll",function(){for(var e=c.length-1;e>=0;e--)c[e].draw()})}else g(function(){createSnow(a,b)})};window.removeSnow=function(){f=false};i.prototype={createEl:function(a,b){this.el=document.createElement("img");this.el.setAttribute("src",b+"snow"+Math.floor(Math.random()*4)+".gif");this.el.style.position="absolute";this.el.style.display="block";this.el.style.zIndex="99999";this.parent.appendChild(this.el)},move:function(){if(this.angle< this.minAngle||this.angle>this.maxAngle)this.angleDelta=-this.angleDelta;this.angle+=this.angleDelta;this.left+=this.speed*Math.cos(this.angle*Math.PI);this.top-=this.speed*Math.sin(this.angle*Math.PI);if(this.left<0)this.left=this.maxLeft;else if(this.left>this.maxLeft)this.left=0},draw:function(){this.el.style.top=Math.round(this.top)+"px";this.el.style.left=Math.round(this.left)+"px"},remove:function(){this.parent.removeChild(this.el);this.parent=this.el=null}}})();
