﻿function clearMainDivs() {
    var divArr = new Array('tabs-1-div', 'tabs-2-div', 'tabs-3-div', 'tabs-4-div', 'tabs-5-div', 'tabs-6-div');
    for (var i = 0; i < divArr.length; i++) {
        if (document.getElementById(divArr[i])) {
            document.getElementById(divArr[i]).style.display = "none";
        }
    }

}

function showDiv(thisDiv) {

    if (document.getElementById(thisDiv)) {
        clearMainDivs();
        document.getElementById(thisDiv).style.display = "block";
    }

}

function inputFocus(obj, evt, str) {

    if (evt == "focus") {

        if (obj.value == str) {
            $(obj).css('color','#333');
            obj.value = "";
        }

    } else if (evt == "blur") {

        if (obj.value == "") {
	    $(obj).css('color','#777');
            obj.value = str;
        }

    }

}






function newsletterValidate(frm) {

var alertMsg = "Please complete the following:\n";
var l_Msg = alertMsg.length;
var f_Arr = new Array();


if (!isEmail(frm.email.value)) {
alertMsg += " - Your Email Address" + "\n";
f_Arr.push(frm.email);
}

if (frm.captcha.value=="" || frm.captcha.value=="Enter the code") {
alertMsg += " - Code" + "\n";
f_Arr.push(frm.captcha);
}

//alert if fields are empty and cancel form submit
if (alertMsg.length == l_Msg){
		//return true;

		return popNewsletter();
		//return false;
}
else {
alert(alertMsg);
if (f_Arr[0] != undefined) {
f_Arr[0].focus();
}
return false;
   }
}






function popNewsletter() {

    var src = "/nlloading.php";
    $.modal('<iframe name="newsletter_iframe" src="'+src+'" width="500" height="250" style="border:0px;">', {

	onShow: function (dlg) {

		$(dlg.container).css('height', 'auto');
       		$(dlg.wrap).css('overflow', 'auto'); // or try jQuery.modal.update();

		setTimeout('$("#newslfrm").submit()','500');
	},

        containerCss: {
            backgroundColor: "#fff",
            border: "10px solid #333",
            width: 500,
            height: 250,
            padding: 10
        },
        overlayClose: true
    });

    return false;

}



function popPage(url,w,h) {

    $.modal('<iframe id="page_iframe" src="'+url+'" width="100%" height="'+h+'" style="border:0px;overflow:hidden;">', {

        containerCss: {
            backgroundColor: "#fff",
            border: "10px solid #333",
            width: w,
            height: h,
            padding: 10
        },
        overlayClose: true
    });

$(".simplemodal-wrap").css('overflow','hidden');
$(".simplemodal-data").css('width',w+"px");

}

function popNews(url,w,h) {

    $.modal('<iframe id="page_iframe" src="'+url+'" width="100%" height="'+h+'" style="border:0px;overflow-x:hidden;">', {


	onShow: function (dlg) {

		$(dlg.container).css('height', 'auto');
       		$(dlg.wrap).css('overflow', 'auto');
	},

        containerCss: {
            backgroundColor: "#fff",
            border: "10px solid #333",
            width: w+15,
            height: h,
            padding: 10
        },
        overlayClose: true
    });

$(".simplemodal-data").css('width',(w+15)+"px");

}


function centerDoc(theURL, winName, features, myWidth, myHeight, isCenter) {

    if (window.screen) if (isCenter) if (isCenter == "true") {
        var myLeft = (screen.width - myWidth) / 2;
        var myTop = ((screen.height - myHeight) / 2) - 40;
        features += (features != '') ? ',': '';
        features += 'scrollbars=yes,resizable=no,status=yes,left=' + myLeft + ',top=' + myTop;
    }

    newWin = window.open(theURL, winName, features + ((features != '') ? ',': '') + 'width=' + myWidth + ',height=' + myHeight);
    newWin.focus();
}




