/* WEEBO : CONTENT MADE EASY  */
/* -------------------------------------------------------------------------------------------------- */
/* Original development began in 2001, where a need came about to develop a content management system */
/* that catered for business and not only graphic designers. Weebo has come a long way and this new   */
/* content management system was derived to cater for the small, medium and large enterprise websites */
/* This code is the intellectual property of Gilbert Martin II, anyone attempting to copy, alter or   */
/* modify this code is committing patent fraud. Beyond this you are a miserable human being if you*/
/* are trying to copy somebody else/*s work, because you are not good enough to do your own.  */
/* -------------------------------------------------------------------------------------------------- */
/* Copyright (C) 2000 - 2020 . Gilbert Martin II (www.gilbertmartin.co.za) . All Rights Reserved  */
/* Visit www.gilbertmartin.co.za or www.weebo.co.za for more information regarding this development   */
/* -------------------------------------------------------------------------------------------------- */

/* EMAIL VALIDATOR */
function isEmail (str)
{
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("You have entered an incorrect Email Address.")
return false
}
if (str.indexOf(" ")!=-1){
alert("You have entered an incorrect Email Address.")
return false
}
return true
}

/* CONNECTOR */
var DataX;
function XHConn()
{
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone)
{
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET")
{
xmlhttp.open(sMethod, sURL+sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", sVars.length);
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp);
}};
if (DataX=='') {xmlhttp.send(sURL+"&data= ");}
else {xmlhttp.send(sURL+"&data=" + DataX);}
}
catch(z) { return false; }
return true;
};
return this;
}
var doAJAXUpdate = function (PageURL, ReqType, PostStr, FunctionName) {
var myConn = new XHConn();
if (myConn){
myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);
} 
else {
alert("You need to use the latest version of Internet Explorer, Firefox or Chrome for Weebo to work"); 
}
}

/* AJAX REQUEST */
var doAJAXRequest = function (PageURL, ReqType, PostStr, FunctionName) {
var myConn = new XHConn();
if (myConn){
myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);
} 
else {
alert("You need to use the latest version of Internet Explorer, Firefox or Chrome for Weebo to work"); 
}
}

/* AJAX UPDATE */
var fieldXS = "";
var doUpdate = function (idX,fieldX,tableX,dbX) {
var PostStr = "";
var Data = document.getElementById(fieldX).value;
if (fieldX.indexOf('emailaddress')!=-1)
{
if (isEmail(Data) == false) {return false;}
}
if (fieldX != 'content') 
{
Data = Data.replace(new RegExp( "\\r", "g" ),"~CR~");
Data = Data.replace(new RegExp( "\\n", "g" ),"~LF~");
}
Data = encodeURIComponent(Data);
DataX = Data;
document.getElementById("ajaxresponse"+fieldX).innerHTML='<img src="/change/images/loading_data.gif" width="16px" hspace="5">';
fieldXS = fieldX;
doAJAXUpdate('do_update.asp?id=' + idX + '&field=' + fieldX + '&table=' + tableX + '&db=' + dbX, 'POST', '', showMessageResponse);
}
var showMessageResponse = function (oXML) { 
var timer = null;
var response = oXML.responseText;
if (response = 'Y') {
document.getElementById("ajaxresponse"+fieldXS).innerHTML = '<img src="/change/images/check.png" hspace="5">';
clearTimeout(timer);
timer=setTimeout("clearDIV()",500)
}};

var oldHTML
var webX
var fieldX

/* FOLDER CREATE AJAX */
function doCreate(fieldname,groupname,ftpname,webname)
{
var fieldvalue = document.getElementById(fieldname).value;
var pidx = document.getElementById("id").value;
var webstr = "http://folders.netdata.co.za/websvc_createfolderx.asp?usnx=sysnxpx&pswx=neutrino&grpx=" + groupname + "&ftpx=" + ftpname + "&webx=" + webname + "&ftcx=" + fieldvalue + "&pidx=" + pidx
oldHTML = document.getElementById("creatingFolderX").innerHTML;
document.getElementById("creatingFolderX").innerHTML='<img src="/change/images/loading_data.gif" width="16" hspace="5">';
doAJAXRequest(webstr, 'POST', '', createResult);
webX = webname
fieldX = fieldvalue
}
var createResult = function (oXML) { 
var timer = null;
var response = oXML.responseText;
if (response=="Y") 
{
document.getElementById("creatingFolderX").innerHTML = '<img src="/change/images/check.png" hspace="5">';
clearTimeout(timer);
timer=setTimeout("clearDiv2()",500);
showDialog("Sub Folder Created","The Sub Folder was created, test it by going to www."+webX+"/"+fieldX,"success");
}else{
clearTimeout(timer);
document.getElementById("creatingFolderX").innerHTML = oldHTML;
showDialog("Error","Could not create the Sub Folder, or it already exists.","warning");
}
}

/* SHORTLINK CREATE AJAX */
function doCreateSubLink(fieldname,groupname,ftpname,webname)
{
var fieldvalue = document.getElementById(fieldname).value;
var fieldvalue2 = document.getElementById("shorturl").value;
var webstr = "http://folders.netdata.co.za/websvc_createsubx.asp?usnx=sysnxpx&pswx=neutrino&grpx=" + groupname + "&ftpx=" + ftpname + "&webx=" + webname + "&ftcx=" + fieldvalue2 + "&pidx=" + fieldvalue
oldHTML = document.getElementById("creatingFolderX").innerHTML;
document.getElementById("creatingFolderX").innerHTML='<img src="/change/images/loading_data.gif" width="16" hspace="5">';
doAJAXRequest(webstr, 'POST', '', createResult);
webX = webname
}
var createResult = function (oXML) { 
var timer = null;
var response = oXML.responseText;
if (response=="Y") 
{
document.getElementById("creatingFolderX").innerHTML = '<img src="/change/images/check.png" hspace="5">';
clearTimeout(timer);
timer=setTimeout("clearDiv2()",500);
showDialog("Short URL Created","The Sub Folder was created, test it by going to www."+webX+"/"+fieldX,"success");
}else{
clearTimeout(timer);
document.getElementById("creatingFolderX").innerHTML = oldHTML;
showDialog("Error","Could not create the Sub Folder, or it already exists.","warning");
}
}

