	// Cross browser add event wrapper

// 	function addEvent(elm, evType, fn, useCapture) {
//   	if (elm.addEventListener) {
//     	elm.addEventListener(evType, fn, useCapture);
//     	return true;
//   	}
//   	if (elm.attachEvent) return elm.attachEvent('on' + evType, fn);
//   	elm['on' + evType] = fn;
//   	return false;
// 	}
      
function cleanFromMailer(mode){
 idFrom  = mode
 objForm = document.getElementById(idFrom)
 objForm.reset();
 if (document.getElementById('imgCaptcha')){
    refCaptcha()
  }
}


function refCaptcha(){

  var currentTime = new Date(); 
  var curTime = currentTime.getSeconds();
  
  $('#imgCaptcha').delay(100,function(){
      $('#imgCaptcha').attr('src','captcha.asp?'+curTime);
    });
 }


function NewWindow(mypage, myname, w, h, scroll) {
  
  var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll
  win = window.open(mypage, myname, winprops)
  win.window.focus(); 

}


function LoadScript(url, viewinf)
{
    if($('#newWeather')){
        $('#newWeather').remove();
    }
    if (typeof(vieinf)=="undefined") vieinf="";
    var sel = document.getElementById("weather");
	  var obj= document.getElementById("informer"+viewinf);
	  //url = sel.options[sel.selectedIndex].value;
	  var cityName = sel.options[sel.selectedIndex].text;
	  var fullUrl = url + end_url

	  if (!obj) obj= document.getElementById("informer");
	  if (obj) {
	  	srcobj= document.createElement("script");
      if(srcobj.setAttribute) srcobj.setAttribute("src",fullUrl);
      else srcobj.src=fullUrl;
      srcobj.setAttribute('id', 'newWeather');
      srcobj.onreadystatechange = function () {
        //wait 0.1 sec
       //obj.innerHTML = srcobj.readyState+'...';

          if (srcobj.readyState == 'complete' || srcobj.readyState == 'loaded') {
               obj.innerHTML=responseText;
               $('#gmtdttl2').remove();
               $('#gmtbl2 :first-child :nth-child(6)').remove()
               $("#nameCityWeather").html(": "+ cityName);
              }
      }

      
      srcobj.onload=function() {
      	  obj.innerHTML=responseText;
      	  $('#gmtdttl2').remove();
      	  $('#gmtbl2 :first-child :nth-child(6)').remove()
          $("#nameCityWeather").html(": "+ cityName);
      }
      document.getElementsByTagName("head")[0].appendChild(srcobj);
	  }
}


	$(function(){
  	if($.uniform){
  		$("select").uniform();
  		//$(":radio").uniform();
  		//$(":checkbox").uniform();
    }


		$('#wrapLogin').hide();

		$('#openLoginForm').click(function(){
		//alert($(window).width())
				var tPic = $('#imgOpenForm').position().top-4;
				var lPic = $('#imgOpenForm').position().left-222
				$('#wrapLogin').css({'top':tPic+'px','left':lPic+'px'}).slideDown();
			});

		$('#closeLoginForm').click(function(){
				$('#wrapLogin').slideUp();
			});

	});


	$(document).ready(function() {
			$('input[type="text"]').addClass("idleField");
			$('input[type="password"]').addClass("idleField");
      $('textarea').addClass("idleField");
      
       	$('input[type="text"]').add($('input[type="password"]')).add('textarea').focus (function() {
       			$(this).removeClass("idleField").addClass("focusField");

           if (! $(":textarea")){
    		    	if (this.value == this.defaultValue){
    		    		this.value = '';
				  	 }
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').add($('input[type="password"]')).add('textarea').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});

    		$('.artContent img').each(function(){
    			//$(this).css('opacity','0');
          var showFirstLoad = $('.artContent img').slice(0,1)
          showFirstLoad.attr('id','fImageArt');
             $('<div class="loaderImg" id="loaderImg"> Loading...</div>').insertAfter(showFirstLoad);

        });

		//initCorners();

		});


      showQuarters = function(obj,idCity,idQuarter){
			
        var idCity = idCity ? idCity : $(obj).val();
        var idQuarter = idQuarter ? idQuarter : '';
        
        
        $.getJSON("getCity.asp",{id_city: idCity,id_region: idQuarter}, function(j){
					var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].value + '">' + j[i].caption + '</option>';
					}
					$("#id_quarters").html(options);
					
					if (idCity == ''){
            $('#id_citys option:first').attr('selected', 'selected');
          } else {
            $('#id_city option[value='+idCity+']').attr('selected', 'selected');
          }

					if (idQuarter == ''){
					     $('#id_quarters option:first').attr('selected', 'selected');
					} else{
               $('#id_quarters option[value='+idQuarter+']').attr('selected', 'selected');
          }
				})
        return
      }


      showCity = function(obj,idCountry,idCity){

			  var idCountry = idCountry ? idCountry : $(obj).val();
        var idCity = idCity ? idCity : '';
        
        
        $.getJSON("getCity.asp",{id_country: idCountry,id_city: idCity}, function(j){
					var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].value + '">' + j[i].caption + '</option>';
					}

					$("#id_city").html(options);
				
					if (idCountry == ''){
            $('#id_countries option:first').attr('selected', 'selected');
          } else {
            $('#id_country option[value='+idCountry+']').attr('selected', 'selected');
          }		
			
					if (idCity == ''){
            $('#id_citys option:first').attr('selected', 'selected');
          } else {
            $('#id_city option[value='+idCity+']').attr('selected', 'selected');
          }

				})
        return
      }


  $(document).ready(function(){
  
 			$("#id_city").change(function(){
          showQuarters(this);
			})

 			$("#id_country").change(function(){
          showCity(this);
			})

          //showQuarters($("#id_city"),'1','21');


          $('.loaderImg').remove();

    		//$.elementReady('fImageArt', function(){
          var sizeImg = $('.artContent img').size()

          /*if (sizeImg > 1)
             { classFloat = 'divFloatLeft' }
             else
              { classFloat = 'divFloatLeft' }
          */   
          var firstImage = $('.artContent img').slice(0,1)
					var titleImg = $(firstImage).attr('title');
							if(titleImg=='') titleImg = $(firstImage).attr('alt');
								titleImg ? titleImg : '';
					var floatImage = $(firstImage).attr('align');
					   if (floatImage=='right'){
              classFloat = 'divFloatRight'
             }else{
              classFloat = 'divFloatLeft'
             }

                firstImage
   							.wrap('<div class="wrapImage '+ classFloat +'" style="width:'+ $(firstImage).width() +'px;" ></div>')
  							.after('<div class="altImage">'+ titleImg +'</div>')
  							.css({'margin':'0','border':'1px solid white','opacity':'1'}).show();
  							//.animate({opacity : '1'},350);
  							

          $('.artContent img').slice(1).each(function(){
						var titleImg = $(this).attr('title');
							if(titleImg=='') titleImg = $(this).attr('alt');
								titleImg ? titleImg : '';

					var floatImage = $(this).attr('align');
					   if (floatImage=='right'){
              classFloat = 'divFloatRight'
             }else{
              classFloat = 'divFloatLeft'
             }

                $(this)//.css('width','160px')
  							.wrap('<div class="wrapOtherImage '+ classFloat +'" style="width:'+ $(this).width() +'px;" ></div>')
  							.after('<div class="altImage">'+ titleImg +'</div>')
  							.css({'margin':'0','border':'1px solid white','opacity':'1'}).show();
  							//.animate({opacity : '1'},350);
    			  });
            sizeOverImage = $('.wrapOtherImage').size()
    			  //$('.wrapOtherImage').slice((sizeOverImage-1),sizeOverImage).after('<div class="clearfix"></div>');
         //});

        }
   );

 jQuery.fn.autoWidth = function(options)
        {
        var settings = {
        limitWidth : false
        }

        if(options) {
        jQuery.extend(settings, options);
        };

        var maxWidth = 0;

        this.each(function(){
        if ($(this).width() > maxWidth){
        if(settings.limitWidth && maxWidth >= settings.limitWidth) {
        maxWidth = settings.limitWidth;
        } else {
        maxWidth = $(this).width();
        }
        }
        });

        this.width(maxWidth);
  }
        

