﻿// JScript File
//used in BrandingColourScheme to Fill ColorPickers with predefined colours
function FillColorPickerBoxes(toplinks,header,tabcolour,tabtextcolour,backgroundcolour)
{
    document.getElementById("TopLinks").value = toplinks;
    document.getElementById("HeaderColor").value = header;
    document.getElementById("TabColour").value = tabcolour;
    document.getElementById("TabTextColour").value = tabtextcolour;
    document.getElementById("BackgroundColour").value = backgroundcolour;
    PreviewStyle();
}
function PreviewStyle()
{
   try{
        if (document.getElementById("TopLinks").value.length == 7)
            document.getElementById("preview_top_links").style.color = document.getElementById("TopLinks").value;
           else
           document.getElementById("preview_top_links").style.color = "";
        if (document.getElementById("HeaderColor").value.length == 7)
            document.getElementById("preview_header_colour").style.backgroundColor = document.getElementById("HeaderColor").value;
        else
            document.getElementById("preview_header_colour").style.backgroundColor = "";
        if (document.getElementById("TabColour").value.length == 7)
            document.getElementById("preview_tab_colour").style.backgroundColor = document.getElementById("TabColour").value;
        else
            document.getElementById("preview_tab_colour").style.backgroundColor = "";
        if (document.getElementById("TabTextColour").value.length == 7)
            document.getElementById("preview_tabtxt_color").style.color = document.getElementById("TabTextColour").value;
        else
            document.getElementById("preview_tabtxt_color").style.color == "";
        if (document.getElementById("BackgroundColour").value.length == 7)
            document.getElementById("preview_background").style.backgroundColor = document.getElementById("BackgroundColour").value;
        else
            document.getElementById("preview_background").style.backgroundColor = "";
      }
      catch(err)
      {
        //do nothing
      }
}
function FillColorPickerBoxesPartner(settingslinks,header,tabcolour,tabtextcolour)
{
    document.getElementById("SettingsLink").value = settingslinks;
    document.getElementById("HeaderColor").value = header;
    document.getElementById("TabColour").value = tabcolour;
    document.getElementById("TabTextColour").value = tabtextcolour;
    cs_init();
    PreviewStylePartner();
}
function PreviewStylePartner()
{
   try{
        if (document.getElementById("SettingsLink").value.length == 7)
            document.getElementById("preview_settings_links").style.color = document.getElementById("SettingsLink").value;
           else
           document.getElementById("preview_settings_links").style.color = "";
        if (document.getElementById("HeaderColor").value.length == 7)
            document.getElementById("preview_header_colour").style.backgroundColor = document.getElementById("HeaderColor").value;
        else
            document.getElementById("preview_header_colour").style.backgroundColor = "";
        if (document.getElementById("TabColour").value.length == 7)
            document.getElementById("preview_tab_colour").style.backgroundColor = document.getElementById("TabColour").value;
        else
            document.getElementById("preview_tab_colour").style.backgroundColor = "";
        if (document.getElementById("TabTextColour").value.length == 7)
            document.getElementById("preview_tabtxt_color").style.color = document.getElementById("TabTextColour").value;
        else
            document.getElementById("preview_tabtxt_color").style.color == "";
   }
   catch(err)
   {
       //do nothing
   }
}
/*submits command information from the page*/
function submitInfo( button ,  command , id )
{
	button.disabled = true; // to prevent multiple clicks
	isSubmit=true;
	document.getElementById("commandName").value = command;
	document.getElementById("commandId").value = id;
	document.forms[0].submit();
}
/*open a dialog and asks for delete schema confirmation. if is ok than it saves the id in an hidden Input and submits the form*/
function deleteSchema( schema_id , schema_name)
{
	if (confirm("Are you sure that you want to delete elertz '" + schema_name + "'"))
	{
		var hid_act = document.getElementById("hidden_action");
		var hid_val = document.getElementById("hidden_value");
		hid_act.value = "delete";
		hid_val.value = schema_id;
		window.document.forms[0].submit();
	}
}
/*open a dialog and asks for delete competition confirmation. if is ok than it saves the id in an hidden Input and submits the form*/
function deleteCompetition( comp_id , comp_name)
{
	if (confirm("Are you sure that you want to delete competition '" + comp_name + "'"))
	{
		var hid_act = document.getElementById("hidden_action");
		var hid_val = document.getElementById("hidden_value");
		hid_act.value = "delete";
		hid_val.value = comp_id;
		window.document.forms[0].submit();
	}
}
/*open a dialog and asks for expiration of competition confirmation. if is ok than it saves the id in an hidden Input and submits the form*/
function expireCompetition( comp_id , comp_name)
{
	if (confirm("Are you sure that you want to expire competition '" + comp_name + "'. No subscribtions will be accepted further if you confirm the command."))
	{
		var hid_act = document.getElementById("hidden_action");
		var hid_val = document.getElementById("hidden_value");
		hid_act.value = "expire";
		hid_val.value = comp_id;
		window.document.forms[0].submit();
	}
}
//show hide RSS field in ToolbarSettings.aspx
function RSS_LinkDisplay(check)
{
    if (check.checked)
       document.getElementById("RSSFeed_Holder").style.display="";
    else
       document.getElementById("RSSFeed_Holder").style.display="none";
}//clipboardCopy
function ToClipBoard(elementName) 
{
	var control = document.getElementById(elementName)
	if (control != null)
	{
		control.focus();
		control.select();
		Copied = control.createTextRange();
		//Copied.execCommand("RemoveFormat"); //removes HTML format and copy only text
		Copied.execCommand("Copy");
	}
	else
		alert ("The control " + elementName + " can not be found on this Web Page!");
}
//number of linnes available in textarea
function setDisplayer(TextBox, Displayer)
{
	if (trim(TextBox.value).length == 0)
	{
	    Displayer.innerHTML = 0;
	    return;
	}
	var splited = trim(TextBox.value).split("\r\n");
	Displayer.innerHTML = splited.length;
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