function showTip(tipId, e) {

    if (tooltipArr[tipId] != "undefined") {

	var thisArr = tooltipArr[tipId].split("|");
	
        $("#tipcontent").html("<div class=\"tiptitle\">"+thisArr[0]+"</div><div class=\"tiptxt\">"+thisArr[1]+"</div>");

        if (document.getElementById('tipcontainer')) {

            var obj = document.getElementById('tipcontainer');
            var tpointerleft = document.getElementById('tippointerleft');
            var tpointerright = document.getElementById('tippointerright');

            tpointerleft.style.display = "none";
            tpointerright.style.display = "none";

            var pixelMid = (screen.width / 2);

            var xPos = mousePos('X', e);
            var yPos = mousePos('Y', e);

            if (xPos <= pixelMid) {
                tpointerleft.style.display = "";
                obj.style.left = (xPos + 10) + "px";
            } else if (xPos > pixelMid) {
                tpointerright.style.display = "";
                obj.style.left = ((xPos - 240) - 10) + "px";
            }

            obj.style.top = (yPos - 18) + "px";
            //obj.style.display = "";
            $(obj).stop(true, true).fadeIn(250);

        }

    }

}

function hideTip() {

    $("#tipcontent").html("");

    if (document.getElementById('tipcontainer')) {

        var obj = document.getElementById('tipcontainer');
        var tpointerleft = document.getElementById('tippointerleft');
        var tpointerright = document.getElementById('tippointerright');

        tpointerleft.style.display = "none";
        tpointerright.style.display = "none";
        obj.style.display = "none";

    }

}

function mousePos(pos, e) {
    var posX = 0;
    var posY = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posX = e.pageX;
        posY = e.pageY;
    } else if (e.clientX || e.clientY) {
        posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    // posX and posY contain the mouse position relative to the document

    if (pos == "X") {
        return posX;
    } else if (pos == "Y") {
        return posY;
    }

}


function findPos(obj, which) {
	var cur = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {

			if (which == "X") {
				cur += obj.offsetLeft;
			} else if (which == "Y") {
				cur += obj.offsetTop;

			}

			obj = obj.offsetParent;
		}
	} else {
		if (which == "X" && obj.x) {
			cur += obj.x;
		} else if (which == "Y" && obj.y) {
			cur += obj.y;
		}

	}

	return cur;
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name+"=";
	var ca = document.cookie.split(';');
	for (var i = 0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}


function eraseCookie(name) {
    createCookie(name,"",-1);
}


function setHeaderDescription(str) {
	$("#cheader_descr").html(str);
}



/* network status*/


var nstatuss = "";
var nstatusSize = "";
var nstatusIndex = 0;


function showNetStatusOnce() {

$('#netstatusdiv').animate({
    height: '85px'
  }, {
    duration: 800,
    complete: function() {

	$("#nstatusimg").removeClass('nstatus_ok');
	$("#nstatusimg").addClass('nstatus_nok');
	$('#nstatusalerts').show();

    }
  });

 $('#nstatusdiv').animate({
    height: '31px'
  }, {
    duration: 800,
    complete: loadNetStatus
  });

createCookie("netstatus", "true", 1);

}


function showNetStatus(ajax) {

if (readCookie('netstatus') != null) {

if ( $("#nstatuscontainer").is(":visible") ) {
loadNetStatus();

} else {

$('#netstatusdiv').height('85px');
$("#nstatusimg").removeClass('nstatus_ok');
$("#nstatusimg").addClass('nstatus_nok');
$('#nstatusalerts').show();

$('#nstatusdiv').height('31px');
$('#nstatusdiv').show();
loadNetStatus();

}


} else {
// only animate once

if (ajax) {

	showNetStatusOnce();
} else {
	// onload
	jQuery(window).bind("load", function() {
		showNetStatusOnce();
	});
}


}

}


function loadNetStatus() {
    $.ajax({
        type: "GET",
        url: "/notices/xml/netstatus.xml",
	cache: false,
        dataType: "xml",

        success: function(xml) {
		$("#nstatus-list").html("");	

            $(xml).find('scroll').each(function() {
                var title = $(this).find('title').text();
                var description = $(this).find('description').text();
		//change anchor attr of div
                $('<div></div>').html(title + ': ' + description).appendTo('#nstatus-list');

            });

		nstatuss = $("#nstatus-list div");
        	nstatusSize = nstatuss.size();
        	if (nstatusSize != 0) {
			//nstatusIndex = 0; // reset index
            		$("#nstatuscontent").html($($(nstatuss)[nstatusIndex]).html());
            		$("#nstatuscontainer").fadeIn(450);
        	}


        }

    });

}



