function fixPNG(element) {
  /*if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
    var src;
    if (element.tagName=='IMG') {
      if (/\.png$/.test(element.src)) {
        src = element.src;
        element.src = "img/blank.gif";
      }
    } else {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src) {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }*/
}

/**
 * @author KNTEL
 */
 
function MapPopup(url_to) {
	window.open(url_to,'Map','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=622,height=381,screenX=150,screenY=150,top=20,left=150')
}

function ShowHideFaq(id) {
 	if (document.getElementById('faq'+id).style.display == 'none') {
 		document.getElementById('faq'+id).style.display = '';
 	} else {
 		document.getElementById('faq'+id).style.display = 'none';
 	}
}
 
 /*Login*/
function sendRequestLogin(url) {
	document.getElementById('idLoginError').style.display = 'none';
	$.ajax({
		url: url,
		cache: false,
		async:false,
		dataType: "text",
		type: "GET",
		data: {
			memberOrPartner:document.getElementById('idMemberOrPartner').value, 
			varLogin:document.getElementById('userID').value,
			varPassword:document.getElementById('userPassword').value
		},
		success: function(data) {
			eval(data);
			if (dataForm['result'] == 'error') {
				document.getElementById('idLoginError').style.display = 'block';
				return;
			}
			else if (dataForm['result'] == 'partner') {
				document.location.href = PROJECT_URI_SSL+'/partner/domain_list';
				return;
			}
			document.location.href = PROJECT_URI_SSL+'/account';
		},
		error: function(data) {
		}
	});
}

/*dictionary_search*/
function DictionarySearch(url, urlLetter) {
	if (document.getElementById('idLetters').value == '2') {
		urlLetter += '/a/'+document.getElementById('idLanguage').value;
/*		document.location.href=urlLetter;
		return;*/
	}
	url += '/'+document.getElementById('idLanguage').value;
	url += '/'+document.getElementById('idLetters').value;

	document.location.href=url;
}

function sendRequestNotification(url) {
	url += '/'+document.getElementById('domainID').value;
	url += '/'+document.getElementById('mailNotification').value;
	if (document.getElementById) {
		var x = mk_xmlhttpreq();
	}

	if (x) {
		x.onreadystatechange = function() {
			if (x.readyState == 4) {
				if (x.status == 200) {
					var responseText = x.responseText;

					eval(responseText);
					if (dataForm['result'] == 'error') {
						document.getElementById('idNotifyError').innerHTML = dataForm['errorMessage'];
						return;
					}

					$('#sendMailNotification').hide();
					document.getElementById('idMessage').innerHTML = dataForm['message'];
				} else if (x.status >= 400) {
				}
			}
		}

		x.open("GET", url, true);
		x.send(null);
	}
}

function loadform(loadedFile){
	$('.TBm2').load(loadedFile);
}
function InitAlert(idMain, logthis, TB_window){
//	$("<div class='TBwindow' style='height:"+ $(document).height() + "px'></div>");
//	$('body').append("<div class='TBmessage'><div class='TBm2'></div></div>");
	$(idMain).show();
	$(TB_window).height($(document).height());
//	$('#TB_window').width($(document).width());
	
	var leftMargin=($(document).width() - ($(logthis).width()))/2;
	var topMargin=(($(window).height() - ($(logthis).height()))/3 + document.getElementsByTagName('body')[0].scrollTop);
	$(logthis).css('left', leftMargin);
	$(logthis).css('top', topMargin);
	$(TB_window).click(function(){
		$(idMain).hide();
		$('#inp1430').focus();
	})
}
function isMemberOrPartner(type) {
	document.getElementById('idMemberOrPartner').value = type;
	if (type == 'partner') {
		$('#idRegistration')[0].href = '/resellst';
		$('#idRegistration')[0].title = 'Partner registration';
		$('#idRegistration').html('Partner registration');
	} else {
		$('#idRegistration')[0].href = '/registr_account';
		$('#idRegistration')[0].title = 'Account registration';
		$('#idRegistration').html('Account registration');
	}
}
document.onkeydown = function(e){   
    if (e == null) { // ie
      keycode = event.keyCode;
    } else { // mozilla
      keycode = e.which;
    }
    if(($('#TB_window'))&&(keycode == 27)){ // close
   	 $('#TB_window').click();
    }
    if(($('#TB_windowMail'))&&(keycode == 27)){ // close
   	 $('#TB_windowMail').click();
    }
};


