function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
var m_form="";
	var m_fldu="";
	var m_fldvt="";
	var m_fldvid="";
	var m_lvalue="";
	//url,function to exe,form name,field source,field to update,xmlsourcename,xmlsourceid,label value
	function xml_get(url,fcn,frm,fld,fldu,fldvt,fldvid,lvalue) {
	document[frm][fldu].options.length=1;
	document[frm][fldu].options[0].text=".... Please Wait ";
	if (fld.indexOf(",",fld) >-1) {
	 	url=url+'?frm='+frm+'&cfts='+new Date();
		var index=0;
		var hit_start=0;
		pid=fld;
		while (index != -1) {
			index = pid.indexOf(",", index + 1);
			index2=index;
			if (index==1) {index2=0;}
			if (hit_start==0) {hit_start=-1;}
			if (index == -1 ) {index2=pid.length;}
			listpartid=pid.substring(hit_start+1,index2);
			url=url+'&'+listpartid+'='+document[frm][listpartid][document[frm][listpartid].selectedIndex].value
			hit_start= index;
		}
	}
	else {
		url=url+'?frm='+frm+'&fld='+fld+'&fldv='+document[frm][fld][document[frm][fld].selectedIndex].value+'&cfts='+new Date();
	}
	m_form=frm;
	m_fldu=fldu;
	m_fldvt=fldvt;
	m_fldvid=fldvid;
	if (lvalue!= null) {
		m_lvalue=lvalue;
	}
	xmlhttp=null
	if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest()}
	else if (window.ActiveXObject) {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
	if (xmlhttp!=null){xmlhttp.onreadystatechange=eval(fcn);xmlhttp.open("GET",url,true);xmlhttp.send(null);}
	else{alert("Your browser does not support XMLHTTP.")}
}
function checkReadyState(obj){
  if(obj.readyState == 4){
    if(obj.status == 200){
      return true;
    }
    else{
      alert("Problem retrieving XML data");
    }
  }
}
function onResponse() 
{
  if(checkReadyState(xmlhttp))
  {
	 // code for IE
	if (window.ActiveXObject)
	  {
	  var response=new ActiveXObject("Microsoft.XMLDOM");
	  response.async="false";
	  response.loadXML(xmlhttp.responseText);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	var parser = new DOMParser();
	var response = parser.parseFromString(xmlhttp.responseText, "text/xml");
	  }
	x=response.getElementsByTagName("datarecord")
	document[m_form][m_fldu].options.length=(x.length+1);
	document[m_form][m_fldu].options[0].text="";
	document[m_form][m_fldu].options[0].value=0;
	if (m_lvalue.length > 0) {
		document[m_form][m_fldu].options[0].text=m_lvalue;
	}
	for (i=0;i<x.length;i++) {
	  {
      try
        {
		document[m_form][m_fldu].options[i+1].text=x[i].getElementsByTagName(m_fldvt)[0].firstChild.data.replace(/&amp;/,'&'); 
		document[m_form][m_fldu].options[i+1].value=x[i].getElementsByTagName(m_fldvid)[0].firstChild.data; 
		 }
      catch (er)
        {
        }
      }
	}
	if (x.length ==1) {
		//document[m_form][m_fldu].selectedIndex=0;
		document[m_form][m_fldu].selectedIndex=1;
		if (document[m_form][m_fldu].onchange) {document[m_form][m_fldu].onchange();}
	}
	
	if (m_lvalue.length > 0) {
		document[m_form][m_fldu].options[0].text=m_lvalue;
		document[m_form][m_fldu].selectedIndex=1;
		//document[m_form][m_fldu].style.display = 'inline';
	}
  } 
  else {
  	document[m_form][m_fldu].options[0].text=document[m_form][m_fldu].options[0].text+".";
  }
}
function school_func_country (tid) {
	select_box_clear(tid,'schoolid');
	if (document[tid].schooltypeid[document[tid].schooltypeid.selectedIndex].value > 0 && document[tid].schoolcountryid[document[tid].schoolcountryid.selectedIndex].value) {
		xml_get('/ajax/school/get_school_prov.cfm','onResponse',tid,'schooltypeid,schoolcountryid','schoolprovinceid','province','provinceid')
	}
}
function school_func_province (tid) {
	xml_get('/ajax/school/get_school_prov_school.cfm','onResponse',tid,'schooltypeid,schoolcountryid,schoolprovinceid','schoolid','schoolname','schoolid')
}

