function Inint_AJAX() {
	try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
	try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
	alert("XMLHttpRequest not supported");
	return null;
}
//var xmlhttp =(window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
//var xmlhttp2 = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
var xmlhttp = Inint_AJAX();
var xmlhttp2 = Inint_AJAX();
function hidecontent(obj2hide){
	document.getElementById(obj2hide).innerHTML="";	
}
function loadcontent(url,loadto){
	var trv=document.getElementById(loadto)
	trv.innerHTML="<center><font color=\"#ADAFB2\" size=\"2\">Loading...</font></center>";
	xmlhttp.open("GET",url,true);	
	xmlhttp.onreadystatechange=function(){		
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			trv.innerHTML="";
			trv.innerHTML=xmlhttp.responseText;
		}	
	}
	xmlhttp.send(null);	
}
function loadcontent2(url,loadto,url2,loadto2){
	var trv=document.getElementById(loadto);
	var trv2=document.getElementById(loadto2);
	trv.innerHTML="<center><font color=\"#ADAFB2\" size=\"2\">Loading...</font></center>";
	trv2.innerHTML="<center><font color=\"#ADAFB2\" size=\"2\">Loading...</font></center>";
	xmlhttp.open("GET",url,true);	
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			trv.innerHTML="";
			trv.innerHTML=xmlhttp.responseText;
		}	
	}
	xmlhttp.send(null);	
	xmlhttp2.open("GET",url2,true);	
	xmlhttp2.onreadystatechange=function(){		
		if(xmlhttp2.readyState==4 && xmlhttp2.status==200){
			trv2.innerHTML="";
			trv2.innerHTML=xmlhttp2.responseText;
		}	
	}
	xmlhttp2.send(null);
}
// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}
function ShowAndHide(obj){
	if(document.getElementById(obj).style.display=='none'){
		document.getElementById(obj).style.display='inline';
	}else{
		document.getElementById(obj).style.display='none';
	}
}
function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.th)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {		
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
   		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
		   }
		}
		//return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter \" + \"country.");
		return false;
	}

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	//return true;		
}

function ChkRegister(frm){
	if(document.getElementById('name').value == ''){
		alert("Name is empty!");
		document.getElementById('name').focus();
		return false;		
	}
	if(document.getElementById('surname').value == ''){
		alert("SurName is empty!");
		document.getElementById('surname').focus();
		return false;		
	}
	if(document.getElementById('email').value == ''){
		alert("E-Mail field is empty!");
		document.getElementById('email').focus();
		return false;
	}else{
		if(emailCheck(document.getElementById('email').value) == false){
			document.getElementById('email').focus();
			return false;
		}
	}
	if(document.getElementById('subject').value == ''){
		alert("Name of Events / Seminars is empty!");
		document.getElementById('subject').focus();
		return false;		
	}
	if(document.getElementById(frm).use_fuji[0].checked == true && document.getElementById('product_name').value == ''){
		alert("Fuji Xerox Products is empty!");
		document.getElementById('product_name').focus();
		return false;		
	}
}