function TurnItOn(obj){
 document.getElementById("tmn"+obj).className = "on";
 document.getElementById("tmn"+obj).href = '#0';
}

over =  new Image();
over.src = '../images/box/domain/status-checked.gif';
free =  new Image();
free.src = '../images/box/domain/status-free.gif';

function Changeit(obj){
 if (obj.width != 18) return 0;
 DOMAINN = document.getElementById("DDname").value;
 Dom = DOMAINN + ("." + obj.id.substring(2)).replace(/([^\.])ir$/, '$1.ir');

 T = document.getElementById("SelectedDomain").value;
 if(T.indexOf(";"+Dom+";") == -1){
  T = T+';'+ Dom+';';
  T = T.replace(";;", ";");
  obj.src = over.src;
 }
 else{
   T = T.replace(";"+Dom+";", ";");
   T = T.replace(";;", ";");
   obj.src = free.src;
  }
 document.getElementById("SelectedDomain").value = T;
}

function testit(){ var ext = new Array('com', 'net', 'org', 'biz', 'info', 'us','tv','cc','cn','ir', 'coir', 'orgir', 'netir', 'acir', 'schir');
 finished = true;
 for (var i=0;i<ext.length;i++){
  if(eval("document.getElementById('IM"+ext[i]+"').width == 19"))
   finished = false;
  if(eval("document.getElementById('IM"+ext[i]+"').width == 28")){
		eval("document.getElementById('IM"+ext[i]+"').src 	= '../images/box/domain/status-search.gif'");
	eval("document.getElementById('IM"+ext[i]+"').src 	= '../images/whois/getwhois.php?domain="+document.getElementById('DDname').value+"."+Dotinsert(ext[i])+"&rnd=<?=$RND2?>"+Math.round(Math.random()*1000)+"'");
	finished = false;
  } 
} 
 if(!finished) setTimeout('testit()', 500);
}

function GetWhois(obj, WDomain){
S = obj.id;
S = S.substring(1);

OB = document.getElementById('IM'+S);
OW = OB.width;
switch (OW){
 case 19: alert("Please Wait ... "); break;
 case 18: Changeit(OB);break;
 case 28: alert("<-- Please refresh the Image ");break;
 case 20: 	ww = window.open('../images/whois/domain-whois.php?domain='+WDomain+'&rnd=<?=$RND2?>'+Math.round(Math.random()*1000), 'Who_is', 'width=500, height=300, scrollbars=yes');
		  ww.focus();
		  break;
 }
}

function enterit2(e){
if (document.all){
 if(e.keyCode==13)
  CheckDomain2('DDname'); 
}
else{
 if(e.which==13)
  CheckDomain2('DDname'); 
}  
}
function SetFormat(id, text, color){
 DomainName = document.getElementById('DDname').value;
 DomainN = "";
 if (DomainName.length > 11)
  for(var i=0;i<DomainName.length;i++)
   DomainN += (i % 11 == 10)? DomainName.charAt(i)+' ':DomainName.charAt(i);
 else
  DomainN = DomainName;  
 return '<a id="'+id+'" href="javascript:void(0);" onclick="GetWhois(this, \''+DomainN+text+'\')" class="domainN" >' + DomainN +	'<font color=#'+color+'>'+text+'</font></a>';
 
}

function Dotinsert(text){
 return text.replace(/(.+)(ir)$/, "$1.$2");
}

