/******************************
/******************************
* @author  Paulo Delgado <pdelgado@aismedia.com>
*****************************/
var superIndex=2;

function initXMLHTTP() {
var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false;
 }
}

	
	return xmlhttp;
}


function toggleTable(el)  {
	minus = new Image();
	minus.src= "/assets/Andrea05/en/All/minus.gif";
	
	plus = new Image();
	plus.src="/assets/Andrea05/en/All/plus.gif";
	
	var myelement = document.getElementById(el);
	var nameelement = document.getElementById(el + "-highlight");
	var myimg = document.getElementById(el + "-img");
	
	if( !myelement.style.display || myelement.style.display == "none" )  {
		myimg = minus;
		if (navigator.appName == "Netscape") {
			myelement.style.display = "table-cell";
		} else {
			myelement.style.display = "inline";
		}
		nameelement.style.fontWeight = "bold";
	
	
	} else {
	myimg= plus;
	myelement.style.display = "none";
	nameelement.style.fontWeight = "normal";
	
	if (navigator.appName == "Netscape")  {
	
	} else {
	document.getElementById('footer').style.position = 'absolute';
	}
	
	}
}

function updatePricing() {
	obj = document.getElementById('pricing_select');
	var num = obj.value;
	obj2 = document.getElementById('pricing_info').innerHTML = document.getElementById('pricing_info_'+num).innerHTML;
}


function toggleDivVis(el)  {
	var myelement = document.getElementById(el);
	var nameelement = document.getElementById(el + "-highlight");
	var myimg = document.getElementById(el + "-img");
	if( !myelement.style.display || myelement.style.display == "none" )  {
		if (navigator.appName == "Netscape") {
			myelement.style.display = "block";
		} else {
			myelement.style.display = "block";
		}
		nameelement.style.fontWeight = "bold";
		myelement.style.fontWeight = "normal";
		myimg.src= "/assets/Andrea05/en/All/minus.gif";
	} else {
		myelement.style.display = "none";
		nameelement.style.fontWeight = "normal";
		myimg.src= "/assets/Andrea05/en/All/plus.gif";
	}
}


function WAtrimIt(theString,leaveLeft,leaveRight)  {
  if (!leaveLeft)  {
    while (theString.charAt(0) == " ")
      theString = theString.substring(1);
  }
  if (!leaveRight)  {
    while (theString.charAt(theString.length-1) == " ")
      theString = theString.substring(0,theString.length-1);
  }
  return theString;
}

function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
  if (document.WAFV_Error)  {
	  document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
	document.WAFV_Focus = focusIt;
  }

  if (stopIt == 1)  {
	document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
	formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
	formElement.WAFV_Stop = true;
	formElement.WAFV_Continue = false;
  }
}

