// basics
var ie=document.all;
var nn6=document.getElementById&&!document.all;

function CXmlHttp(method,target,callback,param){
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	
	// set the callback function
	
	if (xmlhttp){
		xmlhttp.open(method,target+"&rand="+Math.random(),true);
		if (method=='post' || method=='POST'){
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  		xmlhttp.setRequestHeader("Content-length", param.length);
  	} else xmlhttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
		xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4)callback(xmlhttp.responseText);
			}
			xmlhttp.send(param);
	}
}


function postAjaxForm(source,target){
		poststr=parseForm(source);
		new CXmlHttp("POST",target,function (result){d(source).innerHTML=result;},poststr);
}

function parseForm(formname){
	//"&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
	var poststr="";
	var myform=d(formname);
	if (!myform.elements){
		newform=document.createElement('FORM');
		newform.style.display='none';
		newform.innerHTML=myform.innerHTML;
		myform=newform;
	}
	for(i=0;i<myform.elements.length;i++){
		var tempelement=myform.elements[i];
		if(tempelement.name)poststr+=tempelement.name+"="+encodeURI( tempelement.value )+"&";	
	}
	return poststr;
}

function getW(obj){
   return obj.offsetWidth;
}

function getH(obj){
   return obj.offsetHeight;
}

function getX(obj){
   return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}

function getY(obj) {
   return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

function d(obj) {
	if (!document.getElementById(obj)) {
		return false;
	}
	return document.getElementById(obj);
}

function check(_me_out) {
	d("check").innerHTML=_me_out;
}
function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function readCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}



function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
