function ClearIf(control, value)
{
    if (control.value == value)
    {
        control.value = "";
        control.style.color = "Black";
    }
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
/*
function previewPage(page_id)
{
    window.open('/preview.aspx?page=' + page_id + '&type=preview', 'page_preview', 'toolbar=no, menubar=no, location=yes, resizable=yes, scrollbars=yes');
}
*/

function ToggleTabs(tab_id)
{
    for(index = 1; index < 5; index++)
    {
        var tab = document.getElementById('Tab' + index);
        var value = document.getElementById('Tab' + index + '_Value');
        
        if (tab.id == tab_id)
        {
            value.style.display = '';
            tab.style.backgroundColor = '#f5e1d1';
        }
        else
        {
            value.style.display = 'none';
            tab.style.backgroundColor = '#efefef';
        }
    }
}

function ToggleView(element_id)
{
    var e = document.getElementById(element_id);
    if (e.style.display == '')
        e.style.display = 'none';
    else
        e.style.display = '';
}

function SwapView(element_id, id2)
{
    var x = document.getElementById(element_id);
    var y = document.getElementById(id2);
    
    if (x.style.display == '')
    {
        x.style.display = 'none';
        y.style.display = '';
    }
    else
    {
        x.style.display = '';
        y.style.display = 'none';
    }
}

function ToggleButton(button, element_id)
{
    var e = document.getElementById(element_id);
    if (e.style.display == '')
    {
        button.src = '/images/expand-button.gif';
        e.style.display = 'none';
    }
    else
    {
        button.src = '/images/contract-button.gif';
        e.style.display = '';
    }
}

function ToggleButton2(button, element_id)
{
    var e = document.getElementById(element_id);
    if (e.style.display == '')
    {
        button.src = '/images/arrow-hidden.gif';
        e.style.display = 'none';
    }
    else
    {
        button.src = '/images/arrow-view.gif';
        e.style.display = '';
    }
}

function AddItem(control_id, values_id, item_value, item_text)
{
    var control_values = document.getElementById(values_id).value;
    var item_list = document.getElementById(control_id).innerHTML;
    item_list = item_list.replace(/&amp;/g,'&');
    
    var locations = document.getElementById('locations');
    
    if (item_list.match(">" + item_text + "<"))
    {
        item_list = item_list.replace('<A href="javascript:RemoveItem(\'' + control_id + '\',\'' + values_id + '\',' + item_value + ',\'' + item_text + '\')">' + item_text + '</A>, ','');
        control_values = control_values.replace(','+item_value+',',',');
        if (locations != null && control_id != 'tags') locations.value = locations.value.replace(item_text + '/','');
    }
    else
    {
        item_list += '<a href="javascript:RemoveItem(\'' + control_id + '\',\'' + values_id + '\',' + item_value + ',\'' + item_text + '\')">' + item_text + '</a>, ';
        control_values += item_value+',';
        if (locations != null && control_id != 'tags') locations.value += item_text + '/';
    }

    document.getElementById(control_id).innerHTML = item_list;
    document.getElementById(values_id).value = control_values;
}

function RemoveItem(control_id, values_id, item_value, item_text)
{
    var locations = document.getElementById('locations');
    var control_values = document.getElementById(values_id).value;
    var item_list = document.getElementById(control_id).innerHTML;
    item_list = item_list.replace(/&amp;/g,'&');
    item_list = item_list.replace('<A href="javascript:RemoveItem(\'' + control_id + '\',\'' + values_id + '\',' + item_value + ',\'' + item_text + '\')">' + item_text + '</A>, ','');
    document.getElementById(control_id).innerHTML = item_list;
    control_values = control_values.replace(','+item_value+',',',');
    document.getElementById(values_id).value = control_values;
    if (locations != null && control_id != 'tags') locations.value = locations.value.replace(item_text + '/', '');
}

function validateEmailAddress(e)
{
    if (e.value == '') return true;
    
    var email = e.value;
    
	var at="@"
	var dot="."
	var lat=email.indexOf(at)
	var lstr=email.length
	var ldot=email.indexOf(dot)
	
	if (email.indexOf(at)==-1) return false;
	
	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr) return false;
	
	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr) return false;
	
	if (email.indexOf(at,(lat+1))!=-1) return false;

	if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot) return false;

	if (email.indexOf(dot,(lat+2))==-1) return false;
	
	if (email.indexOf(" ")!=-1) return false;

    e.style.borderColor = '#cccccc';
    
	return true					
}