$(document).ready(function(){

	$('#regForm').submit(function(e) {

		register();
		e.preventDefault();

	});

});


function register()
{
	//hideshow('loading',true);
  ShowHideLoaderBtn ('#btnSbmForm');
	
  error(0);

	$.ajax({
		type: "POST",
		url: "submit.asp",
		data: $('#regForm').serialize(),
		dataType: "json",
		success: function(msg){

			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
      else if(parseInt(msg.status)==2)
			{
				sucsess(1,msg.txt);
				ShowHideLoaderBtn ('#btnSbmForm');
			}
      else if(parseInt(msg.status)==3)
			{
				sucsessEdit(1,msg.txt);
				ShowHideLoaderBtn ('#btnSbmForm');
			}
      else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
				ShowHideLoaderBtn ('#btnSbmForm');
			}

		}
	});

}

function ShowHideLoaderBtn (elHide){
	if ($(elHide+':visible').length > 0){
	  $(elHide).hide();
		$('<img />')
			.attr({
				src: 'images/ajax_anim.gif',
				title: 'Loading...',
				id: 'AjaxAnim'
			})
			.css({
				'width': '21px',
				'height': '5px'
			})
			.appendTo('#wrapBtnSbm');
	} else {
		if ($('#AjaxAnim').length > 0){
			 $('#AjaxAnim').remove();
		}
		$(elHide).show();
	}

}


