var globalURL = '';
var interval=null;
var divObj;
var contentObj;
var timeout;
function checkAll(checkbox) {
	if (checkbox)
	   {
	   var boxes=document.getElementsByTagName('input');
	   for (i=0;i<boxes.length;i++)
	       {
		   if ((boxes[i].name=='multipledomains[]') && (boxes[i].type=='checkbox'))
		      {
			  boxes[i].checked=true;
			  }
		   }
	   }
	else
	   {
	   var boxes=document.getElementsByTagName('input');
	   for (i=0;i<boxes.length;i++)
	       {
		   if ((boxes[i].name=='multipledomains[]') && (boxes[i].type=='checkbox'))
		      {
			  boxes[i].checked=false;
			  }
		   }
	   }
	}
function ajax_auth(username,password){                                                                                            
        var xmlhttp;                                                                                                         
        if (window.XMLHttpRequest)                                                                                                
                {                                                                                                                     
                 // code for IE7+, Firefox, Chrome, Opera, Safari                                                                     
                 xmlhttp=new XMLHttpRequest();                                                                                        
                }                                                                                                                     
        else if (window.ActiveXObject)                                                                                            
                {                                                                                                                     
                 // code for IE6, IE5                                                                                                 
                 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");                                                                      
                }                                                                                                                     
        else                                                                                                                      
                {                                                                                                                     
                 alert("Your browser does not support XMLHTTP!");                                                                     
                }                                                                                                             
        xmlhttp.onreadystatechange=function(){                                                                                          
                                        if(xmlhttp.readyState==4)                                                                                         
                                              {                                                                                                               
                                              var haystack=xmlhttp.responseText;
                                              var needle="Detaliile de autentificare sunt incorecte.";
                                              var i = (haystack+'').indexOf(needle,0);
                                              if(i==-1) window.location="http://hosting.bunt.ro/reseller-domenii";
                                              else Shadowbox.open({content:'<div style="background-image:url(images/error_message.png); height:141px; width:448px"></div>',player:'html',title:'Eroare autentificare',width:448,height:141});
                                              }                                                                                                               
                                        }                                                       
        xmlhttp.open("GET","../clienti/dologin.php?username="+username+"&password="+password,true);                                
        xmlhttp.send(null);                                                                                                            
       }

function setTipContent(content) {
	contentObj = document.getElementById("tooltip_content");
	contentObj.innerHTML = content;
}

function setToolTip(e) {
	var posx = 0;
	var posy = 0;
	if (!e)
	e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft
		+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
		+ document.documentElement.scrollTop;
	}
	divObj = document.getElementById("tooltip");
	divObj.style.display = 'block';
	divObj.style.top=(posy+10)+"px";
	divObj.style.left=(posx+23)+"px";
}
function hideTooltip() {
	divObj = document.getElementById("tooltip");
	divObj.style.display = 'none';
}
function expandPanel(div)
        {
	    if (document.getElementById('domains_panel').offsetHeight>187)
		   {
		   div.style.backgroundImage="url(images/expand_arrow.png)";
		   div.title="Mai mult";
		   param='close';
		   }
		else
		   {
		   div.style.backgroundImage="url(images/collapse_arraow.png)";
		   div.title="Ascunde";
		   param='open';
		   }
	    if (param=='open')
		   {
		   if (interval!=null)
		      {
		      interval=clearInterval(interval);
			  }
		   start_from=document.getElementById('domains_panel').offsetHeight;
		   interval=setInterval("slideup('domains_panel',start_from,350,8);",1);
		   }
		else if (param=='close')
		   {
		   if (interval!=null)
		      {
		      interval=clearInterval(interval);
			  }
		   start_from=document.getElementById('domains_panel').offsetHeight;
		   interval=setInterval("slidedown('domains_panel',start_from,187,8);",1);
		   }
		}
function slideup(id,start_at,stop_at,step)
        {
	    start_from=start_at;
		if (start_from<=stop_at)
		   {
		   document.getElementById(id).style.height=start_from+'px';
		   start_from=start_from+step;
		   }
		else
		   {
		   interval=window.clearInterval(interval);
		   document.getElementById(id).style.height=stop_at+'px';
		   }
		}
