
/*
 *
 *	Application:	TORA'S WHOIS
 *	Version:	0.1
 *	File:		./media/scripts/scriptsPortal.js
 *	Last update:	2007-04-27
 *
 *	URL:		http://whois.toras-systems.com
 *
 *	Copyright:	Tora's Systems (www.toras-systems.com), 2007
 *			CZ-Online Webdesign (www.cz-online.com), 2007
 *
 */


		var countAvail =1;
		httpRequest = new Object();

function ajaxRequest(){
//alert("ajaxRequest");
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
//  return new XDomainRequest()
//alert("ActiveXObject");
	if (window.XDomainRequest) // IE8
  		return new ActiveXObject("Microsoft.XMLHTTP")

   for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) {// if Mozilla, Safari etc
//alert("XMLHttpRequest");
  return new XMLHttpRequest()
 } else if (window.XDomainRequest) {// IE8
//alert("XDomainRequest");
   return new ActiveXObject("Microsoft.XMLHTTP")
//  return new XDomainRequest()
 } else {
//alert("none");
  return false
 }
}


		function checkDomain( domainName, domainName8,domainExt, domainID, domainStatus, loadingImage, showWhois, form ) {

			var url			= "http://registrera-doman.se/w/index.php?doAction=checkDomain&searchDomainName="+domainName+"&searchDomainExt="+domainExt;
			var showDomainID	= document.getElementById( domainID );
			showDomainID.innerHTML	= "<img src=\"" + loadingImage + "\" alt=\"S&ocirc;ker\" />";
// http://www.javascriptkit.com/jsref/ajax.shtml
			if ( url != 0 ) {
//				if ( window.ActiveXObject ) {
//					httpRequest[domainExt] = new ActiveXObject("Microsoft.XMLHTTP");
//				} else {
//					httpRequest[domainExt] = new XMLHttpRequest();
//				}
//				httpRequest[domainExt] = new XMLHttpRequest;
				lable=domainName+domainExt;
				httpRequest[lable] = new ajaxRequest();
				httpRequest[lable].open("GET", url, true);
				httpRequest[lable].onreadystatechange	= function () { processRequest( domainID, domainStatus, domainName, domainName8, domainExt, showWhois, form ); } ;
				httpRequest[lable].send(null);
			} else {
				document.getElementById(domainID).innerHTML = "";
			}

		}


		function processRequest( domainID, domainStatus, domainName, domainName8, domainExt, showWhois, form ) {
				lable=domainName+domainExt;
//alert("processRequest: "+domainName+"."+domainExt+' '+domainID);
			if ( httpRequest[lable].readyState == 4 ) {
				if( httpRequest[lable].status == 200 ) {
					var showDomainID	= document.getElementById( domainID );
					var showDomainStatus	= document.getElementById( domainStatus );

					if ( httpRequest[ lable ].responseText == "OK" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/accept.png border=0 alt=\"Ledig dom&auml;n\">";
						showDomainID.innerHTML		= "<input type=checkbox name=check" + countAvail + " value=" + domainName8 + "." + domainExt + " />";
						countAvail = countAvail+1;
						//form.numdomains.disabled = true;
					} else if ( httpRequest[ lable ].responseText == "ERROR_101" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/lock.png border=0 alt=\"Upptagen dom&auml;n\">";
						showDomainID.innerHTML		= "<a href=\"javascript: showDomainWhois( '" + domainName + "', '" + domainExt + "' );\">" + "whois</a> / " + "<a href=http://" + domainName + "." + domainExt + " target=blank>www</a>";
					} else if ( httpRequest[ lable ].responseText == "ERROR_102" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/exclamation.png border=0 alt=\"Ogiltliga tecken\">";
						showDomainID.innerHTML		= " ";
					} else if ( httpRequest[ lable ].responseText == "ERROR_103" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/exclamation.png border=0 alt=\"Tomt domännamn\">";
						showDomainID.innerHTML		= " ";
					} else if ( httpRequest[ lable ].responseText == "ERROR_104" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/exclamation.png border=0 alt=\"Ogiltlig toppdomän\">";
						showDomainID.innerHTML		= " ";
					} else if ( httpRequest[ lable ].responseText == "ERROR_105" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois servern svarade inte\">";
						showDomainID.innerHTML		= " ";
					} else if ( httpRequest[ lable ].responseText == "ERROR_106" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois server timeout\">";
						showDomainID.innerHTML		= " ";
					} else {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois server timeout\">";
//						showDomainStatus.innerHTML	= "Unknown error";
						showDomainID.innerHTML		= " ";
					}
				} else {
					alert( "Chyba pri nacitani stanky \n"+ httpRequest[lable].status +":"+ httpRequest[domainExt].statusText );
				}
			} else {
				//alert("Hello" + httpRequest[domainExt].readyState );
//				alert("processRequest error:\nreadyState: " + httpRequest[domainExt].readyState + ":" + httpRequest[domainExt].statusText);
			}

		}

		function processPHPRequest( domainID, domainStatus, domainName, domainName8, domainExt, showWhois, form , responseText) {
//alert("processPHPRequest: " + domainName + " " + responseText);
					var showDomainID	= document.getElementById( domainID );
					var showDomainStatus	= document.getElementById( domainStatus );

					if ( responseText == "OK" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/accept.png border=0 alt=\"Ledig dom&auml;n\">";
						showDomainID.innerHTML		= "<input type=checkbox name=check" + countAvail + " value=" + domainName8 + "." + domainExt + " />";
						countAvail = countAvail+1;
						//form.numdomains.disabled = true;
					} else if ( responseText == "ERROR_101" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/lock.png border=0 alt=\"Upptagen dom&auml;n\">";
						showDomainID.innerHTML		= "<a href=\"javascript: showDomainWhois( '" + domainName + "', '" + domainExt + "' );\">" + "whois</a> / " + "<a href=http://" + domainName + "." + domainExt + " target=blank>www</a>";
					} else if ( responseText == "ERROR_102" ) {
						showDomainStatus.innerHTML	= "Incorrect characters";
						showDomainID.innerHTML		= " ";
					} else if ( responseText == "ERROR_103" ) {
						showDomainStatus.innerHTML	= "Empty domain name";
						showDomainID.innerHTML		= " ";
					} else if ( responseText == "ERROR_104" ) {
						showDomainStatus.innerHTML	= "Non-supported domain extension";
						showDomainID.innerHTML		= " ";
					} else if ( responseText == "ERROR_105" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois servern svarade inte\">";
						showDomainID.innerHTML		= " ";
					} else if ( responseText == "ERROR_106" ) {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois server timeout\">";
						showDomainID.innerHTML		= " ";
					} else {
						showDomainStatus.innerHTML	= "<img src=media/images/hourglass_delete.png border=0 alt=\"Whois server timeout\">";
//						showDomainStatus.innerHTML	= "Unknown error";
						showDomainID.innerHTML		= " ";
					}

		}

		function showDomainWhois( domainName, domainExt ) {

			window.open( "whois-light.php?w=" + domainName + "." + domainExt, "whoisInfo", "width=750,height=600,left=50,top=50,scrollbars=1" );

		}

		function showDomainWhois_v3( domainName, domainExt ) {

			window.open( "v3/index.php?w=" + domainName + "." + domainExt, "whoisInfo", "width=750,height=600,left=50,top=50,scrollbars=1" );

		}
		function showDomainWhois_orig( domainName, domainExt ) {

			window.open( "index.php?doAction=showWhois&searchDomainName=" + domainName + "&searchDomainExt=" + domainExt, "whoisInfo", "width=750,height=600,left=50,top=50,scrollbars=1" );

		}