$(document).ready(function(){
	try {
	$('.zebra tr:even td').css('background','#ebebeb');
	$('.zebra tr:odd td').css('background','#fff');
	$('.zebra td.empty').css('background', 'none');
	
	$('.support .infoArea>ul').children('li').addClass('topLevel');
	$('.topLevel>div').addClass('helpBox').hide();
	
	$('.topLevel h4').hover(
		function(){$(this).addClass('Factive');},
		function(){$(this).removeClass('Factive');}
	)
	
	$('.topLevel h4').click(function(){
		if ($(this).hasClass('Factive2')) {
			$(this).removeClass('Factive2').next('div').slideUp('fast');
		}
		else {
			$('.topLevel>div').slideUp('fast');
			$('.topLevel h4').removeClass('Factive2');
			$(this).addClass('Factive2').next('div').slideDown('fast');
		}
	})
	
	$('#userID').focus(function(){
		if ($(this).attr('value')=='user_ID') {
		
			$(this).attr('value', '').blur(function(){
				if ($(this).attr('value') == '') {
					$(this).attr('value', 'user_ID')
				}
			});
		}
	}) 
	
	$('#userPassword').focus(function(){
		if ($(this).attr('value') == 'user_pass') {
			$(this).attr('value', '').blur(function(){
				if ($(this).attr('value') == '') {
					$(this).attr('value', 'user_pass')
				}
			});
		}
	})
	
	$('.selectmember div').click(function(){
		$('.selectmember div').removeClass('activeTab');
		$(this).addClass('activeTab');
	})
	
	$('#btnLogin').click(function(){
		InitAlert('#loginarea', '#logthis', '#TB_window');
		$('.popupClose').click(function(){$('#TB_window').click();})
		$('#idLoginError').hide();
	})
	
	$('span.busyDomain').click(function(){
		InitAlert('#sendMailNotification', '#logthis', '#TB_windowMail');
		$('.popupClose').click(function(){$('#TB_windowMail').click();})
	})
	
	$('#idAgreement').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	$('#inp1430').focus();
	setMainHeight();
	
	} catch(e){
		alert(e);
	}
})

function setMainHeight() {
   var obj=$('.wrapUserbox');
   $('.mainmap').height('auto');
   if (obj.length && ($('.mainmap').height()<(obj.height()-36))) {
	   $('.mainmap')[0].style.minHeight = obj.height()-36+"px";
	}
}

function get_page_data(container_id, server_url, page_number) {
	$.ajax({
		url: server_url + page_number,
		cache: false,
		async:false,
		dataType: "text",
		type: "GET",
		success: function(data) {
			$('#' + container_id).html(data);
		},
		error: function(data) {
		}
	});		
}

function SendMailNotification() {
	document.getElementById('domainID').value = '<?=$domainID ?>';
	InitAlert('#sendMailNotification', '#logthis', '#TB_windowMail');
	$('.popupClose').click(function(){$('#TB_windowMail').click();})
}

function RenewalBackorder(domainName, type) { // type - account or partner
	$.ajax({
		url: '/'+type+'/backorder/renewalaction',
		cache: false,
		async:false,
		dataType: "text",
		type: "POST",
		data: {
			//backordersID:backordersID
		},
		success: function(data) {
			if(data != "{}") {
				eval(data);
				var classStyle = '';
				for(key in data) {
					if (data[key] == false) {
						classStyle = '';
						if (type == 'partner') {
							classStyle = 'class="white"';
						}
						$('#idBackorderAction_'+key).html("<a "+classStyle+" href='/backorder/"+domainName+"'>Bid now!</a>");
					}
				}
			}
		},
		error: function(data) {
		}
	});
}

function trim(string) {
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

function ScrollToElement(theElement) {
	  var selectedPosX = 0;
	  var selectedPosY = 0;

	  while(theElement != null){
	    selectedPosX += theElement.offsetLeft;
	    selectedPosY += theElement.offsetTop;
	    theElement = theElement.offsetParent;
	  }

	 window.scrollTo(selectedPosX,selectedPosY);
}