function closeNetStatus() {

$('#nstatusdiv').animate({
    height: '0px'
  }, {
    duration: 800,
    complete: function() {

	$('#nstatus-list').html("");
	$('#nstatusdiv').hide();

    }
});

$('#netstatusdiv').animate({
    height: '66px'
  }, {
    duration: 800,
    complete: function() {

	$("#nstatusimg").removeClass('nstatus_nok');
	$("#nstatusimg").addClass('nstatus_ok');
	$('#nstatusalerts').hide();

    }
});

eraseCookie("netstatus");

}



function refreshNetworkStatus(timer) {

var refreshId = setInterval(function(){

$.ajax({
        type: "GET",
        url: "/networkcontrol.php",
	cache: false,
 	success: function(msg) {
		//alert(msg);

		if (msg.substr(0,1) == "1") {
			
			// only call if closed
			//if ( !$("#nstatuscontainer").is(":visible") ) {
				$("#nstatusalertstxt").text(msg.split("|")[1]);
				showNetStatus(true);
			//}

		} else if (msg.substr(0,1) == "0") {

			// only call if open
			if ( $("#nstatuscontainer").is(":visible") ) {
				closeNetStatus();
			}
		}

  	}
});

    }, timer);

}


function changeNetStatus(dir) {

        if (dir == "prev") {
            nstatusIndex--;
        } else if (dir == "next") {
            nstatusIndex++;
        }

        if (nstatusIndex == nstatusSize) {
            nstatusIndex = 0;
        } else if (nstatusIndex < 0) {
            nstatusIndex = (nstatusSize - 1);
        }

        $('#nstatuscontainer').stop(true, true).fadeOut('200',
        function() {
            $("#nstatuscontent").html($($(nstatuss)[nstatusIndex]).html());
            $("#nstatuscontainer").fadeIn(450);
        });

}



function searchSubmit(frm) {

if ( searchValidate(frm) ) {
	frm.submit();
}

}


function searchValidate(frm) {

var alertMsg = "Please complete the following:\n";
var l_Msg = alertMsg.length;
var f_Arr = new Array();

if (frm.query.value=="" || frm.query.value=="Search the site..") {
alertMsg += " - Search Keywords" + "\n";
f_Arr.push(frm.query);
}

//alert if fields are empty and cancel form submit
if (alertMsg.length == l_Msg){
		return true;
}
else {
alert(alertMsg);
if (f_Arr[0] != undefined) {
f_Arr[0].focus();
}
return false;
   }
}





/* signin*/

function loginValidate(frm) {
var alertMsg = "Please complete the following:\n";
var l_Msg = alertMsg.length;
var f_Arr = new Array();

// user
if (frm.signin_user.value=="") {

var thisVal = $("#signin_panel").attr('value');
if (thisVal == "ccp" || thisVal == "rcp") {
	alertMsg += " - Client Code" + "\n";
} else {
	alertMsg += " - Username" + "\n";	
}

f_Arr.push(frm.signin_user);
}

// password
if (frm.signin_pass.value=="") {
alertMsg += " - Password" + "\n";
f_Arr.push(frm.signin_pass);
}



if ( $('#hserverdiv').is(":visible") ) {

if (frm.hserverselect.value == "-1") {
alertMsg += " - Hosting Server" + "\n";
f_Arr.push(frm.hserverselect);
}

}


//alert if fields are empty and cancel form submit
if (alertMsg.length == l_Msg){
		

		loginRequest(frm.signin_panel.value); // user tracking

		if (frm.hserverselect.value != -1) {
			loginControl(frm.signin_panel.value,frm.signin_user.value,frm.signin_pass.value,frm.hserverselect.value);
		} else {
			loginControl(frm.signin_panel.value,frm.signin_user.value,frm.signin_pass.value,'');
		}

		return false;
}
else {
alert(alertMsg);
if (f_Arr[0] != undefined) {
f_Arr[0].focus();
}
return false;
   }
}