function slidedown(id,start_at,stop_at,step)
        {
	    start_from=start_at;
		if (start_from>=stop_at)
		   {
		   document.getElementById(id).style.height=start_from+'px';
		   start_from=start_from-step;
		   }
		else
		   {
		   interval=window.clearInterval(interval);
		   document.getElementById(id).style.height=stop_at+'px';
		   }
		}
function checkDomain(value,where)
{

	url = 'http://hosting.bunt.ro/reseller-domenii/domainchecker.php?domain='+value;
	if(value!='' && globalURL!=value)
		{
		$('#'+where).load(url);
		globalURL = value;
		document.getElementById('fromdomain').value=value;
		}
	url = 'http://hosting.bunt.ro/reseller-domenii/checkmoney.php?domain='+value;
	if(value!='')
		{
		$('#'+where+'_money').load(url);
		}
}
function checkTLD(form)
		{
		var tlds = new Object();
		tlds[0]='.ro';
		tlds[1]='.com';
		tlds[2]='.net';
		tlds[3]='.eu';
		tlds[4]='.org';
		tlds[5]='.info';
		tlds[6]='.co.uk';
		tlds[7]='.us';
		tlds[8]='.biz';
		tlds[9]='.name';
		tlds[10]='.mobi';
		tlds[11]='.me';
		tlds[12]='.tv';
		tlds[13]='.com.ro';
		tlds[14]='.org.ro';
		tlds[15]='.tm.ro';
		tlds[16]='.nt.ro';
		tlds[17]='.nom.ro';
		tlds[18]='.info.ro';
		tlds[19]='.arts.ro';
		tlds[20]='.firm.ro';
		tlds[21]='.store.ro';
		tlds[22]='.www.ro';
		tld=form.reqdomain.value.substr(form.reqdomain.value.indexOf('.'));
		found=false;
		for (i=0;i<=22;i++)
		    {
		    if (tlds[i]==tld)
			   {
			   found=true;
			   break;
			   }
		    }
	    if (!found)
		   {
		   alert('Domeniu invalid');
		   }
		return found;
		}
function rejectSpace(e)
{
var keynum=-1;
var KeyID = (window.event) ? event.keyCode : e.keyCode;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
if (keynum==-1)
   {
   }
else if (keynum==32)
   {
   return false;
   }
   return true;
}

function selectClientExisting(value)
{
	if(document.getElementById('multipledomains'))
	{
		var domenii = document.getElementById('multipledomains').value;
		var i; var url='';
		for(i=0;i<domenii;i++)
		{
			if(url=='')
			url = document.getElementById('domain'+i).value;
			else
			url = url+','+document.getElementById('domain'+i).value;
		}
		url = '&multipledomains='+url;

		if(value!='')
		{
		window.location='./neworder?existingClient='+value+url;
		}
	}
	else
	{
		window.location='./neworder?existingClient='+value;
	}
}

function checkDomainRegister()
{

	var domainrequest = document.getElementById('reqdomain').value;
	var extensionrequest = document.getElementById('reqextension').value;

	url = 'http://hosting.bunt.ro/reseller-domenii/domainchecker.php?domain='+domain+extensionrequest;
	$("#reqstatus") = load(url);

}

function checkPasswordStrength(password)
{
	$('#passwordCheck').load("http://hosting.bunt.ro/reseller-domenii/passwordStrength.php?password="+password);
}

function checkPhoneFormat(phone)
{
	$('#phoneCheck').load("http://hosting.bunt.ro/reseller-domenii/phoneFormat.php?phone="+phone);
}

function checkMail(mail)
{
	$('#mailCheck').load("http://hosting.bunt.ro/reseller-domenii/mailCheck.php?mail="+mail);
}



function del(id)
       {
	   txt=document.getElementById(id).value;
	   if (txt.indexOf( 'www.' )!=-1)
	      {
		  txt=txt.substr(4,txt.length);
		  document.getElementById(id).value=txt;
		  }
	   }
