
function GetViewWidth()
{
    var myview_w = 0;
	
    if (self.innerWidth){
	    myview_w = self.innerWidth;
	}
    else if (document.documentElement && document.documentElement.clientWidth){
	    myview_w = document.documentElement.clientWidth;
	}
    else if (document.body){
    	myview_w = document.body.clientWidth;
    }

    return myview_w;
}

function GetViewHeight()
{
    var myview_h = 0;

    if (self.innerHeight){
        myview_h = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight){
	    myview_h = document.documentElement.clientHeight;
	}
    else if (document.body){
	    myview_h = document.body.clientHeight;
	}
    return myview_h;
}

function OpenDialogFeedback()
{
	var left = Math.floor((GetViewWidth() - 700) / 2);
	var top = Math.floor((GetViewHeight() - 598) / 2);

	if (!DialogFeedback.get_isShowing())
	{
        DialogFeedback.set_x(left);
        DialogFeedback.set_y(top);
        DialogFeedback.Show();
	}
}

function DialogFeedbackSuccess(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("This message has been sent. Thank you.");
    }
    DialogFeedback.Close('');
}

function DialogFeedbackFail(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("There was an error sending your feedback request.");
    }
    DialogFeedback.Close('');
}

function OpenDialogTools()
{
	var left = Math.floor((GetViewWidth() - 700) / 2);
	var top = Math.floor((GetViewHeight() - 500) / 2);

	if (!DialogTools.get_isShowing())
	{
        DialogTools.set_x(left);
        DialogTools.set_y(top);
        DialogTools.Show();
	}
}

function DialogToolsSuccess(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    DialogTools.Close('');
}


function DialogToolsFail(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    DialogTools.Close('');
}


function OpenDialogTimeTracking()
{
	var left = Math.floor((GetViewWidth() - 700) / 2);
	var top = Math.floor((GetViewHeight() - 500) / 2);

	if (!DialogTimeTracking.get_isShowing())
	{
        DialogTimeTracking.set_x(left);
        DialogTimeTracking.set_y(top);
        DialogTimeTracking.Show();
	}
}

function OpenDialogAnnotations()
{
	var left = Math.floor((GetViewWidth() - 700) / 2);
	var top = Math.floor((GetViewHeight() - 500) / 2);

	if (!DialogAnnotations.get_isShowing())
	{
        DialogAnnotations.set_x(left);
        DialogAnnotations.set_y(top);
        DialogAnnotations.Show();
	}
}

function OpenDialogSavedSearch()
{
	var left = Math.floor((GetViewWidth() - 700) / 2);
	var top = Math.floor((GetViewHeight() - 500) / 2);

	if (!DialogSavedSearch.get_isShowing())
	{
        DialogSavedSearch.set_x(left);
        DialogSavedSearch.set_y(top);
        DialogSavedSearch.Show();
	}
}
 
function OpenDialogLogin()
{
	var left = Math.floor((GetViewWidth() - 450) / 2);
	var top = Math.floor((GetViewHeight() - 250) / 2);

	if (!DialogLogin.get_isShowing())
	{
        DialogLogin.set_x(left);
        DialogLogin.set_y(top);
        DialogLogin.Show();
	}
}

function OpenDialogLogout()
{
	var left = Math.floor((GetViewWidth() - 450) / 2);
	var top = Math.floor((GetViewHeight() - 250) / 2);

	if (!DialogLogout.get_isShowing())
	{
        DialogLogout.set_x(left);
        DialogLogout.set_y(top);
        DialogLogout.Show();
	}
}

function DialogLoginSuccess(message)
{
    
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        //alert("You were successfully logged in.");
        //UpdateWizard();
    }
    DialogLogin.Close('');
    UpdateLoginStatus();
}

function DialogLoginFail(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("");
    }
    DialogLogin.Close('');
    UpdateLoginStatus();
}

function SetupForgotPassword()
{
   // alert("Now showing...");

   setTabAble("ctl00_ForgotPassword1_txtForgotPasswordUsername", 1, true);
   setTabAble("ctl00_ForgotPassword1_btnForgotPasswordSubmit", 2, false);
}

function OpenDialogForgotPassword()
{
	var left = Math.floor((GetViewWidth() - 450) / 2);
	var top = Math.floor((GetViewHeight() - 250) / 2);

	if (!DialogForgotPassword.get_isShowing())
	{
        DialogForgotPassword.set_x(left);
        DialogForgotPassword.set_y(top);
        DialogForgotPassword.Show();
	}
}