function loginControl(panel,u,p,hostingUrl) {

	loginAjaxUI('on');

$.ajax({
   type: "GET",
   url: "/logincontrol.php",
   data: "panel="+panel+"&u="+u+"&p="+encodeURIComponent(p)+"&hostingurl="+hostingUrl,

    timeout: 45000,
    error: function(xhr, textStatus, errorThrown){
    	//alert("Error: " +textStatus);

	if (error == "timeout") {
		loginAjaxUI('off','Cannot connect to Control Panel.<br>Please try again.');
	} else {
		loginAjaxUI('off',textStatus);
	}


    },

   success: function(msg){
//alert(msg);

	if (msg.substr(0,1) == "1") { // check success/failure
		loginAjaxUI('off','');
		//redirect
		loginRedirect(panel,msg.split("|")[1]);
	} else if (msg.substr(0,1) == "0"){
		// ERROR
		loginAjaxUI('off',msg.split("|")[1]);
	}


   }
 });

}




function loginRedirect(panel,hostingLinks) {

if (panel == "webmail") {

	// post form with these creds
	$("#webmail_user").attr('value', $("#signin_user").attr('value'));
	$("#webmail_pass").attr('value', $("#signin_pass").attr('value'));
	$('#frmwebmail').submit();
}


if (panel == "hosting") {

var hostingLinksArr = hostingLinks.split("~");

if (hostingLinksArr.length == 1) {

	$("#signin_navaway").css("width",$("#signindiv").width() - 26);
	$("#signin_navaway").css("height",$("#signindiv").height() - 18);
	$("#signin_navaway").show();
	//window.location = hostingLinksArr[0];
	setTimeout('window.location = "'+hostingLinksArr[0]+'"','100');
} else { //multiple hosting servers

//alert(hostingLinksArr);

	// clear hosting select
	$("#hserverselect option").remove();
	$("#hserverselect").append(new Option("Choose Server", "-1"));

	for (var i = 0; i <hostingLinksArr.length-1;i++) {
	//alert(hostingLinksArr[i]);
	var hLink = hostingLinksArr[i];
	
	var hProt = hLink.substr(0,hLink.indexOf("//")+2);
	var hTemp = hLink.substr(hLink.indexOf("//")+2);
	var hHost = hTemp.substr(0,hTemp.indexOf("."));

	if (hTemp.indexOf('2083') != -1) {//cpanel
		var hTxt = hHost +" : cPanel";
	} else {//plesk
		var hTxt = hHost +" : Plesk";
	}

	$("#hserverselect").append(new Option(hTxt, hLink));	
	}


	$("#hserverdiv").show();
	$("#hserverselect").focus();
	return;
}


}



if (panel == "ccp") {
	$("#frmlogin").attr('action', 'https://www.adsl.co.za/client/login');
} else if (panel == "rcp") {
	$("#frmlogin").attr('action', 'https://rcp.adsl.co.za/reseller/login');
} else if (panel == "gsc") {
	$("#frmlogin").attr('action', 'https://ccp.adsl.co.za/groupstoreclient/login');
}

if (panel == "ccp" || panel == "rcp") {
$("#login_user").attr('value', $("#signin_user").attr('value'));
$("#login_pass").attr('value', $("#signin_pass").attr('value'));
$('#frmlogin').submit();
}

if (panel == "gsc") {

var userArr = $("#signin_user").attr('value').split("@");

$("#login_user").attr('value', userArr[0]);
$("#login_pass").attr('value', $("#signin_pass").attr('value'));
$("#login_realmid").show();
$("#login_realmid").attr('value', userArr[1]);

$('#frmlogin').submit();

}


$("#signin_navaway").css("width",$("#signindiv").width() - 26);
$("#signin_navaway").css("height",$("#signindiv").height() - 18);
$("#signin_navaway").show();


}



