// +--------------------------------------+
// | OCTETH TECHNOLOGIES                  |
// | www.octeth.com                       |
// | help@octeth.com                      |
// +--------------------------------------+
// | (c)Copyright Octeth Technologies.    |
// | All rights reserved.                 |
// +--------------------------------------+


// ####################################################################
// Opens a popup window and displays campaign bandwidth
// ----
function DisplayBandwidth(FormName, SourceID, Module)
	{
	if ((SourceID == '0') && (Module == 'send'))
		{
		eval('document.' + FormName + '.form_get_cmd.value="BandwidthCalculator";');
		eval('document.' + FormName + '.target="_blank";');
		eval('document.' + FormName + '.submit();');
		}
	}

// ####################################################################
// Shows or hides the given ID tag
// ----
function ShowHide(TagID)
	{
	TagID = eval(TagID);
    if (TagID.style.display=="none")
		{
		TagID.style.display="";
		}
    else
		{
		TagID.style.display="none";
        }
//	window.event.cancelBubble=true;
	}
// ####################################################################
// Insert selected pre-defined tag into defined field
// ----
function UpdateContent(WhichTag, WhichField)
	{
	if (WhichTag == '%link=%')
		{
		// Link click tracking
		var ReturnVal = prompt("Enter URL to track click statistics (start with http://)");
		ReturnVal = '%link=' + ReturnVal + '%';
//		document.all[WhichField].value = document.all[WhichField].value + ReturnVal;
		editor_insertHTML(WhichField, ReturnVal);
		}
	else if (WhichTag == '%date=%')
		{
		// Custom date
		var ReturnVal = prompt("Please enter the date format (for reference, please click '[Pre-defined tag list']");
		ReturnVal = '%date=' + ReturnVal + '%';
//		document.all[WhichField].value = document.all[WhichField].value + ReturnVal;
		editor_insertHTML(WhichField, ReturnVal);
		}
	else
		{
		// Any other tags (ex: extra fields)
		editor_insertHTML(WhichField, WhichTag);
		}

	
	
	return true;
	}
// ####################################################################
// Jumps to the defined URL from a checkbox
// Options can be:
// ----
function CheckboxJumpMenu (targ,selObj,restore)
	{
	theURL = selObj.options[selObj.selectedIndex].value; 
	if (theURL)
		{
		window.location = theURL;
		}

	/*
	INCOMPATIBLE WITH MAC IE - STARTED
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore)
		{
		selObj.selectedIndex=0;
		}
	INCOMPATIBLE WITH MAC IE - FINISHED
	*/
	
	
	}

// ####################################################################
// Opens a popup browser
// Options can be:
// 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=100,height=100'
// ----
// void OpenBrowser(string URL, string WinName,string WinOptions)
function OpenBrowser(URL,WinName,WinOptions)
	{
	window.open(URL,WinName,WinOptions);
	}
	
// ####################################################################
// Checks email format
// ----
// void ChangeFieldStatus(string email, string message)
function CheckEmail(email, message)
	{
	var str=email;
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		{
		return true;
		}
		else
		{
		alert(message);
		return false;
		}
	}

// ####################################################################
// Changes the status (enabled/disabled) of the given field
// ----
// void ChangeFieldStatus(object which)
function ChangeFieldStatus(which)
	{
	if (which.disabled == true)
		{
		which.disabled = false;
		}
	else
		{
		which.disabled = true;
		}
	return;
	}
	
	
// ####################################################################
// Checks for required fields on the form
// Usage:
// Insert this funtion to the form tag: <form onSubmit="return CheckRequired(this)">
// Add "r" letter to the required fields : <input type="text" name="form_getr_name">
// ----
// void CheckRequired(object which, string message)
function CheckRequired(which, message)
	{
	var pass=true;
	if (document.images)
		{
		for (i=0;i<which.length;i++)
			{
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,10)=="form_getr_")
				{
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1))
					{
					pass=false;
					break;
					}
				}
			}
		}
	if (!pass)
		{
		alert(message);
		return false;
		}
	else
		{
		return true;
		}
	}


// ####################################################################
// Clears form element content on focus
// ----
// void clearText(object thefield)
function clearText(thefield)
	{
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
	} 
	