function hideshow(el,act)
{
	if(act) $('#'+el).show();//.css('visibility','visible');
	else $('#'+el).hide();//.css('visibility','hidden');
}

function error(act,txt)
{
  $('#userok').hide()
  hideshow('error',act);
	if(txt) $('#error').html(txt);
}

function sucsess(act,txt)
{
  $('#error').hide()
	hideshow('userok',act);
	if(txt) $('#userok').html(txt);
  $('#regForm').clearForm();
  refCaptcha();
}

function sucsessEdit(act,txt)
{
  $('#error').hide()
	hideshow('userok',act);
	if(txt) $('#userok').html(txt);
	$('#captcha').val('');
  refCaptcha();
  $('#userok').doTimeout(3000,function(){$('#userok').fadeOut();})
}

$.fn.clearForm = function() {
  // iterate each matching form
  return this.each(function() {
 // iterate the elements within the form
 $(':input', this).each(function() {
   var type = this.type, tag = this.tagName.toLowerCase();
   if (type == 'text' || type == 'password' || tag == 'textarea')
  this.value = '';
   else if (type == 'checkbox' || type == 'radio')
  this.checked = false;
   else if (tag == 'select')
  this.selectedIndex = -1;
 });
  });
};

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);
}

// To close one thickbox and then open another, this is quite handy
// when you want to open another response modal window on the action of current modal window.
// Opening more then one thickbox window is not possible on the same page,
// so closing one and opening another could be quite handy and we can change height
// and width as well for another window.
var jThickboxNewLink;

function tb_remove_open(reloadLink){
jThickboxReloadLink	=	reloadLink;
tb_remove();
setTimeout("jThickboxNewLink();",500);
return false;
}

// This function will let you open new thickbox window without specifying
// class="Thickbox" and any href="http://web.com" attribute
// It will be helpful when you are dynamically loading any content and
// from those content you would like to open Thickbox windows.
// As basically the nature of thickbox is such that it scans all links (..) tags
// on load using jQuery's $(document).ready function so if your link is loaded using ajex
// or using any dynamic javascript and was not on page at the time of load then this thickbox
// setup won't work and you have to use this function.
function tb_open_new(jThickboxNewLink){
tb_show(null,jThickboxNewLink,null);
}

// Modified to provide parent window's function callback
function tb_remove(parent_func_callback) {
$("#TB_imageOff").unbind("click");
$("#TB_closeWindowButton").unbind("click");
$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
$("#TB_load").remove();
if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
$("body","html").css({height: "auto", width: "auto"});
$("html").css("overflow","");
}
if(parent_func_callback != undefined)
eval("window."+parent_func_callback);
document.onkeydown = "";
document.onkeyup = "";
return false;
}

(function($) {

$.fn.clickUrl = function() {
	var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
	this.each(function() {
		$(this).html(
			$(this).html().replace(regexp,"<a href=\"$1\">$1</a>")
		);
	});
	return $(this);
}

$.fn.stripTags = function() {
	var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
	this.each(function() {
		$(this).html(
			$(this).html().replace(regexp,"")
		);
	});
	return $(this);
}

$.fn.escapeHtml = function() {
	this.each(function() {
		$(this).html(
			$(this).html()
				.replace(/&/g,'&amp;')
				.replace(/</g,'&lt;')
				.replace(/>/g,'&gt;')
				.replace(/"/g,'&quot;')
		);
	});
	return $(this);
}

})(jQuery);

jQuery.fn.center = function()
	{
	var w = $(window);
	this.css("position","absolute");
	this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
	return this;
	}

// Convert string to boolean

	Boolean.parse = function(str) {
    switch (str.toLowerCase()) {
        case "true":
            return true;
        case "false":
            return false;
        default:
            throw new Error("Boolean.parse: Cannot convert string to boolean.");
    }
};

// Check word length characters > 13
//$("input[id$=TextBox1]").blur(function() {
//    var data = $(this).val().split(" ");
//    for (var i = 0; i < data.length; i++) {
//        if (data[i].length >= 13) {
//            alert(data[i]);
//        }
//    }
//});

// Slice from left and right sides of string

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

// Title page blink for new message

function titlebar(val)
{
	var speed = 500;
	var pos = val;


	var msg1  = "    "+msg.toUpperCase()+" ----";
	var msg2  = "    "+msg.toLowerCase()+" ====";

	if(pos == 0){
		masg = msg1;
		pos = 1;
	}
	else if(pos == 1){
		masg = msg2;
		pos = 0;
	}

	document.title = masg;
	timerTitle = window.setTimeout("titlebar("+pos+")",speed);
}


$(document).ready(function() {
	
		
});