function clearHostingDiv() {
	$("#hserverselect option").remove();
	$("#hserverselect").append(new Option("Choose Server", "-1"));
	$("#hserverdiv").hide();
}




function loginAjaxUI(process,err) {

if (process == "on") {

	$("#signinsubmit").attr('value','Processing');
	$("#signin_processloader").show();
	$("#signinsubmit").attr('disabled',true);
	$("#signin_panel").attr('disabled',true);

	//$("#signin_err").stop(true, true).fadeOut(450);
	$("#signin_err").hide();

} else if (process == "off") {

	$("#signinsubmit").attr('value','Sign In');
	$("#signin_processloader").hide();
 	$('#signinsubmit').removeAttr("disabled");
 	$('#signin_panel').removeAttr("disabled"); 

	if (err != "") {
		clearHostingDiv();
		$("#signin_err_txt").html(err);
		$("#signin_err").stop(true, true).fadeIn(450);
	}

}

}


function toggleContainer(thisObj,newObj) {

        $("#"+thisObj).stop(true, true).fadeOut('200',
        function() {
		$("#"+newObj).stop(true, true).fadeIn(250);

		if (newObj == "signin_container") {
			clearHostingDiv();
			$("#fpass_err").hide();
			$("#signin_user").focus();
		} else if (newObj == "fpass_container") {

			clearPassDivs();
			$("#signin_err").hide();
			$("#fpass_user").focus();

			if ($("#fpass_panel").attr('value') == "ccp" || $("#fpass_panel").attr('value') == "rcp") {
				$("#fpass_user_label").text('E-mail');
			}

			if ($("#fpass_panel").attr('value') == "gsc") {

				$("#fpass_user").attr('disabled',true);
				$("#fpasssubmit").attr('disabled',true);
			} else {
			 	$('#fpass_user').removeAttr("disabled"); 
 				$('#fpasssubmit').removeAttr("disabled"); 
			}


		}

        });

}


function clearCpanelDiv() {
	$("#fpass_cpanel_code").attr('value', '');
	$("#fpass_cpanel_txt").text('');
	$("#fpass_cpanel_txtdiv").hide();
	$("#fpass_cpanel_div").hide();
}

function clearPleskDiv() {
	$("#fpass_plesk_txtdiv").hide();
	$("#fpass_plesk_email").attr('value', '');
	$("#fpass_plesk_div").hide();
}

function clearPassDivs() {
	//-- panel -->
	$("#fpass_panel_txtdiv").hide();
	//-- panswer -->
	$("#fpass_index").attr('value', '');
	$("#fpass_answer").attr('value', '');
	$("#answerdiv").hide();
	$("#fpass_newpassword").attr('value', '');
	$("#fpass_token").attr('value', '');
	$("#newpassworddiv").hide();
	//-- cpanel -->
	$("#fpass_cpanel_code").attr('value', '');
	$("#fpass_cpanel_txt").text('');
	$("#fpass_cpanel_txtdiv").hide();
	$("#fpass_cpanel_div").hide();
	//-- plesk -->
	$("#fpass_plesk_txtdiv").hide();
	$("#fpass_plesk_email").attr('value', '');
	$("#fpass_plesk_div").hide();
	//-- hosting -->
	$("#fpass_hserverselect option").remove();
	$("#fpass_hserverselect").append(new Option("Choose Server", "-1"));
	$("#fpass_hserverdiv").hide();

}


function selectHostingPass(obj) {
	fPassValidate(obj.form,'true');
	clearCpanelDiv();
	clearPleskDiv();
}


function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
	return true;
} else {
	return false;
}
}