function checkD2(){
 setTimeout('testit()', 500);
 document.getElementById('comment').style.display = 'none';
 document.getElementById('result').style.display = '';
 document.getElementById('legend').style.display = '';
 document.location.href = '#page1';
 
 var ext = new Array('com', 'net', 'org', 'biz', 'ir', 'info','us','tv','cc','cn','coir', 'orgir', 'netir', 'acir', 'schir');
 for (var i=0;i<ext.length;i++){
  eval("document.getElementById('TD"+ext[i]+"').innerHTML 	= SetFormat('A"+ext[i]+"'   , '."+Dotinsert(ext[i])+"', '003399')");
  eval("document.getElementById('IM"+ext[i]+"').src 	= '../images/box/domain/status-search.gif'");
  eval("document.getElementById('IM"+ext[i]+"').src 		= '../images/whois/getwhois.php?domain="+document.getElementById('DDname').value+"."+Dotinsert(ext[i])+"&rnd=<?=$RND2?>"+Math.round(Math.random()*1000)+"'");
  }
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CheckDomain2(obj){
 document.getElementById("SelectedDomain").value = '';
 var DomainName = document.getElementById(obj).value;
 var md = DomainName.split(/\./ig);
 var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789--";
 DomainName = (md[0]=='www')?md[1]:md[0];
 document.getElementById(obj).value =  DomainName.toLowerCase();
 var DomainLen  = document.getElementById(obj).value.length;
 var valid = true;
 if (DomainName == "" || DomainLen < 2 || DomainLen > 30) valid=false;
 
 else
 for (i = 0;  i < DomainName.length;  i++)
 {
   ch = DomainName.charAt(i);
   for (j = 0;  j < checkOK.length;  j++)
     if (ch == checkOK.charAt(j))
       break;
   if (j == checkOK.length)
   {
     valid = false;
     break;
   }
   else valid = true;
 }
 
 if (valid && DomainLen > 2)
  setTimeout('checkD2()', 100);
 else
  alert("ERROR...\n\n\n\nInvalid Domain Name!\n'"+DomainName+".com'\n\n(Here you can check domain between 3 to 30 characters only!)");
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var MAXsc = 260;
var LASTsc = -1;
function Scrolltop(obj){
 if(obj)
 	LASTsc = 1000;
 window.document.body.scrollTop = Math.round(window.document.body.scrollTop/4*3)-1;
 if(window.document.body.scrollTop == 0)
	return;
 if(window.document.body.scrollTop < LASTsc)
	 setTimeout('Scrolltop()', 100);
 LASTsc = window.document.body.scrollTop; 
}

function Scrollit(obj){
 if(obj)
 	LASTsc = obj;
 st = window.document.body.scrollTop
 window.document.body.scrollTop = st + Math.ceil(MAXsc - st)/5;
 if(window.document.body.scrollTop <= LASTsc){
 	window.document.body.scrollTop = MAXsc;
 	return;
 	}
 LASTsc = window.document.body.scrollTop;
 setTimeout('Scrollit()', 50);
}

function TurnitOf(obj){
 if(document.getElementById("mmn"+obj))
	document.getElementById("mmn"+obj).className = "";
 if(document.getElementById("td_"+obj))
	document.getElementById("td_"+obj).className = "hide";
}

function TurnOffAll(){
 for(var i=1;i<10;i++)
 	if(document.getElementById("mmn"+i))
 		TurnitOf(i);
}

function Switchto(obj){
 if(obj == 0) Scrolltop(1000);
 if(!document.getElementById("mmn"+obj)) return;
 TurnOffAll();
 document.getElementById("mmn"+obj).className = "on"
 document.getElementById("td_"+obj).className = "show";
 document.getElementById("PagePathText").innerHTML = fPageTitle + " / " + document.getElementById("mmn"+obj).innerHTML;
 Scrollit(obj);
}

LASTP = '';
function CheckP(){
	R = document.location.href.split('#');
	if(LASTP != R[1] && R[1] >= 0){
		LASTP = R[1];
		Switchto(R[1]);
		}
}

function Starter(){
 setInterval('CheckP()', 100);
 LASTP = '';
 document.getElementById("PagePathText").innerHTML = fPageTitle;
}

function EmailItTo(){
 W = 400;
 H = 200;
 L = Math.round((screen.width - W)/2);
 T = Math.round((screen.height - H)/2);
 nw = window.open("pagemailer.php", "PageMailer", "menubar=no,scrollbars=no,width="+W+",height="+H+",status=no,left="+L+",top="+T);
 nw.focus();
}