function DialogForgotPasswordSuccess(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("Your password was successfully changed. You will receive an email containing your new password.");
    }
    DialogForgotPassword.Close('');
}

function DialogForgotPasswordFail(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("There was an error changing your password.");
    }
    DialogForgotPassword.Close('');
}

function OpenDialogChangePassword()
{
	var left = Math.floor((GetViewWidth() - 450) / 2);
	var top = Math.floor((GetViewHeight() - 250) / 2);

	if (!DialogChangePassword.get_isShowing())
	{
        DialogChangePassword.set_x(left);
        DialogChangePassword.set_y(top);
        DialogChangePassword.Show();
	}
}

function DialogChangePasswordSuccess(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("Your password was successfully changed.");
    }
    DialogChangePassword.Close('');
}

function DialogChangePasswordFail(message)
{
    if (message.length > 0)
    {
        alert(message);
    }
    else
    {
        alert("There was an error changing your password.");
    }
    DialogChangePassword.Close('');
}


/**********************************************************/
///User/ProductDowload.aspx
function OpenUserAgreementDialog()
{
    var left = Math.floor((GetViewWidth() - 950) / 2);
    var top = Math.floor((GetViewHeight() - 550) / 2);
    if (!DialogAgreement.get_isShowing())
    {
        DialogAgreement.set_x(left);
        DialogAgreement.set_y(top);
        DialogAgreement.Show();
    }
}


/**********************************************************/
//Admin/SubscriptionForm/DialogContact
function OpenDialogContact()
{
	var left = Math.floor((GetViewWidth() - 450) / 2);
	var top = Math.floor((GetViewHeight() - 250) / 2);

	if (!DialogContact.get_isShowing())
	{
        DialogContact.set_x(left);
        DialogContact.set_y(top);
        DialogContact.Show();
	}
}

/**********************************************************/
//Admin/DialogSubscriptionManagement

var intervalOpenDialog;

function OpenDialogSubscriptionManagement()
{
    intervalOpenDialog = window.setInterval('TryOpenDialogSubscriptionManagement();',100);
}

function TryOpenDialogSubscriptionManagement()
{
    try
    {
    	var left = Math.floor((GetViewWidth() - 800) / 2);
	    var top = Math.floor((GetViewHeight() - 600) / 2);

        DialogSubscriptionManagement.set_x(left);
        DialogSubscriptionManagement.set_y(top);
        DialogSubscriptionManagement.Show();
        if (DialogSubscriptionManagement.get_isShowing())
        {
            window.clearInterval(intervalOpenDialog);
        }
    }
    catch (err)
    {
    }
}

function OpenDialogSubscriptionManagementAlert()
{
    intervalOpenDialog = window.setInterval('TryOpenDialogSubscriptionManagementAlert();',100);
}

function TryOpenDialogSubscriptionManagementAlert()
{
    try
    {
    	var left = Math.floor((GetViewWidth() - 450) / 2);
	    var top = Math.floor((GetViewHeight() - 250) / 2);

        DialogSubscriptionManagementAlert.set_x(left);
        DialogSubscriptionManagementAlert.set_y(top);
        DialogSubscriptionManagementAlert.Show();
        if (DialogSubscriptionManagementAlert.get_isShowing())
        {
            window.clearInterval(intervalOpenDialog);
        }
    }
    catch (err)
    {
    }
}

/**********************************************************/
// ???

function dialogshow(dialog)
{
    // document.getElementById("status").innerHTML = dialog.get_id()+" shown";
    // document.getElementById("result").innerHTML = dialog.get_result();
    //alert("dialogshow");
    infoDialog.set_x(50);
    infoDialog.set_y(50);

}

function dialogclose(dialog)
{
    //  document.getElementById("status").innerHTML = dialog.get_id()+" closed";
    //  document.getElementById("result").innerHTML = dialog.get_result();
    //  document.getElementById('showclose').value = 'Show Dialog';
    //alert("dialogclose");
    if (dialog.get_result() == 'OK click')
    {
        link = document.getElementById("LinkUrl").value;
        title = document.getElementById("LinkTitle").value;
        target = document.getElementById("LinkTarget").options[document.getElementById("LinkTarget").selectedIndex].value;
        //document.getElementById("result").innerHTML = dialog.get_result()+' ( <a href="'+link+'" target="'+target+'">'+title+'</a> )';
    }
}