function fPassValidate(frm,bypass) {
var alertMsg = "Please complete the following:\n";
var l_Msg = alertMsg.length;
var f_Arr = new Array();

// user
if (frm.fpass_user.value=="") {

var thisVal = $("#fpass_panel").attr('value');
if (thisVal == "ccp" || thisVal == "rcp") {
	alertMsg += " - E-mail" + "\n";
} else {
	alertMsg += " - Username" + "\n";	
}

f_Arr.push(frm.fpass_user);
}



if ( $('#answerdiv').is(":visible") ) {

if (frm.fpass_answer.value=="") {
alertMsg += " - Answer" + "\n";
f_Arr.push(frm.fpass_answer);
}

}


if ( $('#newpassworddiv').is(":visible") ) {

if (frm.fpass_newpassword.value.length < 6) {
alertMsg += " - New Password (6+ characters)" + "\n";
f_Arr.push(frm.fpass_newpassword);
}

}



if (bypass == "false") {

if ( $('#fpass_cpanel_div').is(":visible") ) {

if (frm.fpass_cpanel_code.value=="") {
alertMsg += " - Confirmation Code" + "\n";
f_Arr.push(frm.fpass_cpanel_code);
}

}


if ( $('#fpass_plesk_div').is(":visible") ) {

if (!isEmail(frm.fpass_plesk_email.value)) {
alertMsg += " - E-mail" + "\n";
f_Arr.push(frm.fpass_plesk_email);
}

}

}




if ( $('#fpass_hserverdiv').is(":visible") ) {

if (frm.fpass_hserverselect.value == "-1") {
alertMsg += " - Hosting Server" + "\n";
f_Arr.push(frm.fpass_hserverselect);
}

}


//alert if fields are empty and cancel form submit
if (alertMsg.length == l_Msg){


		if (frm.fpass_answer.value != "" && frm.fpass_index.value != "") {

			if (frm.fpass_newpassword.value!= "" && frm.fpass_token.value!= "") {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,frm.fpass_answer.value,frm.fpass_index.value,frm.fpass_newpassword.value,frm.fpass_token.value,'','','');
			} else {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,frm.fpass_answer.value,frm.fpass_index.value,'','','','','');
			}


		} else if (frm.fpass_cpanel_code.value!= "") { // cpanel step 2

			if (frm.fpass_hserverselect.value!= "-1") {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','',frm.fpass_cpanel_code.value,'',frm.fpass_hserverselect.value);
			} else {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','',frm.fpass_cpanel_code.value,'','');
			}

		} else if (frm.fpass_plesk_email.value!= "") { // plesk

			if (frm.fpass_hserverselect.value!= "-1") {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','','',frm.fpass_plesk_email.value,frm.fpass_hserverselect.value);
			} else {
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','','',frm.fpass_plesk_email.value,'');
			}

		} else if (frm.fpass_hserverselect.value!= "-1") { // multiple hosting
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','','','',frm.fpass_hserverselect.value);

		} else {// all, except webmail step 2
			fPassControl(frm.fpass_panel.value,frm.fpass_user.value,'','','','','','','');
		}

		return false;
}
else {
alert(alertMsg);
if (f_Arr[0] != undefined) {
f_Arr[0].focus();
}
return false;
   }
}





