/* *******************************************************
Software: Web Wiz Forums
Info: http://www.webwizforums.com
Copyright: ©2001-2007 Web Wiz. All rights reserved
******************************************************* */

//function to change page from option list
function linkURL(URL) {
	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;
	return true;
}

//function to open pop up window
function winOpener(theURL, winName, scrollbars, resizable, width, height) {

	winFeatures = 'left=' + (screen.availWidth-10-width)/2 + ',top=' + (screen.availHeight-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar=0'
  	window.open(theURL, winName, winFeatures);
}

//Show drop down
function showDropDown(parentEle, dropDownEle, dropDownWidth, offSetRight){

	parentElement = document.getElementById(parentEle);
	dropDownElement = document.getElementById(dropDownEle)

	//position
	dropDownElement.style.left = (getOffsetLeft(parentElement) - offSetRight) + 'px';
	dropDownElement.style.top = (getOffsetTop(parentElement) + parentElement.offsetHeight + 3) + 'px';

	//width
	dropDownElement.style.width = dropDownWidth + 'px';

	//display
	hideDropDown();
	dropDownElement.style.visibility = 'visible';


	//Event Listener to hide drop down
	if(document.addEventListener){ // Mozilla, Netscape, Firefox
		document.addEventListener('mouseup', hideDropDown, false);
	} else { // IE
		document.onmouseup = hideDropDown;
	}
}

//Hide drop downs
function hideDropDown(){
	hide('div');
	hide('iframe');
	function hide(tag){
		var classElements = new Array();
		var els = document.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)dropDown(.*\)');

		for (i = 0, j = 0; i < elsLen; i++){
			if (pattern.test(els[i].className)){
				els[i].style.visibility='hidden';
				j++;
			}
		}
	}
}