// ####################################################################
// Returns browser type and version
// ----
// sring checkbrowser()
function checkbrowser()
    {
    var browser_type=navigator.appName
    var browser_version=parseInt(navigator.appVersion)

    //if NS 6
    if (browser_type=="Netscape"&&browser_version>=5)
        {
        return "NS6";
        }
    //if IE 4+
    else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
        {
        return "IE4+";
        }
    //if NS4+
    else if (browser_type=="Netscape"&&browser_version>=4)
        {
        return "NS4+";
        }
    //NOT NS 4+ and NOT IE 4+
    else
        {
        return "N/A";
        }
    }

// ####################################################################
// Does your form contain an "Accept terms" section users must agree to 
// before submitting the form? If so, this script helps enforce it, by 
// disabling the submit button (in IE4+ and NS6+) or process (all other browsers) 
// until he/she checks a box indicating compliance
// Ex: 
// <form name="agreeform" onSubmit="return defaultagree(this)">
// Rest of your form here<br>
// <input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br>
// <input type="Submit" value="Submit!" disabled>
// </form>
//
// change two names below to your form's names
// <script>
// document.forms.agreeform.agreecheck.checked=false
// </script>
// ----
// void agreesubmit(string el)
function agreesubmit(el)
    {
    checkobj=el
    if (document.all||document.getElementById)
        {
        for (i=0;i<checkobj.form.length;i++)
            {
            //hunt down submit button
            var tempobj=checkobj.form.elements[i]
            if(tempobj.type.toLowerCase()=="submit")
                {
                tempobj.disabled=!checkobj.checked
                }
            }
        }
    }

// ####################################################################
// Does your form contain an "Accept terms" section users must agree to 
// before submitting the form? If so, this script helps enforce it, by 
// disabling the submit button (in IE4+ and NS6+) or process (all other browsers) 
// until he/she checks a box indicating compliance
// Ex: 
// <form name="agreeform" onSubmit="return defaultagree(this)">
// Rest of your form here<br>
// <input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br>
// <input type="Submit" value="Submit!" disabled>
// </form>
//
// change two names below to your form's names
// <script>
// document.forms.agreeform.agreecheck.checked=false
// </script>
// ----
// void defaultagree(string el)
function defaultagree(el)
    {
    if (!document.all&&!document.getElementById)
        {
        if (window.checkobj&&checkobj.checked)
            {
            return true
            }
        else
            {
            alert("Please read/accept terms to submit form")
            return false
            }
        }
    }

// ####################################################################
// Changes the bgcolor of tr on "mouse over"
// ----
// void mouse_over(string src, string clrOver)
function mouse_over(src, clrOver)
	{
	if (!src.contains(event.fromElement))
		{
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
		}
	}

// ####################################################################
// Changes the bgcolor of tr on "mouse out"
// ----
// void mouse_out(string src, string clrIN)
function mouse_out(src,clrIn)
	{
	if (!src.contains(event.toElement))
		{
		src.style.cursor = 'default';
		src.bgColor = clrIn;
		}
	}
	
// ####################################################################
// Submits the link if clicked to the <tr>
// ----
// void mouse_click(string src)
function mouse_click(src) 
	{
	if(event.srcElement.tagName=='TD')
		{
		src.children.tags('A')[0].click();
		}
	}

// ####################################################################
// Checks/unchecks checkboxes 
// ----
// boolean checkall(string ownercheckbox, string targetcheckbox, integer formindex)
function checkall(ownercheckbox,targetcheckbox,formindex)
	{	
    // Always forms[0] has been taken because there are more than
    // one forms with the same name in the page. This is causing
    // conflicts. The listing which includes the form should be
    // the first (index 0) form in the page for this function to 
    // work.
    var elts      = document.forms[formindex].elements[targetcheckbox];
    var elts_cnt  = elts.length;
    var do_check  = true;

    owner_checkbox = document.forms[formindex].elements[ownercheckbox];

	if (owner_checkbox.checked == true)
        {
        do_check = true;
        }
    else
        {
        do_check = false;
        }

	for (var i = 0; i < elts_cnt; i++)
		{
		elts[i].checked = do_check;
		} // end for
		
    return true;
	}