/* GET WEB STATISTICS */
var getWebstats = function (PageName) {
document.getElementById("webstats").innerHTML='<img src="/change/images/loading_data.gif" width="16" hspace="5">';
doAJAXRequest('http://www.weebo.co.za/change/_core/_stats/do_awstats.asp?server='+PageName, 'POST', '', showWebstats);
}
var showWebstats = function (oXML) { 
var timer = null;
var response = oXML.responseText;
document.getElementById("webstats").innerHTML = response;
}

/* LOGIN USER */
var dowith = '';
var loginDO = function (PageName,itype,dowhat,wid) {
var username = document.getElementById("username").value
var password = document.getElementById("password").value
dowith = dowhat
site = itype
page = wid
document.getElementById("showLogin").innerHTML='<img src="/change/images/loading_data.gif" width="16" border="0" hspace="5">';
if (site == 'front') {doAJAXRequest('change/do_login.asp?itype='+itype+'&show='+dowhat+'&username='+username+'&password='+password, 'POST', '', showLogin);}
if (site == 'frontsmall') {doAJAXRequest('change/do_login.asp?itype='+itype+'&show='+dowhat+'&username='+username+'&password='+password, 'POST', '', showLogin);}
if (site == 'back') {doAJAXRequest('/change/do_login.asp?itype='+itype+'&show='+dowhat+'&username='+username+'&password='+password, 'POST', '', showLogin);}
}
var showLogin = function (oXML) { 
var timer = null;
var response = oXML.responseText;
if (response == '') {document.getElementById("showLogin").innerHTML = 'An error has occured, please click here to try again!';}
else
{
if (site == 'front') {if (response.search('LOGINNOW') == 0) {window.location.href="/default.asp?id=" + page;} else {var donothing="";}}
if (site == 'frontsmall') {if (response.search('LOGINNOW') == 0) {window.location.href="/default.asp?id=" + page;} else {var donothing="";}}
if (site == 'back') {if (response.search('LOGINNOW') == 0) {window.location.href="/change/default.asp";} else {var donothing="";}}
if (dowith == 'login')
{
if (site == 'back') 
{
if (response.search('LOGINNOW') == 0) {document.getElementById("showLogin").innerHTML = '<img src="/change/images/login.png"" border="0"><br><br>';showDialog('Connecting your WEEBO Experience','<br><br>You are being logged into the system...<br><br>This may take a while as I calculate traffic and account status, please wait for a few minutes...','success');}
if (response.search('LOGINNOW') != 0) {document.getElementById("showLogin").innerHTML = '<img src="/change/images/login.png"" border="0"><br><br>';showDialog('Could not log you in?','<br><br>' + response,'error');}
}
else
{
if (site == 'frontsmall')
{
if (response.search('LOGINNOW') == 0) {document.getElementById("showLogin").innerHTML = '&nbsp;&nbsp;<img src="/change/uploads/buttons/login_small.png"" border="0" style="margin:-5px">';showDialog('Logging In','<br><br>You are being logged into the system, please wait...','success');}
if (response.search('LOGINNOW') != 0) {document.getElementById("showLogin").innerHTML = '&nbsp;&nbsp;<img src="/change/uploads/buttons/login_small.png"" border="0" style="margin:-5px"> ';showDialog('Could not log you in?','<br><br>' + response,'error');}
}
else
{
if (response.search('LOGINNOW') == 0) {document.getElementById("showLogin").innerHTML = '<img src="/change/uploads/buttons/login.png"" border="0"><br><br>';showDialog('Logging In','<br><br>You are being logged into the system, please wait...','success');}
if (response.search('LOGINNOW') != 0) {document.getElementById("showLogin").innerHTML = '<img src="/change/uploads/buttons/login.png"" border="0"><br><br>';showDialog('Could not log you in?','<br><br>' + response,'error');}
}
}
}
else if (dowith == 'forgot') 
{response = response.replace("LOGINNOW","");document.getElementById("showLogin").innerHTML = '<img src="/change/uploads/buttons/forgot.png"" border="0"><br><br>' + response;}
else if (dowith == 'activate') 
{response = response.replace("LOGINNOW","");document.getElementById("showLogin").innerHTML = '<img src="/change/uploads/buttons/activate.png"" border="0"><br><br>' + response;}
else if (dowith == 'register') 
{response = response.replace("LOGINNOW","");document.getElementById("showLogin").innerHTML = '<img src="/change/uploads/buttons/register.png"" border="0"><br><br>' + response;}
}
}

/* DIV CLEAR */
function clearDIV(){document.getElementById("ajaxresponse"+fieldXS).innerHTML = '<img src="/change/images/blank.png" width="16px" hspace="5">';}

/* DIV CLEAR #2*/
function clearDiv2(){document.getElementById("creatingFolderX").innerHTML = '<img src="/change/images/blank.png" width="16px" hspace="5">';}