function fPassControl(panel,u,answer,passIndex,newpassword,token,cpanelCode,pleskEmail,hostingUrl) {

	passwordAjaxUI('on','');


$.ajax({
   type: "GET",
   url: "/passwordcontrol.php",
   data: "panel="+panel+"&u="+u+"&answer="+answer+"&passindex="+passIndex+"&newpassword="+newpassword+"&token="+token+"&cpanelcode="+cpanelCode+"&pleskemail="+pleskEmail+"&hostingurl="+hostingUrl,

    error: function(xhr, textStatus, errorThrown){
    	//alert("Error: " +textStatus);
	passwordAjaxUI('off','Please Try Again');
    },

   success: function(msg){
//alert(msg);

	if (msg.substr(0,1) == "1") { // check success/failure

		passwordAjaxUI('off','');

	if (panel == "ccp" || panel == "rcp" || panel == "gsc") {
		
		$("#fpass_panel_txtdiv").show();

	} else if (panel == "webmail") {

		//add question
		//update page index
		var msgArr = msg.split("|");
		$("#fpass_index").attr('value',msgArr[1]);
		$("#answertxt").text(msgArr[2]);
		$("#answerdiv").show();
		$("#fpass_answer").focus();

	} else if (panel == "hosting") {
	
		var hostingLinksArr = msg.split("|")[1].split("~");

		if (hostingLinksArr.length == 1) {

			// cpanel or plesk?
			var subPanelArr = msg.split("|");
			if (subPanelArr[1] == "cpanel") {

				$("#fpass_cpanel_div").show();
				$("#fpass_cpanel_code").focus();

			} else if (subPanelArr[1] == "plesk") {

				$("#fpass_plesk_div").show();
				$("#fpass_plesk_email").focus();

			}

		} else { //multiple hosting servers

			// clear hosting select
			$("#fpass_hserverselect option").remove();
			$("#fpass_hserverselect").append(new Option("Choose Server", "-1"));

			for (var i = 0; i <hostingLinksArr.length-1;i++) {
			//alert(hostingLinksArr[i]);
			var hLink = hostingLinksArr[i];
	
			var hProt = hLink.substr(0,hLink.indexOf("//")+2);
			var hTemp = hLink.substr(hLink.indexOf("//")+2);
			var hHost = hTemp.substr(0,hTemp.indexOf("."));

			if (hTemp.indexOf('2083') != -1) {//cpanel
				var hTxt = hHost +" : cPanel";
			} else {//plesk
				var hTxt = hHost +" : Plesk";
			}

			$("#fpass_hserverselect").append(new Option(hTxt, hLink));	
			}


			$("#fpass_hserverdiv").show();
			$("#fpass_hserverselect").focus();
			return;

		}


		
	}


	} else if (msg.substr(0,1) == "2") { // webmail

		passwordAjaxUI('off','');

		$('#fpass_token').attr('value',msg.split("|")[1]);
		$('#newpassworddiv').show();
		$('#fpass_newpassword').focus();

	} else if (msg.substr(0,1) == "5") { // webmail final

		passwordAjaxUI('off','');

		//alert('password has been updated');
		$("#newpasswordtxtdiv").show();
	
	} else if (msg.substr(0,1) == "3") { // cpanel final

		passwordAjaxUI('off','');

		//$("#fpass_cpanel_txt").html(msg.split("|")[1]).text(); //password could contain |
		$("#fpass_cpanel_txt").html(msg.substr(2)).text();
		$("#fpass_cpanel_txtdiv").show();

	} else if (msg.substr(0,1) == "4") { // plesk final

		passwordAjaxUI('off','');
		$("#fpass_plesk_txtdiv").show();

	} else if (msg.substr(0,1) == "0"){

		//alert('error');
		// ERROR
		passwordAjaxUI('off',msg.split("|")[1]);
	}





 }
 });

}







function passwordAjaxUI(process,err) {

if (process == "on") {

	$("#fpasssubmit").attr('value','Processing');
	$("#fpass_processloader").show();
	$("#fpasssubmit").attr('disabled',true);
	$("#fpass_panel").attr('disabled',true);

	$("#fpass_err_txt").text("");
	//$("#fpass_err").stop(true, true).fadeOut(450);
	$("#fpass_err").hide();

} else if (process == "off") {

	$("#fpasssubmit").attr('value','Request Password');
	$("#fpass_processloader").hide();
 	$('#fpasssubmit').removeAttr("disabled");
 	$('#fpass_panel').removeAttr("disabled"); 

if (err != "") {
	$("#fpass_err_txt").text(err);
	$("#fpass_err").stop(true, true).fadeIn(450);
}

}

}




jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 600
	}, settings);	
	
	return this.each(function(){
		var caller = this;
		$(caller).change(function (event) {
	
			event.preventDefault();
			var locationHref = window.location.href;
			var elementClick = $(caller).attr("value");
			
			//var destination = $(elementClick).offset().top;
			var destination = document.getElementById($(elementClick).attr("id")).offsetTop;


			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick;
			});
		  	return false;
		})
	})
}

function pageTop() {
	$('html, body').animate( { scrollTop: 0 }, 600 );
}



