// 
function ShowHideDiv(divname) {
	var curstate = document.getElementById(divname).style.display;
	//alert(curstate);
	if(curstate == "none") {
		document.getElementById(divname).style.display = "";
	} else {
		document.getElementById(divname).style.display = "none";
	}
}

function liquidconfirm(pagelink){
question = confirm("Are you sure you want to delete this? It cant be undone.")
if (question !="0"){
	location = pagelink;
	}
}

function setfieldvalue(thefield,newvalue) {
		document.getElementById(thefield).value = newvalue;
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
	
function sethelp(mess) {
	document.getElementById("helptext").innerHTML = mess;
}

var win= null;

function NewWindow(fieldName)
{
// Save the name of the target input field to the hidden input
document.form1.fieldName.value=fieldName

// Opens the Color Chart Popup
win2=window.open('../popup.html','colorPop','height=130,width=274,top=150,left=100,scrollbars=no,resizable=no');
}

function doIt(color)
{
// Get the selected color and send it to the target input field
eval('document.form1.' + document.form1.fieldName.value + '.value=\'' + color + '\'');
}

/* Script by: www.jtricks.com
 * Version: 20070703
 * Latest version:
 * www.jtricks.com/javascript/window/box_centered.html
 */
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement
    && document.documentElement.clientWidth;

// Moves the box object to be centered on current
// viewable area of the page
function center_box(box, width, height)
{
    cleft = has_inner
        ? pageXOffset + 
          (window.innerWidth - width)/2
        : has_element
          ? document.documentElement.scrollLeft + 
            (document.documentElement.clientWidth - width)/2
          : document.body.scrollLeft + 
            (document.body.clientWidth - width)/2;

    ctop = has_inner
        ? pageYOffset + (window.innerHeight - height)/2
        : has_element
          ? document.documentElement.scrollTop + 
            (document.documentElement.clientHeight - height)/2
          : document.body.scrollTop + 
            (document.body.clientHeight - height)/2;

    box.style.left = cleft > 0 ? cleft + 'px' : '0px';
    box.style.top = ctop > 0 ? ctop + 'px' : '0px';
}

// Hides other alone popup boxes that might be displayed
function hide_other_alone(obj)
{
    if (!document.getElementsByTagName)
        return;

    var all_divs = document.body.getElementsByTagName("DIV");

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).style.position != 'absolute' ||
            all_divs.item(i) == obj ||
            !all_divs.item(i).alonePopupBox)
        {
            continue;
        }

        all_divs.item(i).style.display = 'none';
    }
    return;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_box(an, width, height, borderStyle, conttype)
{
    show_hide_centered_href(
        an.href, width, height, borderStyle);
    return false;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_href(href, width, height, borderStyle, conttype)
{
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            hide_other_alone(boxdiv);
            // Show existing box, move it
            // if document changed layout
            center_box(boxdiv, width, height);
            boxdiv.style.display='block';

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow) {
                boxdiv.contents.src = href;
            }
        } else {
            // Hide currently shown box.
            boxdiv.style.display='none';
        }
        return false;
    }

    hide_other_alone(null);

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    // Add object identification variable
    
    boxdiv.alonePopupBox = 1;
	boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.padding = '0px';
    //boxdiv.style.textAlign = 'left';
    //boxdiv.style.background = '#FFFFFF';
    boxdiv.style.backgroundImage="url(../images/box470x420.png)";
    document.body.appendChild(boxdiv);
    boxdiv.style.textAlign = 'center';
	
	// iframe start
	if (conttype == "iframe") {
		var ifboxr = Math.random();
		var ifboxname = "ifbox" + ifboxr;
		var offset = 100;
		var nwwidth = width - 20;
		var nwwidth2 = width - 40;
		var ifmane = "'"+ ifboxname +"'";
		
		var closediv = document.createElement('div');
		closediv.style.width = nwwidth + 'px';
		closediv.style.textAlign = 'right';
		var hdtext = '<div  style=" text-align: left; color: #FFFFFF; margin-top: 20px; padding-left: 29px; padding-bottom: 3px; font-size: 14px;"><b>Change Page Settings</b></div>';
		var lkfunctext = "show_hide_centered_href('" + href + "', '" + width + "', '" + height + "', '" + borderStyle + "')";
		var atext = '<a href="javascript:void();" onclick="'+ lkfunctext +'"><img src="../buttons/cancelsm.png" style="margin-top: 10px;" alt="Cancel" width="61" height="26" border="0"></a>';
		var atext2 = '<a href="javascript:top.frames[' + ifmane + '].document.prefs.submit();"><img src="../buttons/savesm.png" style="margin-top: 10px;" alt="Cancel" width="61" height="26" border="0"></a>';
		var iftext = '<IFRAME SRC="'+ href +'" FRAMEBORDER="0" NAME="' + ifboxname + '" width="' + nwwidth2 + '" SCROLLING="AUTO" height="' + (height - offset) + '"></IFRAME><br/>';
		
		var outtext = hdtext + iftext + atext + atext2;
		
		closediv.innerHTML = outtext;
		boxdiv.appendChild(closediv);
	}
	//iframe end
	
	// folder start
	if (conttype == "newfolder") {
		var closediv = document.createElement('div');
		closediv.style.width = nwwidth + 'px';
		closediv.style.textAlign = 'right';
		var hdtext = '<div  style=" text-align: left; color: #FFFFFF; margin-top: 20px; padding-left: 29px; padding-bottom: 3px; font-size: 14px;"><b>Create a new folder</b></div>';
		
	}
	// folder end
	
    
	center_box(boxdiv, width, height);
    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return;
}

function dropgo(thedropdown) {
	var x = document.getElementById(thedropdown);
	var gotopg = x.options[x.selectedIndex].value;
	
	location = gotopg;
}

function findUserAQ(retrieve) {
	var em = document.getElementById('inemail').value;
	//alert(em);
	agent.call('../ajax_functions.php','findUserCRM','callback_findUserCRM',em,retrieve);
}

function callback_findUserAQ(outvar) {
	var result = outvar[0];
	var outpass = outvar[1];
	if(result == "true") {
		document.getElementById('password').value = outpass;
	} else {
		document.getElementById('getp').innerHTML = outpass;
	}
	//document.getElementById(getp).innerHTML = newtxt
}

function logonuserAQ() {
	var em = document.getElementById('inemail').value;
	var pass = document.getElementById('password').value;
	//alert(em);
	agent.call('../ajax_functions.php','logonuserAQ','callback_logonuserAQ',em,pass);
}

function callback_logonuserAQ(outvar) {
	var result = outvar[0];
	var username = outvar[1];
	var gotofolhm = outvar[2];
	if(result == "true") {
		//document.getElementById('password').value = outpass;
		welctxt = "Welcome back " + username;
		document.getElementById('getp').innerHTML = welctxt;
		//document.getElementById('logform').submit();
		window.location = gotofolhm;
		
	} else {
		document.getElementById('getp').innerHTML = username;
	}
	
	
	//document.getElementById(getp).innerHTML = newtxt
} 