function dialogdrag(dialog)
{
    document.getElementById("status").innerHTML = dialog.get_id()+" drag started";
    document.getElementById("position").innerHTML = "x: "+dialog.get_x()+" y: "+dialog.get_y();
}
function dialogdrop(dialog)
{
    document.getElementById("status").innerHTML = dialog.get_id()+" dropped";
    document.getElementById("position").innerHTML = "x: "+dialog.get_x()+" y: "+dialog.get_y();
}
function dialogfocus(dialog)
{
    document.getElementById("status").innerHTML = dialog.get_id()+" focused";
}

function alignmentchange(sender, eventargs)
{
    Dialog1.set_x(null);
    Dialog1.set_y(null);
    Dialog1.set_alignment(sender.getSelectedItem().Value);
}
function update()
{
		Dialog1.beginUpdate();
		Dialog1.set_value(document.getElementById('dialogvalue').value);
		Dialog1.set_title(document.getElementById('dialogtitle').value);
		Dialog1.set_icon(ComboBox2.getSelectedItem().Value);
		Dialog1.endUpdate();
}
function populate()
{
		document.getElementById('dialogvalue').value = Dialog1.get_value();
		document.getElementById('dialogtitle').value = Dialog1.get_title();
}
function toggle()
{
	if(Dialog1.get_isShowing())
	{
		Dialog1.Close();
		document.getElementById('showclose').value = 'Show Dialog';
	}
	else
	{
	  Dialog1.Show();
		document.getElementById('showclose').value = 'Close Dialog';
	}
}

function animationstyle(sender, eventargs)
{
		switch(sender.getSelectedItem().Value)
		{
			case '0':	// None
			  Dialog1.beginUpdate();
			  Dialog1.set_showTransition(0);
			  Dialog1.set_closeTransition(0);
				Dialog1.set_animationType('None');
				Dialog1.set_animationPath('Direct');
				Dialog1.endUpdate();
				break;
			case '1':	// Windows Vista
			  Dialog1.beginUpdate();
			  Dialog1.set_showTransition(3);				// Fade
				Dialog1.set_closeTransition(3);				// Fade
			  Dialog1.set_animationSlide(2);				// ExponentialDecelerate
			  Dialog1.set_animationDirectionElement('Dialog1');
				Dialog1.set_animationType('Live');
				Dialog1.set_animationPath('Direct');
				Dialog1.set_animationDuration(600);
				Dialog1.set_transitionDuration(100);
				Dialog1.endUpdate();
				break;
			case '2':	// Outline
				Dialog1.beginUpdate();
			  Dialog1.set_showTransition(0);
				Dialog1.set_closeTransition(0);
			  Dialog1.set_animationSlide(3);				// Linear
			  Dialog1.set_animationDirectionElement('showclose');
				Dialog1.set_animationType('Outline');
				Dialog1.set_animationPath('Direct');
				Dialog1.set_animationDuration(200);
				Dialog1.set_transitionDuration(200);
				Dialog1.endUpdate();
				break;
			case '3':	// Basic
				Dialog1.beginUpdate();
			  Dialog1.set_showTransition(3);
				Dialog1.set_closeTransition(3);
			  Dialog1.set_animationSlide(3);				// Linear
			  Dialog1.set_animationDirectionElement('showclose');
				Dialog1.set_animationType('Live');
				Dialog1.set_animationPath('Direct');
				Dialog1.set_animationDuration(400);
				Dialog1.set_transitionDuration(400);
				Dialog1.endUpdate();
				break;
			case '4':	// Boomerang
			  Dialog1.beginUpdate();
			  Dialog1.set_showTransition(3);				// Fade
				Dialog1.set_closeTransition(3);				// Fade
			  Dialog1.set_animationSlide(4);				// QuadraticAccelerate
			  Dialog1.set_animationDirectionElement('showclose');
				Dialog1.set_animationType('Live');
				Dialog1.set_animationPath('Boomerang');
				Dialog1.set_animationDuration(500);
				Dialog1.set_transitionDuration(500);
				Dialog1.endUpdate();
				break;
		}
}


function setTabAble(id, index, setfocus)
{
    var obj = document.getElementById(id);

    obj.tabIndex = index;
    obj.tabEnabled = true;

    if (setfocus)
    {
     // alert("setting focus for" + id);
      obj.focus();
    }
}