function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType)  {
  var isValid = true;
  if (!document.WAFV_Stop && !formElement.WAFV_Stop)  {
    if (inputType == "select")  {
	  if (formElement.selectedIndex == -1)  {
	    isValid = false;
	  }
	  else if (!formElement.options[formElement.selectedIndex].value || formElement.options[formElement.selectedIndex].value == "") {
	    isValid = false;
	  }
	}
	else if (inputType == "checkbox")  {
	  if (!formElement.checked)
	    isValid = false;
	}
	else if (inputType == "radio")  {
	  isValid = false;
	  if (formElement.checked)
	    isValid = true;
	}
	else if (inputType == "radiogroup")  {
	  isValid = false;
	  for (var x=0; x<formElement.length; x++)  {
	    if (formElement[x].checked && formElement[x].value!="")  {
		  isValid = true;
		  break;
		}
	  }
	  formElement = formElement[0];
	}
	else  {
	  var value = formElement.value;
	  if (trimWhite)  {
	    value = WAtrimIt(value);
	  }
	  if (value == "")  {
	    isValid = false;
	  }
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  { 
  if (!document.WAFV_StopAlert)  { 
	  document.WAFV_StopAlert = true;
	  if (document.WAFV_InvalidArray)  {  
	    document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
	    if (errorHead!="")
		  errorMsg = errorHead + "\n" + errorMsg;
		if (errorFoot!="")
		  errorMsg += "\n" + errorFoot;
		document.MM_returnValue = false;
		if (document.WAFV_Error!="")
		  alert(errorMsg.replace(/&quot;/g,'"'));
		else if (submitForm)
		  submitForm.submit();
	    if (setFocus && document.WAFV_Focus)  {
		  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
	      document.WAFV_InvalidArray[x].WAFV_Stop = false;
	    }
	  }
	  else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
	    if (submitForm)  {
	      submitForm.submit();
	    }
	    document.MM_returnValue = true;
	  }
      document.WAFV_Focus = false;
	  document.WAFV_Error = false;
	  document.WAFV_InvalidArray = false;
  }
}

function WA_isCreditCard(st) {
  if (st == 0)
    return (false);

  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

}

function WAValidateCC(formElement,value,errorMsg,format,allow,focusIt,stopIt,required)  {
  var isValid = true;
  var accepted = "\r\n\t.- ";
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var stripVal = "";
	for (var x=0; x<value.length; x++)  {
	  if (value.charCodeAt(x)>=48 && value.charCodeAt(x)<=57)
	    stripVal += value.charAt(x);
	  else if (accepted.indexOf(value.charAt(x))<0)  {
	    isValid = false;
	  }
	}
	if (isValid)  {
	  if (allow!="")  {
	    isValid = false;
	    allow = allow.split(":");
		for (var y=0; y<allow.length-1 && !isValid; y++)  {
		  if (stripVal.indexOf(allow[y])==0)
		    isValid = true;
		}
	  }
	}
	if (isValid)  {
	  isValid = WA_isCreditCard(stripVal);
	}
	if (isValid && format!="")  {
	  var newFormat = "";
	  while (format!="")  {
	    if (format.charAt(0) == "x") {
		  newFormat += stripVal.charAt(0);
		  stripVal = stripVal.substring(1);
		}
		else  {
		  newFormat += format.charAt(0);
		}
		format = format.substring(1);
	  }
	  formElement.value = newFormat;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAValidateAN(formElement,value,errorMsg,allowUpper,allowLower,allowNumbers,allowSpace,extraChars,focusIt,stopIt,required)  {
  var isValid = true;
  extraChars = extraChars.replace(/&quot;/g,'"');
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) || formElement.WAFV_Continue)  {
    for (var x=0; x<value.length; x++)  {
	  var charGood = false;
	  var nextChar = value.charAt(x);
	  var charCode = value.charCodeAt(x);
	  if (allowLower)  {
	    if (charCode >= 97 && charCode <= 122)  {
		  charGood = true;
		}
	  }
	  if (allowUpper)  {
	    if (charCode >= 65 && charCode <= 90)  {
		  charGood = true;
		}
	  }
	  if (allowNumbers)  {
	    if (charCode >= 48 && charCode <= 57)  {
		  charGood = true;
		}
	  }
	  if (allowSpace)  {
	    if (nextChar == " ")  {
		  charGood = true;
		}
	  }
	  if (extraChars)  {
	    if (unescape(extraChars).indexOf(nextChar) >= 0)  {
		  charGood = true;
		}
	  }
	  if (!charGood)  {
	    isValid = false;
		x = value.length;
	  }
	}
	if (required && value=="")
	  isValid = false;
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function openWin(wName, wWidth, wHeight, wResize) {
	features = 'scrollbars=1,status=1,resizable=' + ((wResize) ? 1 : 0) + ((wWidth) ? ',width=' + wWidth : '') + ((wHeight) ? ',height=' + wHeight : '');
	popWin = window.open('', wName, features);
	if(popWin.focus) { 
		popWin.focus(); 
	}
	return true;
}

function verifyDomain() {
	document.getElementById('domain_check_button').disabled = true;
	document.getElementById('domain_check_button').src = "/assets/Andrea05/en/" + theme + "/all/buttons/" + buttonSet + "b/querying.gif";
	domain = document.getElementById('domain').value;
	myDiv = document.getElementById('domain_results');
	myDiv.style.display = 'block'
	myDiv.innerHTML = "Please wait...";
	xmlhttp = initXMLHTTP();
	xmlhttp.open("GET","/assets/whois/?domain=" + domain , true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			myXml = xmlhttp.responseXML;
			errors = myXml.getElementsByTagName('error');
			if(errors.length > 0) {
				myDiv.innerHTML = '<div class="error">' + errors[0].firstChild.data + '</div>';
				document.getElementById('domain_check_button').disabled = false;
				document.getElementById('domain_check_button').value = "Check Again";
			} else {
				domains = myXml.getElementsByTagName('domain');
				rehtml = '<table width="100%">';
				allow_form = false;
				for(i = 0 ; i < domains.length ; i++) {
					name = domains[i].getElementsByTagName('name')[0].firstChild.data;
					response_code = domains[i].getElementsByTagName('response_code')[0].firstChild.data;
					if(response_code == '210') {
						// available
						rehtml += '<tr><td><input type="checkbox" name="domains[]" checked value="'+ name + '"></td><td class="domain_name">' + name + '</td><td style="color: green;">Available!</td></tr>';
						allow_form = true;
					} else {
						// taken
						rehtml += '<tr><td><input type="checkbox" name="" value="" disabled></td><td class="domain_name">' + name + '</td><td style="color: red;">Taken</td></tr>';
					}
					
				}
				if(allow_form) {
					rehtml += '<tr><td colspan="3"><input type="image" src="/assets/Andrea05/en/' + theme + '/all/buttons/' +buttonSet + 'b/register_now.gif" value="Purchase Selected Domains"></td></tr>';
					rehtml += "</table>";
				} else {
					rehtml += "</table>";
				}
				
				myDiv.innerHTML = rehtml;
				document.getElementById('domain_check_button').disabled = false;
				document.getElementById('domain_check_button').src = "/assets/Andrea05/en/" + theme + "/all/buttons/" + buttonSet  + "b/check_again.gif";
			}
		}
	}
	xmlhttp.send(null);
	return false;
}

function domainsOnly() {
	document.getElementById('order_domains_only_fieldset').style.display = 'block';
	document.getElementById('payment_info_fieldset').style.display = 'block';
	document.getElementById('domains_only_button').style.display = 'none';
	document.getElementById('buy_hosting_too').value = "I changed my mind, I want a hosting plan too!";
}

function toggleHostingPlans() {
	check = document.getElementById('no_hosting_checkbox');
	hostingPlan = document.getElementById('hostingPlan');
	if(check.checked) {
		hostingPlan.disabled = true;
	} else {
		hostingPlan.disabled = false;
	}
}


function startzoom () {
	if (flag_zoom) return;
	var flag_zoom = false;
	
	
	
	
	
	Zoom01 = new BigLayer('Zoom01');
	Zoom01.Create(0,0,475,342,false);
	Zoom01.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/shipping_formula.gif')
	Zoom01.SetClipAni('ro');
	Zoom01.Write();


	Zoom02 = new BigLayer('Zoom02');
	Zoom02.Create(0,0,475,351,false);
	Zoom02.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/automated_tax_calculation.gif')
	Zoom02.SetClipAni('ro');
	Zoom02.Write();



	Zoom03 = new BigLayer('Zoom03');
	Zoom03.Create(0,0,422,522,false);
	Zoom03.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/cobranded.gif')
	Zoom03.SetClipAni('ro');
	Zoom03.Write();



	Zoom04 = new BigLayer('Zoom04');
	Zoom04.Create(0,0,500,438,false);
	Zoom04.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/search.gif')
	Zoom04.SetClipAni('ro');
	Zoom04.Write();



	Zoom05 = new BigLayer('Zoom05');
	Zoom05.Create(0,0,386,351,false);
	Zoom05.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/wishlist.gif')
	Zoom05.SetClipAni('ro');
	Zoom05.Write();

	Zoom06 = new BigLayer('Zoom06');
	Zoom06.Create(0,0,500,438,false);
	Zoom06.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/product_discount.gif')
	Zoom06.SetClipAni('ro');
	Zoom06.Write();
			
	Zoom07 = new BigLayer('Zoom07');
	Zoom07.Create(0,0,500,438,false);
	Zoom07.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/options_and_variances.gif')
	Zoom07.SetClipAni('ro');
	Zoom07.Write();
	
	
	Zoom08 = new BigLayer('Zoom08');
	Zoom08.Create(0,0,389,351,false);
	Zoom08.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/product_comparison.gif')
	Zoom08.SetClipAni('ro');
	Zoom08.Write();
			
			
	
	Zoom09 = new BigLayer('Zoom09');
	Zoom09.Create(0,0,475,343,false);
	Zoom09.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/product_rating.gif')
	Zoom09.SetClipAni('ro');
	Zoom09.Write();
			
	Zoom10 = new BigLayer('Zoom10');
	Zoom10.Create(getX(),getY(), 475,456,false);
	Zoom10.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/online_store_interface.gif')
	Zoom10.SetClipAni('ro');
	Zoom10.Write();
	
	Zoom11 = new BigLayer('Zoom11');
	Zoom11.Create(0,0,500,400,false);
	Zoom11.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/traffic_stats.gif')
	Zoom11.SetClipAni('ro');
	Zoom11.Write();

	Zoom12 = new BigLayer('Zoom12');
	Zoom12.Create(0,0,500,400,false);
	Zoom12.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/top_referring_sites.gif')
	Zoom12.SetClipAni('ro');
	Zoom12.Write();

	Zoom13 = new BigLayer('Zoom13');
	Zoom13.Create(0,0,500,400,false);
	Zoom13.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/page_view_count.gif')
	Zoom13.SetClipAni('ro');
	Zoom13.Write();

	Zoom14 = new BigLayer('Zoom14');
	Zoom14.Create(0,0,500,438,false);
	Zoom14.InsertImage('/assets/Andrea05/en/All/images/excerpo_zoom/search_topics.gif')
	Zoom14.SetClipAni('ro');
	Zoom14.Write();
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s


var posx = 0;
var posy = 0;


function getMouseXY(e)
{
	
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.documentElement.scrollLeft;
		posy =  e.clientY + document.documentElement.scrollTop;
	}
	//document.title = posx + " - " + posy;
}

function getX() {
	return posx;
}

function getY() {
	return posy;
}

function displayEnlarged(ZoomLayer) {
	y = getY();
	x = getX();
	ZoomLayer.style.top = y + "px";
	w = ZoomLayer.style.width;
	atmp = w.substring(0, w.indexOf('px'));
	atmp = x - atmp;
	ZoomLayer.style.left = atmp + "px";
	ZoomLayer.ClipAni.Open();
}


function verifyReportUserPass() {
	u = document.reportForm.name.value;
	p = document.reportForm.pwd.value;
	
	if(p == '10mistakesreport') {
		window.open("/assets/Andrea05/en/All/10mistakereport/10mistakes_report.pdf" , '10MistakesReport' );
		return false;
	} else {
		alert("Wrong email and/or password");
		return false;
	}
}

function checkPlan(form_id) {
	if(!document.getElementById('no_hosting_checkbox').checked && document.getElementById('hostingPlan').selectedIndex == 0) {
		alert('Please select a hosting plan or indicate that you do not want a hosting plan.');
		document.MM_returnValue = false;
	}
}

var forTheTimeout;

function interruptTheTimeout() {
	clearTimeout(forTheTimeout);
}

function restoreTheTimeout() {
	var theLink = document.getElementById(this.getAttribute('name') + "_dropdown");
	if(!theLink) {
		//alert('oops - ' + this.getAttribute('name'));
	} else {
		theLink.onmouseout = hideDropDown;
	}
}

function showDropDown() {
	//alert(this.name);
	var menu = document.getElementById(this.name + "_dropdown");
	if(!menu) {
		//alert('Invalid Link');
	} else {
		menu.style.display = 'block';
		menu.onmouseover = interruptTheTimeout;
		menu.onmouseout = restoreTheTimeout;
	}
}

function hideDropDown() {
	var menu = document.getElementById(this.name + "_dropdown");
	forTheTimeout = setTimeout('reallyHideTheDropDown("' + this.name + '_dropdown");', 500);
}

function reallyHideTheDropDown(elem) {
	var menu = document.getElementById(elem);
	if(!menu) {
		//alert('Invalid Link');
	} else {
		menu.style.display = 'none';
	}	 
}

function setupMenus() {
	var myLinks = document.getElementsByTagName('a');
	for(i=0; i< myLinks.length ; i++) {
		if(myLinks[i].getAttribute('rel') == 'dropdown') {
			myLinks[i].onmouseover= showDropDown;
			myLinks[i].onmouseout = hideDropDown;
		}
	}
}

window.onload = setupMenus;


function checkAvailability(u_user) {
	var username = document.getElementById(u_user).value;
	if(username.length == 0) {
		alert('Please provide a username');
		document.getElementById('submit_button').disabled = true;
		return false;
	}
	xmlhttp = initXMLHTTP();
	xmlhttp.open("GET","/assets/whois/excerpomail/index.php?username=" + username , true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			myXml = xmlhttp.responseXML;
			errors = myXml.getElementsByTagName('error');
			if(errors.length > 0) {
				alert(errors[0].firstChild.data);
				document.getElementById('submit_button').disabled = true;
			} else {
				alert('This username is available');
				document.getElementById('submit_button').disabled = false;
				document.getElementById('submit_button').value = "Continue";
			}
		}
	}
	xmlhttp.send(null);
	return false;	
}

/**
* Form Validation function
*/
function verifyForm(form_id) {
        var myForm = document.getElementById(form_id);
        var errorMessage = '';
        var logMessage = "";
        var inputs = myForm.getElementsByTagName('input');
        var selects = myForm.getElementsByTagName('select');
        var idx = 0;
        logMessage += "Found " + inputs.length + " inputs\n";
        logMessage += "Found " + selects.length + " selects\n";
        for(idx=0; idx<inputs.length ; idx++) {
                if(inputs[idx].getAttribute('required') == 'required') {
                        logMessage += "found a required field: " + idx + " with value = " + inputs[idx].value  + "\n";
                        
                        if(inputs[idx].getAttribute('type') == 'checkbox') {
                        	if( !inputs[idx].checked) {
	                                var myName = inputs[idx]['name'];
	                                myName = myName.replace(/_/g, ' ');
	                                errorMessage += "The field '" + myName + "' must be checked.\n";
	                        }
                        }
                        
                        if( ( inputs[idx].getAttribute('type') == '' || inputs[idx].getAttribute('type') == 'text' ) && inputs[idx].value.length == 0) {
                                var myName = inputs[idx]['name'];
                                myName = myName.replace(/_/g, ' ');
                                errorMessage += "The field '" + myName + "' must not be empty.\n";
                        }
                }
                if(inputs[idx].getAttribute('required') == 'requiredemail') {
                        logMessage += "found a required field: " + idx + " with value = " + inputs[idx].value  + "\n";
                        if(inputs[idx].value.length == 0 || inputs[idx].value.indexOf('@') == -1) {
                                var myName = inputs[idx]['name'];
                                myName = myName.replace(/_/g, ' ');
                                errorMessage += "The field '" + myName + "' must not be empty or must contain a valid email address.\n";
                        }
                }
        }



        for(idx=0; idx<selects.length ; idx++) {
                if(selects[idx].getAttribute('required') == 'required') {
                        logMessage += "found a required field: " + idx + " with value = " + selects[idx].selectedIndex + "\n";
                        if(selects[idx].selectedIndex == 0) {
                                var myName = selects[idx]['name'];
                                myName = myName.replace(/_/g, ' ');
                                errorMessage += "You must choose an option from the '" + myName + "' drop-down menu.\n";
                        }
                }
        }

        if(errorMessage !='') {
                alert("The following errors were found:\n" + errorMessage);
                return false;
        } else {
                //alert(logMessage + "\n\nErrormessage: " + errorMessage);
                return true;
        }
}
function showLanguageChoices(e) {
	var choices = document.getElementById('language_choices');
	var adjustment = 0;
	try {
		adjustment += document.body.scrollTop;
		adjustment += document.documentElement.scrollTop;
	} catch (e) {}
	
	choices.style.left = (e.clientX -185) + 'px';
	choices.style.top = (e.clientY + adjustment - 70) + 'px';
	choices.style.display = 'block';
}