function toggleAll(type)
       {
	   if (type=='on')
	      {
		   checks=document.getElementsByName('tlds[]');
		   for (i=0;i<checks.length;i++)
			   {
			   if(checks[i].title=='main')
			   checks[i].checked=true;
			   }
		}
	   if (type=='off')
	      {
		   checks=document.getElementsByName('tlds[]');
		   for (i=0;i<checks.length;i++)
			   {
			   if(checks[i].title=='main')
			   checks[i].checked=false;
			   }
		  }
	   }

function restrictOne(object){
    {
     var final=object.checked;
     if(object.title=='secondary'){
    				   var checks=document.getElementsByName('tlds[]');
				   for (i=0;i<checks.length;i++)
				    {
				     if(checks[i].title=='secondary')
				     checks[i].checked=false;
				    }
				    object.checked=final;
    				  }
    }
}
function buyAll(id,type)
       {
	   if (type=='on')
	      {
		   checks=document.getElementById(id).getElementsByTagName('input');
		   for (i=0;i<checks.length;i++)
			   {
			   checks[i].checked=true;
			   }
		  }
	   if (type=='off')
	      {
		   checks=document.getElementById(id).getElementsByTagName('input');
		   for (i=0;i<checks.length;i++)
			   {
			   checks[i].checked=false;
			   }
		  }
	   }
function suspended() {
		 Shadowbox.open({content:'<div style="background-image:url(images/suspended_account.png); height:141px; width:448px"></div>',player:'html',title:'Eroare',width:448,height:141});
		 }var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
}
function fixAll() {
	var imgs = new Object();
	imgs=document.getElementsByTagName('img');
	while (imgs.length>0)
		{
		var x=imgs[0];
		fixPNG(x);
	    imgs=document.getElementsByTagName('img');
		}
	}


var domains='';
function checkMultipleDomains(number)
{
	//alert('Testing multiple: '+number);
	var i = 0;
	value='';
	for(i=0;i<number;i++)
	{
		value += document.getElementById('domain'+i).value+',';
	}
	
	url = 'http://hosting.bunt.ro/reseller-domenii/domainchecker2.php?domain='+value+'&i='+i;
	$.get(url,function(data){
					   var tmp=data.split('&');
					   var prices=tmp[2].split('|');
					   tmp[0]=''+tmp[0];
					   for(i=0;i<number;i++){
					       if(tmp[0].substr(i,1)=='0'){var t=document.getElementById('statusDomain'+i);t.innerHTML='<img src="./images/domain_ok.png" alt="" title="Disponibil" /> &nbsp;<span style="display:inline-block;position:relative;top:-10px;font-weight:bold;color:#c63a39;font-size:18px">'+prices[i]+'&euro;</span>';}
					       if(tmp[0].substr(i,1)=='1'){var t=document.getElementById('statusDomain'+i);t.innerHTML='<img src="./images/domain_invalid.png"  alt="" title="Invalid" />';}
						   if(tmp[0].substr(i,1)=='2'){var t=document.getElementById('statusDomain'+i);t.innerHTML='<img src="./images/domain_taken.png"  alt="" title="Indisponibil" />';}
						   if(tmp[0].substr(i,1)=='3'){var t=document.getElementById('statusDomain'+i);t.innerHTML='<img src="./images/domain_invalid.png" alt="" title="Deja procesat" />';}
					      }
						if(tmp[1]=='0'){
							             document.getElementById('client_data').style.display='none';
										 document.getElementById('money_warning').style.display='';
							            }
							else {
								  document.getElementById('client_data').style.display='';
								  document.getElementById('money_warning').style.display='none';      
								 }
					   });
	}


function clear_domain(id,max_domains){
	 var tmp=document.getElementById('domain'+id);
	 tmp.value='';
	 tmp=document.getElementById('tr_'+id);
	 tmp.style.display='none';
	 checkMultipleDomains(max_domains);
	}