// user tracking
function loginRequest(val) {


	$.ajax({
		type: "GET",
    		url: "/loginrequest.php",
		cache: false,
		data: "loginpath="+val,
    		dataType: "text",
		timeout: 15000,
		error: function(request,error,errorThrown) {
				
			/*
			if (error == "timeout") {
				//alert('timeout');	
			} else {
				//alert(errorThrown);	
			}
			*/
				
		},
    		success: loginRequestProcess

	});


}


function loginRequestProcess() {


}




$(document).ready(function() {


    /* main nav */
    $('#nav ul li').mouseenter(function() {
        $(this).children(".subnav").stop(true, true).fadeIn(450);
    });

    $('#nav ul li').mouseleave(function() {
        $(this).children(".subnav").stop(true, true).fadeOut(200);
    });

    /* sign in */
    $(".signin").click(function(e) {
        e.preventDefault();

        if ($("#signindiv").css('display') == "none") {
            $("#signindiv").stop(true, true).fadeIn(450);
            toggleContainer('fpass_container', 'signin_container');
	
		$("#signin_navaway").hide();	
            //$("#signin_user").focus();
        } else {
            $("#signindiv").stop(true, true).fadeOut(200);
        }

    });

    $("#signindiv").mouseup(function() {
        return false;
    });

    $(document).mouseup(function(e) {
        $("#signindiv").stop(true, true).fadeOut(200);
    });

    $('#signin_panel').change(function() {
	var thisVal = $("#signin_panel").attr('value');
	setLabel(thisVal,this)
        $("#signin_user").focus();
        $("#signin_err").stop(true, true).fadeOut(450);
        $("#fpass_panel").attr('value', thisVal);
	clearHostingDiv();
    });

    $('#fpass_panel').change(function() {
	var thisVal = $("#fpass_panel").attr('value');
	setLabel(thisVal,this);
        $("#fpass_user").focus();
	$("#fpass_err").stop(true, true).fadeOut(450);
        $("#signin_panel").attr('value', thisVal);
	clearPassDivs();
    });

    $('#signin_user').change(function() {
        $("#fpass_user").attr('value', $("#signin_user").attr('value'));
	clearHostingDiv();
    });

    $('#fpass_user').change(function() {
        $("#signin_user").attr('value', $("#fpass_user").attr('value'));
	clearPassDivs();
    });

    /* tabs */
    $("#tabs li a").click(function() {

        $("#tabs li").removeClass('tabselect');
        var thisAnchor = this.parentNode.firstChild;
        var thisList = this.parentNode;

        $(thisList).addClass('tabselect');
        var thisDiv = document.getElementById(thisAnchor.id + "-div");

        clearMainDivs();
        thisDiv.style.display = "block";
        //$(thisDiv).fadeIn(500);

    });

    $('.nstatusprev').click(function() {
        changeNetStatus('prev');
    });

    $('.nstatusnext').click(function() {
        changeNetStatus('next');
    });


function setLabel(val,obj) {
	if (val == "ccp" || val == "rcp") {
		$("#signin_user_label").text('Client Code');
		$("#fpass_user_label").text('E-mail');
	} else {
		$("#fpass_user_label").text('Username');
		$("#signin_user_label").text('Username');	
	}

	
	if (obj.id == "fpass_panel") { // only forgot password
		if (val == "gsc") {
			$("#fpass_user").attr('disabled',true);
			$("#fpasssubmit").attr('disabled',true);
		} else {
 			$('#fpass_user').removeAttr("disabled"); 
 			$('#fpasssubmit').removeAttr("disabled"); 
		}
	}

}




	$("#netstatusdiv").click(function(){
		window.location = "/networkstatus.php";	
	});


	$("#query").focus(function(){
		inputFocus(this,'focus','Search the site..');
	});

	$("#query").blur(function(){
		inputFocus(this,'blur','Search the site..');
	});

	$("#email").focus(function(){
		inputFocus(this,'focus','Your Email Address');
	});

	$("#email").blur(function(){
		inputFocus(this,'blur','Your Email Address');
	});

	$("#captcha").focus(function(){
		inputFocus(this,'focus','Enter the code');
	});

	$("#captcha").blur(function(){
		inputFocus(this,'blur','Enter the code');
	});




    // end jquery ready
});
