//////////////////////////////////////////////////////////////////////
// !Detect Form Changes                                             //
//////////////////////////////////////////////////////////////////////
function setCookie(name, value, expires, path, domain, secure){
    document.cookie = name 
			   + "=" + escape(value)
               + ((expires) ? "; expires=" 
			   + expires.toGMTString() : "") 
			   + ((path) ? "; path=/" + path : "")
               + ((domain) ? "; domain=" + domain : "")
			   + ((secure) ? "; secure" : "");
}
function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == - 1){
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else{
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == - 1){
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function stripHTML(oldString) {
   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
        if(!inTag) newString += oldString.charAt(i);
   }
   return newString;
}
function checkLogin(MemberLogin){
		var tmpInfo      = getCookie('nephp5x_user');
        if(tmpInfo!=null){
            AccountInfo = tmpInfo.split("|");
    		if(AccountInfo[2]!=null && typeof(MemberLogin)!='undefined'){
    			MemberLogin.innerHTML="<span class='logged-msg'>Welcome <b>"+AccountInfo[0]+"</b> (<a class='link' href='"+nephp_base+"/login.php?no_login_gui=1'>logout</a>),  you are belonged to <b>'"+AccountInfo[1]+"'</b> group.</span>";
    		}
        }
}
function SearchForm(fvar){
	var objfvar = fvar;
	var strTmp  = '{';
	var i,tmp;
    
    if(fvar.qstring.value==''){
        alert("You must enter a keyword");
        return;
    }
	for(i=1; i<=fvar.ftotal.value; i++){
		eval("tmp=objfvar.var"+i+";");
		if(tmp && (tmp.checked || (tmp.type!='checkbox' && tmp.value!=''))){
        	strTmp+=tmp.value+'='+escape(fvar.qstring.value)+'|';
		}
	}
	if(fvar.extras && fvar.extras.value){
    	strTmp+=fvar.extras.value;
	}
	strTmp+='}';
	fvar.keywords.value = strTmp;
    fvar.submit();
}
function popup(url, name, height, width, scroll, resize){
    if (name == 'ImgPreview'){
        url     = url_root + '/index.php?m=common&pm=img_preview&url=' + escape(url);
        height  = parseInt(height) + 34;
        width   = parseInt(width) + 29;
    }
    if (scroll == '')	scroll = 'no';
    if (resize == '')	scroll = 'no';
    if (width > screen.width) width = screen.width;
    if (height > screen.height) height = screen.height;
    var winl = (screen.width) ? (screen.width - width) / 2 : 0;
    var wint = (screen.height) ? (screen.height - height) / 2 : 0;
    window.open(url,
                name,
                'width=' + width                     
			+ 	',height=' + height
            + ',menubar=no,scrollbars=' + scroll     
			+ ',toolbar=no,location=no,directories=no,resizable=' + resize 
			+ ',top='    + wint
            + ',left='   + winl
    );
}
function getObject(id){
	return (document.all) ? document.all[id] : document.getElementById(id);
}

// Ajax Tools
function ajax_init(){
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}
function encode(input) {
	return escape(input);
}
function decode(input) {
	return unescape(input.replace(/\+/g,  " "));
}
function RemoteContents(url,method,param,blnCheck){
    var buffer="",tmpKey,blnSendType;
    var http = ajax_init();
    http.onreadystatechange=function() {
        if (http.readyState==4) {
            document.writeln(http.responseText);
        }
    }
    if(method.toLowerCase() == 'post'){
        if(param){
            for(tmpKey in param){
                buffer += "&"+ tmpKey + "=" + param[tmpKey];
            }
        }
        http.open(method, url, true);
        http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        http.send(buffer);
    } else {
        if(param){
            for(tmpKey in param){
                buffer += "&"+ tmpKey + "=" + encode(param[tmpKey]);
            }
        }          
        http.open(method, url+"?"+buffer, true);
        http.send(null);
    }
    return contents;
}
// !Ajax Tools

function jump(url, vconfirm, sREF, def, felement,ignore){
    if (url == '') return;
    if (sREF && ignore!=1){
        url += "&url=" + sREF;
    }
    var MsgTxt = '';
    if (felement){
        eval("var actv = document." + active_form + ";");
        //if (actv && form_changes(actv)){
            if (! submit_confirm('You should save the changes. Proceed anyway?')){
                return;
            }
        //}
    }
    if (vconfirm != null && vconfirm != ''){
        if (vconfirm == 1) MsgTxt = "Are you sure you want to continue?";
        else MsgTxt = vconfirm;
        if (submit_confirm(MsgTxt)){
            if (url != ''){
                if (url.indexOf('#popup') == - 1){
                    window.location = url;
                }
                else{
                    popup(url, 'ActionWindow', 200, 400, 'yes', 'no');
                }
            }
        }
    }
    else{
        if (url != '') window.location.replace(url);
    }
}
function submit_confirm(text){
    if (ie4){
        if (confirm(text)){
            return true;
        }
    }
    else{
        if (window.confirm(text)){
            return true;
        }
    }
    return false;
}
function frm_confirm(e, text){
    if (submit_confirm(text)){
        e.submit();
    }
}
function val_retrieve(text, default_val){
    return prompt(text, default_val);
}
function thumb_write(input){
	var isThumb = parseInt(getCookie('nephp5_thumb'));
	if(isThumb){
		document.write("<td width='100' class='ThumbList'>\n");
		if(input!=''){
			document.write("<div class='SearchImgThumb' style=\"background: #c0c0c0 url('"+input+"') no-repeat;\">\n");
            document.write("&nbsp;</div>");
		}
		document.write("</td>");
	}
}
function thumb_toggle(){
	var intThumb = parseInt(getCookie('nephp5_thumb'));
	if(intThumb) {
		setCookie('nephp5_thumb','0');
	} else {
		setCookie('nephp5_thumb','1');
	}
	window.location.reload();
}
