
//--------------------------------------------------------------------
//  File:       sivasoftware.js
//  Project:    SivaSoftware web site
// 
//  Date:       24.05.05
//  Author:     Gernot Walterskirchen
//  Contact:    www.sivasoftware.com
//--------------------------------------------------------------------

// contents button ids
var aButtonIds = new Array("company", "solutions", "contact", "downloads", "links");
	
function OnLoadContents()
{
	// force page into frame
	if (top == self) 
	{
	    // use frame instead of single page
	    top.location.replace("frame.aspx");
	    return;
	}

	// preload button images
	PreloadImgs(
		"images/btn_company1.gif", 
		"images/btn_company2.gif",
		"images/btn_company3.gif",
		"images/btn_solutions1.gif", 
		"images/btn_solutions2.gif", 
		"images/btn_solutions3.gif", 
		"images/btn_contact1.gif", 
		"images/btn_contact2.gif", 
		"images/btn_contact3.gif", 
		"images/btn_downloads1.gif", 
		"images/btn_downloads2.gif",
		"images/btn_downloads3.gif",
		"images/btn_links1.gif", 
		"images/btn_links2.gif",
		"images/btn_links3.gif");
}

function OnLoadBanner()
{
	// force page into frame
	if (top == self) 
	{
	    // use frame instead of single page
	    top.location.replace("frame.aspx");
	    return;
	}
}

function OnLoadDownloads()
{
    SetContents('downloads');
		 
    PreloadImgs(
		"images/btn_prog_download1.gif", 
        "images/btn_prog_download2.gif");
}

function OnLoadContact()
{
    SetContents('contact');
    
    // intitialize
    if (ContactForm.EMailInit.value == "")
    {
        ContactForm.EMail.style.color = "#000000";
        ContactForm.EMail.value = FieldRequired;
    }
    
    if (ContactForm.TextInit.value == "")
    {
        ContactForm.Text.style.color = "#000000";
        ContactForm.Text.innerHTML = FieldRequired;
    }
}

function BtnNormal(id)
{
	BtnSet(id, '0');
    window.status = "";
}

function BtnHover(id)
{
	BtnSet(id, '1');
    window.status = "";
}

function BtnPress(id)
{
	BtnSet(id, '2');
    window.status = "";
}

function BtnCheck(id)
{
	BtnSet(id, '3');
		
	// reset all other contents buttons
	for (var i = 0; i < aButtonIds.length; i++)
	{
		var oButton = document.getElementById(aButtonIds[i]);
		
		if (!oButton) return;
		
		if (id == aButtonIds[i])
			oButton.checked = true;
		
		else
		{
			oButton.checked = false;
			oButton.src = "images/btn_" + aButtonIds[i] + "0.gif";
		}
	}
}

function BtnSet(id, n)
{
	var oButton = document.getElementById(id);
	
	if (oButton && !oButton.checked)    // oButton.checked evaluates false if undefined
	{
		// treat program download buttons all the same
		if (id.substr(0, 13) == "prog_download")
			oButton.src = "images/btn_prog_download" + n + ".gif";
			
		else
			oButton.src = "images/btn_" + id + n + ".gif";
	}
}

function Download(id, fromParent)
{
    BtnHover(id);
    
    var img = new Image;
    var folder = fromParent? "../": "";
    
    if (id == "prog_download_sivsudoku")
    {
        self.location.href = folder + "sivsudoku/sivsudoku10.msi";  
        img.src = folder +  "counter.asp?id=download_sivsudoku"
    }
    
    else if (id == "prog_download_sivplugin")
    {
        self.location.href = folder + "sivplugin/sivplugin10.exe";  
        img.src = folder + "counter.asp?id=download_sivplugin"
    }
    
    else if (id == "prog_download_comptools")
    {
        self.location.href = folder + "comptools/comptools.msi";  
        img.src = folder + "counter.asp?id=download_comptools"
    }
    
    else if (id == "prog_download_foldertools")
    {
        self.location.href = folder + "foldertools/foldertools.msi";  
        img.src = folder + "counter.asp?id=download_foldertools"
    }
    
    else if (id == "prog_download_zipit")
    {
        self.location.href = folder + "zipit/zipit.msi";  
        img.src = folder + "counter.asp?id=download_zipit"
    }
    
    else if (id == "prog_download_iging")
    {
        self.location.href = folder + "i-ching/i-ching.msi";  
        img.src = folder + "counter.asp?id=download_iging"
    }
}

function SetContents(name)
{
	// force page into frame
	if (top == self) 
	{
	    // use frame instead of single page
	    top.location.replace("frame.aspx?page=" + name);
	    return;
	}

	try
	{
	    // check contents button
	    top.contents.BtnCheck(name);
    	
	    // set title
	    if      (name == "home")      SetTitle(TitleHome);
	    else if (name == "company")   SetTitle(TitleCompany);
	    else if (name == "solutions") SetTitle(TitleSolutions);
	    else if (name == "contact")   SetTitle(TitleContact);
	    else if (name == "downloads") SetTitle(TitleDownloads);
	    else if (name == "links")     SetTitle(TitleLinks);
    }
    
    catch (e)
    {
	    // contents or banner not loaded yet -> try later
	    window.setTimeout("SetContents(\"" + name + "\")", 100);
    }
}

function SetTitle(text)
{
	var oTitle = top.banner.document.getElementById("id_title");
	if (oTitle) oTitle.firstChild.nodeValue = text;
}

function SetStatus(name)
{
    var txt = "";
    
	if      (name == "company")   txt = StatusCompany;
	else if (name == "solutions") txt = StatusSolutions;
	else if (name == "contact")   txt = StatusContact;
	else if (name == "downloads") txt = StatusDownloads;
	else if (name == "links")     txt = StatusLinks;
	
    if (window.status != txt) window.status = txt; 
}
 
function SetLanguage(langId)
{
    top.location.href = langId + "frame.aspx";
}

function PreloadImgs() 
{
    if (!document.aImages) document.aImages = new Array();

    for (var i = 0; i < arguments.length; i++)
    {
        document.aImages[i] = new Image;
        document.aImages[i].src = arguments[i];
    }
}

function ShowImagePopup(filename, w, h)
{
	var width  = w + 25;
	var height = h + 25;

  	window.open(filename, "Popup", "width=" + width + ",height=" + height + ",resizable=yes");
}

function ValidateContactForm() 
{
	var email  = ContactForm.EMail.value;
	var text   = ContactForm.Text.value;
	
	if (ContactForm.EMailInit.value == "" || 
	    !email.length || email.indexOf("@")==-1 || email.indexOf(".")==-1)
	{
		alert(AlertEMail);
		return false;
	}
	
	if (ContactForm.TextInit.value == "" || !text.length)
	{
		alert(AlertMsgText);
		return false;
	}
	
	return true;
}

function OnFocusFormField(name)
{
	if (name=="EMail" && ContactForm.EMailInit.value == "")
	{
        ContactForm.EMail.style.color = "#0000FF";
        ContactForm.EMail.value = "";
	    ContactForm.EMailInit.value = "init";
	}
	
	if (name=="Text" && ContactForm.TextInit.value == "")
	{
        ContactForm.Text.style.color = "#0000FF";
        ContactForm.Text.innerHTML = "";
	    ContactForm.TextInit.value = "init";
	}
}