function func_country_change(tid,opt) {
	if (document.getElementById('countryid'+tid)[document.getElementById('countryid'+tid).selectedIndex].value <=2) {
		document.getElementById('province'+tid+'_id').style.display="block";
		document.getElementById('province'+tid+'_text').style.display="none";
		if (opt==null || (opt!= null && opt==1)) {
		xml_get('/ajax/checkout/province.cfm','onResponse','checkoutform','countryid'+tid,'provinceid'+tid,'province','provinceid')
		}
	}
	else {
		document.getElementById('province'+tid+'_id').style.display="none";
		document.getElementById('province'+tid+'_text').style.display="block";
	}
}
function checkout_addresstype_check(frm,id) {
	if (document[frm]['addresstypeid'+id][document[frm]['addresstypeid'+id].selectedIndex].value==2 || document[frm]['addresstypeid'+id][document[frm]['addresstypeid'+id].selectedIndex].value==3) {
		document.getElementById('company_fld'+id).style.display="block";
		if (document[frm]['addresstypeid'+id][document[frm]['addresstypeid'+id].selectedIndex].value==2) {
			document.getElementById('id_header_name'+id).innerHTML='Company Name';
		}
		else {
		document.getElementById('id_header_name'+id).innerHTML='Institution Name';
		}
	}
	else {
		document.getElementById('company_fld'+id).style.display="none";
	}
}
function select_box_clear(frm,selbox) {
	document[frm][selbox].options.length=0;
}
function select_box_selectvalue(frm,selbox,vld) {
	for (i=1; i <= document[frm][selbox].options.length; i++) {
		if (document[frm][selbox].options[i-1].value == vld) {
			document[frm][selbox].selectedIndex=i-1;
			i=10000;
		}
	}
}
function browse_by_comp () {
		if (document.form_header.bcompanyurl.options.length==1) {		
			xml_get('/ajax/header/bbcl.cfm','onResponse','form_header','bcompanyurl','bcompanyurl','companyname','companyurl','---Browse By Company---')
		}
	}
function browse_by_comp_nav() {
	if (document.form_header.bcompanyurl[document.form_header.bcompanyurl.selectedIndex].value != 0) {
		document.location=document.form_header.bcompanyurl[document.form_header.bcompanyurl.selectedIndex].value;
	}
}
function change_country(url,storeid) {

	if(storeid == 5)
	{
		window.location = "http://www.studica.com.br/";
	}
	else if (url.indexOf('?') > 0) {
		window.location=url+'&storeid='+storeid;
	}
	else {
		window.location=url+'?storeid='+storeid;
	}
	//alert('bye');
}
function removeemailstr() {
		if (document.emailsignupform.newsletter_email_signup.value=="--Email Address--") {
			document.emailsignupform.newsletter_email_signup.value=""
		}
	}
	function replaceemailstr(){
		if (document.emailsignupform.newsletter_email_signup.value=="") {
			document.emailsignupform.newsletter_email_signup.value="--Email Address--"
		}
	}
function cus_type_fct(frm,cid) {
		if (cid==1 || cid==4) {
			document.getElementById('cus_type_ev').style.display="block";
		}
		else {
			document.getElementById('cus_type_ev').style.display="none";
		}
		try
        {
		
		
		if (cid==2) {
			for (itest=1;itest<=2;itest++) {
				select_box_selectvalue(frm,'addresstypeid'+itest,3);
				checkout_addresstype_check(frm,itest);
			}
		}
		if (cid==6 || cid==5) {
			for (itest=1;itest<=2;itest++) {
				select_box_selectvalue(frm,'addresstypeid'+itest,2);
				checkout_addresstype_check(frm,itest);
			}
		}
		if (cid==3 ) {
			for (itest=1;itest<=2;itest++) {
				select_box_selectvalue(frm,'addresstypeid'+itest,1);
				checkout_addresstype_check(frm,itest);
			}
		}
		 }
      catch (er)
        {
        }
	}
function select_school_type(frm) {
		if (document[frm].schooltypeid[document[frm].schooltypeid.selectedIndex].value==1 || document[frm].schooltypeid[document[frm].schooltypeid.selectedIndex].value==2 || document[frm].schooltypeid[document[frm].schooltypeid.selectedIndex].value==3) {
			document.getElementById('school_filter_country').style.display="block";
		}
		else {
			document.getElementById('school_filter_country').style.display="none";
		}
	}
	function select_school_filter_country(frm) {
		xml_get('/ajax/school/get_school_prov.cfm','onResponse','checkoutform','schoolcountryid','schoolprovinceid','province','provinceid')
	}