//Top offset
function getOffsetTop(elm){
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

//Left offset
function getOffsetLeft(elm){
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

//AJAX
var xmlHttp;
var xmlHttpResponseID;

//create XMLHttpRequest object
function createXMLHttpRequest(){
	if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		if (! xmlHttp){
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
}

//XMLHttpRequest event handler
function XMLHttpResponse(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=='complete'){
		if (xmlHttp.status == 200){
			xmlHttpResponseID.innerHTML = xmlHttp.responseText;
//alert(xmlHttp.responseXML.Xml);
//encoderus(xmlHttp.responseText);
		}else {
			xmlHttpResponseID.innerHTML = '<strong>Îøèáêà ïîäêëþ÷åíèÿ ê ñåðâåðó</strong>';
		}

	}
}


var azbuka = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";

function recode(str) 
{
var len = str.length;
var ret;
for (ich=0; ich <= len-1; ich++) {
	ch = str.substr(ich,1);
	if (str.charCodeAt(ich) < 128) {
		ret+=ch;
	} else {
		idx = azbuka.indexOf(ch);
		if (idx >= 0 && idx < 64) {
			code = 1040 + idx;
			ret+="&amp;#" + code + ";";
		} else if (ch == "¨") {
			ret+="&amp;#1025;";
		} else if (ch == "¸") {
			ret+="&amp;#1105;";
		}
	}
}
return ret;
}


var koi2utf={
163:1105,
179:1025,
192:1102,
193:1072,
194:1073,
195:1094,
196:1076,
197:1077,
198:1092,
199:1075,
200:1093,
201:1080,
202:1081,
203:1082,
204:1083,
205:1084,
206:1085,
207:1086,
208:1087,
209:1103,
210:1088,
211:1089,
212:1090,
213:1091,
214:1078,
215:1074,
216:1100,
217:1099,
218:1079,
219:1096,
220:1101,
221:1097,
222:1095,
223:1098 
};

  function koi2unicode (str){
     if (str == null){ return null;}
     var result = "";
     var o_code = "";
     var i_code = "";
     for (var I=0; I < str.length; I++){
        i_code = str.charCodeAt(I);
                                   
        if (koi2utf[i_code] != null){
            o_code = koi2utf[i_code];
        } else if (i_code > 223 && koi2utf[i_code-32] != null){
            o_code = koi2utf[i_code-32]-32;
        } else {
            o_code = i_code;
        }
        result = result + String.fromCharCode(o_code);
     }

     return result;
  }

function win2unicode (str){
     if (str == null){ return null;}
     var result = "";
     var o_code = "";
     var i_code = "";
     for (var I=0; I < str.length; I++){
        i_code = str.charCodeAt(I);

        if (i_code == 184){
            o_code = 1105;
        } else if (i_code == 168){
            o_code = 1025;
        } else if (i_code > 191 && i_code < 256){
            o_code = i_code + 848;
        } else {
            o_code = i_code;
        }
        result = result + String.fromCharCode(o_code);
     }                                                
      
     return result;
}


function encoderus(EntryTXT) { 
  var text = "";    
  var Ucode; 
  var ExitValue;
//  var s;
  
  for (var i=0; i<EntryTXT.length; i++) { 
  
    s= EntryTXT.charAt(i);
    Ucode = EntryTXT.charCodeAt(i); 
alert(Ucode);    
   var Acode = Ucode; 

   if (Ucode > 1039 && Ucode < 1104){ 
//      Acode -= 848;
      ExitValue = String.fromCharCode(Acode);          
    }
    else   
    if (Ucode == 1025) {
 //     Acode = 168; 
      ExitValue = String.fromCharCode(Acode);          
//      ExitValue = "%" + Acode.toString(16);          
    }
    else  
    if (Ucode == 1105){
 //     Acode = 184;
       ExitValue = String.fromCharCode(Acode);          
//     ExitValue = "%" + Acode.toString(16);          
    } 
/*    else
    if (Ucode == 32){
      Acode = 32;
      ExitValue = "%" + Acode.toString(16);          
    } 
    else if(Ucode == 10){
        Acode=10;
        ExitValue = "%0A";
    }else
     ExitValue=s;          
 */    
//alert(Acode) 
  text = text + ExitValue; 
  }      

//alert(String.fromCharCode(1100));
    return text; 
}

function encoderus1(EntryTXT) { 
  var text = "";    
  var Ucode; 
  var ExitValue;
  var s;
  
  for (var i=0; i<EntryTXT.length; i++) { 
  
    s= EntryTXT.charAt(i);
    Ucode = s.charCodeAt(0); 
    var Acode = Ucode; 
    if (Ucode > 1039 && Ucode < 1104){ 
      Acode -= 848;
      ExitValue = "%" + Acode.toString(16);          
    }
    else   
    if (Ucode == 1025) {
      Acode = 168; 
      ExitValue = "%" + Acode.toString(16);          
    }
    else  
    if (Ucode == 1105){
      Acode = 184;
      ExitValue = "%" + Acode.toString(16);          
    } 
    else
    if (Ucode == 32){
      Acode = 32;
      ExitValue = "%" + Acode.toString(16);          
    } 
    else if(Ucode == 10){
        Acode=10;
        ExitValue = "%0A";
    }else
     ExitValue=s;          
     
   text = text + ExitValue; 

  }      
    return text; 
}
/*function DecodeStr(ResponseBody){
 var oRS; 
 oRS = new ActiveXObject('ADODB.Recordset');
 oRS.Fields.Append("ru",200,100000);
 oRS.Open();
 oRS.AddNew();
alert('aaa');
/* oRS(0).AppendChunk ResponseBody

 DecodeStr=oRS(0)

 Set oRS = Nothing
 return ResponseBody;
}

*/


//Get AJAX data
function getAjaxData(url, elementID){
	xmlHttpResponseID = document.getElementById(elementID);
	xmlHttpResponseID.innerHTML = '<strong>Çàãðóçêà...</strong>';
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = XMLHttpResponse;
	xmlHttp.open("GET", url, true);

//xmlDom.loadXML("<?xml version=\"1.0\" encoding=\"windows-1251\"?><root></root>"); 

	xmlHttp.setRequestHeader("Accept-Language", "ru");
	xmlHttp.setRequestHeader("Accept-Charset", "windows-1251;q=1, koi8-r;q=0.6");
	xmlHttp.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Connection", "Keep-Alive");

	xmlHttp.send(null);
}
