// client-side functions for BuyDomains.com

// to launch Control Panel in the main window when window focus is on a pop-up.
function controlPanel() {
	win2=opener.parent.location.href = '/login/control_panel.jsp';
}

// to launch the control panel demo
function launchDemo() {
	window.open("/demo/index.jsp","doDemo","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=680,height=750,left=10,top=10,marginwidth=0, marginheight=0");
}

// to open a pop-up window
function openW(url, name, w, h, o) {
// options - menubar,location,resizable,scrollbars,status,toolbar (there are more)
// if you want them just list them seperated by commas
	var wlocation = "left=25,screenX=25,top=25,screenY=25";
	var windowprops = "width=" + w + ",height=" + h;
	if (o != '')
	    windowprops = windowprops + "," + o + "," + wlocation;
	popup = window.open(url, name, windowprops);
	popup.focus();
}

// pop up Sweepstakes Terms & Conditions
function showSTC() {
	window.open("/sweepstakes/frames/sweepstakesTermsO.jsp","doSTC","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=450,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Terms of Sale
function showTOS() {
	window.open("/info/terms-of-sale-pop.jsp","doTOS","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=450,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Terms of Use
function showTOU() {
	window.open("/info/terms-of-use-pop.jsp","doTOU","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=450,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Alerts Phase II
function showAPQ(anc) {
	window.open("/info/alerts-phase-questions-pop.jsp#" + anc,"doAPQ","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=450,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Legal Owner
function showLegalOwner() {
	window.open("/info/legal_owner.jsp","doTOS","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=400,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Domain Agreement
function showDomainAgreement() {
	window.open("/info/domain_agreement.jsp","doDomAgree","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=400,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Dispute Resolution
function showDisputeResolution() {
	window.open("/info/dispute_resolution.jsp","doDisRes","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=400,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up Thawte Certificate
function showThawte() {
	window.open("https://www.thawte.com/core/process?process=public-site-seal-cert-details&public-site-seal-cert-details.code=USYESDX1","doThawte","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=500,height=570,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up credit card verification
function showVerifyCC() {
	window.open("/info/cc_verification.jsp","doThawte","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=525,height=300,left=100,top=100,marginwidth=0, marginheight=0");
}

// rollovers for info buttons on Value Added Services
function switchImg(imgId, status) {
	var obj = document.getElementById(imgId);
	if (status == "on") {
		obj.setAttribute("src", "/images/buttons/button_info_roll.gif");
	} else {
		obj.setAttribute("src", "/images/buttons/button_info.gif");
	}
}

// pop up post-sale info
function showPostSale() {
		window.open("/find-premium-domains/postsale_pop.jsp","doPS","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=325,left=100,top=100,marginwidth=0, marginheight=0");
}

// pop up hosting plan
function showPlan(plan) {
	window.open("/info/hosting/package_" + plan + ".jsp","doPlan","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=475,left=100,top=100,marginwidth=0, marginheight=0");
}

// used to scroll to show the error msg
function scrollToTop() {
    window.scrollTo(0, 0);
}

function isValidEmail(email) {
    var result = true;
    if (email != null && email.length > 0) {
        var emailRegxp = /^.+@.+\..{2,4}$/;
        result = emailRegxp.test(email);
    }
    return result;
}

// called up function in Offermatica test to show list of domain categories
var arrCat = new Array("Real Estate", "Health &amp; Medicine", "Home &amp; Garden", "Business", "Finance", "Music", "Two characters", "Three characters", "Four characters", "More categories");
var arrUrl = new Array("search-results.jsp?category_id=23", "search-results.jsp?category_id=18", "search-results.jsp?category_id=28", "search-results.jsp?category_id=2", "search-results.jsp?category_id=32", "search-results.jsp?category_id=12", "search-results.jsp?length_min=1&length_max=2", "search-results.jsp?length_min=1&length_max=3", "search-results.jsp?length_min=1&length_max=4", "other-search.jsp?searchType=category");
var strCat = "";
var counter = 1;

function showHomeCategories() {
	for (var i = 0; i < arrCat.length; i++) {
		if (counter == 1) {
			strCat += '<tr class="rowA">\n';
		} else {
			strCat += '<tr class="rowB">\n';
		}
		strCat += '<td class="blueLeft"><a href="/find-premium-domains/' + arrUrl[i] + '">' + arrCat[i] + '</a></td>\n';
		strCat += '<td class="blueRight"><a href="/find-premium-domains/' + arrUrl[i] + '">Take a Look</a> <span class="arrow">&#187;</span></td>\n';
		strCat += '</tr>\n';
		counter++;
		if (counter > 2) {
			counter = 1;
		}
	}
	document.write(strCat);	
}

// show DHTML pop-up box
function displayInfo(box) {
	document.getElementById(box).className = "visible";
}

// hide DHTML pop-up box
function closeBox(box) {
	document.getElementById(box).className = "hidden";
}

function sendScreenInfo() {
	tracker = new Image();
	tracker.src="/images/blank.gif?report=screenInfo" +
		"&availHeight=" + screen.availHeight +
		"&availWidth=" + screen.availWidth +
		"&height=" + screen.height +
		"&width=" + screen.width +
		"&colorDepth=" + screen.colorDepth +
		"&pixelDepth=" + screen.pixelDepth;	
}

function updateLevel2List(){
	loadLevel2CategoryList();
	var lvl1 = document.getElementsByName('l1')[0];
	var lvl2 = document.getElementsByName('l2')[0];
	if (lvl1.options[0].selected){
		lvl2.style.display = 'none';
	}else {
		lvl2.style.display = '';
	}
}


function loadLevel2CategoryList(){
	var lvl1 = document.getElementsByName('l1')[0];
	var lvl2 = document.getElementsByName('l2')[0];
	while (lvl2.length > 0){
        lvl2.remove(lvl2.length - 1);
    }
    var params  = '';
    if (lvl1.options[0].selected){                  // unselect all the rest if all is selected.
    	for (var i = 1; i < lvl1.options.length; i++) {
    		lvl1.options[i].selected = false;
    	}
    	return;
    } else {                                        // build params string based on currently selected options.
    	for (var i = 1; i < lvl1.options.length; i++) {
    		if(lvl1.options[i].selected)
				params = params + '&lvl1='+lvl1.options[i].value;
    	}
    }
	var data = 'type=lvl2' + params;
    var myAjax = new Ajax.Request('/servlet/finder',
        {method: 'get', parameters: data,  asynchronous: false}
    );
    var respXML = myAjax.transport.responseXML;
    var item = respXML.getElementsByTagName("list")[0];
    var nodes = item.getElementsByTagName("category");
    var opt = new Option("All", "", '', '');
    lvl2.options[0] = opt;
    for(var i=0; i < nodes.length;i++){
        var description = nodes[i].getElementsByTagName("label")[0].firstChild.data;
        var id = nodes[i].getElementsByTagName("id")[0].firstChild.data;
        var optionName = new Option(description, id, '', '');
        lvl2.options[i+1] = optionName;
    }
}

function loadLevel2List(level1, lvl1Name){
	var div = document.getElementById('secondLevelLink');
    while(div.hasChildNodes()){
		div.removeChild(div.firstChild);
	}
	var th = document.getElementById('secondlevelth');
	if(level1 == ''){
		document.getElementById('secondleveltable').style.display = 'none';
		th.firstChild.nodeValue = '';
		return;
	}
	th.firstChild.nodeValue = 'Second-Level Category';
	var data = 'type=lvl2&lvl1=' + level1;
    var myAjax = new Ajax.Request('/servlet/finder',
        {method: 'get', parameters: data,  asynchronous: false}
    );
    document.getElementById('secondleveltable').style.display = '';
    var respXML = myAjax.transport.responseXML;
    var item = respXML.getElementsByTagName("list")[0];
    var nodes = item.getElementsByTagName("category");

	for(var i=0; i < nodes.length;i++){
        var description = nodes[i].getElementsByTagName("label")[0].firstChild.data;
        var id = nodes[i].getElementsByTagName("id")[0].firstChild.data;
        var tempLink=document.createElement('a');
        tempLink.appendChild(document.createTextNode(description));
        tempLink.setAttribute('href','/find-premium-domains/search-results.jsp?l2='+id+'&category='+description);
        div.appendChild(tempLink);
    }
    var link = document.getElementById("alllink");
    link.href = '/find-premium-domains/search-results.jsp?l1='+level1+'&category='+lvl1Name;
 
}

// get array of elements of the same obj type with same class
function getElementsByClass(objArea, thisTag, thisClass) {
	if (objArea != "") {
		var obj = document.getElementById(objArea).getElementsByTagName(thisTag);
	} else {
		var obj = document.getElementsByTagName(thisTag);
	}
	var arrElements = new Array();
	for (i = 0; i < obj.length; i++) {
		if(obj[i].className == thisClass) {
			arrElements[arrElements.length] = obj[i]
		}
	}
	return arrElements;
}

// hide/show objects
function hideObj(obj) {
	obj = document.getElementById(obj);
	obj.style.display = "none";
}

function showObj(obj) {
	obj = document.getElementById(obj);
	obj.style.display = "block";
}

// show/hide text box beneath link
function changeStatus(objId) {
	var objLink1 = document.getElementById(objId + "Status1");
	var objLink2 = document.getElementById(objId + "Status2");
	var objLink3 = document.getElementById(objId + "Status3");
	hideObj(objId + "Link1");
	hideObj(objId + "Link2");
	hideObj(objId + "Link3");
	showObj(objId + "Box1");	
	showObj(objId + "Box2");
	showObj(objId + "Box3");
}
	// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
};




function removeChildren(container){
	if ( container.hasChildNodes() ){
		while ( container.childNodes.length >= 1 ){
       		container.removeChild( container.firstChild );       
   		} 
	}
}

// show/hide text box beneath link
function changeArticleStatus(objId) {
	var objLink = $(objId + "Status");
	if (objLink !== null) {		
		if (objLink.className == "rightArrow") {
			objLink.className = "downArrow";
			showObj(objId + "Box");
		} else {
			objLink.className = "rightArrow";
			hideObj(objId + "Box");
		}
	}
}

function pickSize(obj1) {

if (document.widgetSize.os0.value == 0) {
	$("360x250").show();
	$("300x250").hide();
	$("180x150").hide();
	$("160x420").hide();
	$("160x600").hide();
}

if (document.widgetSize.os0.value == 1) {
	$("360x250").hide();
	$("300x250").show();
	$("180x150").hide();
	$("160x420").hide();
	$("160x600").hide();
}

if (document.widgetSize.os0.value == 2) {
	$("360x250").hide();
	$("300x250").hide();
	$("180x150").show();
	$("160x420").hide();
	$("160x600").hide();
}

if (document.widgetSize.os0.value == 3) {
	$("360x250").hide();
	$("300x250").hide();
	$("180x150").hide();
	$("160x420").show();
	$("160x600").hide();
}

if (document.widgetSize.os0.value == 4) {
	$("360x250").hide();
	$("300x250").hide();
	$("180x150").hide();
	$("160x420").hide();
	$("160x600").show();
}

}