﻿// Removes leading whitespace
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes trailing whitespace
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and trailing whitespace
function trim( value ) {
	return LTrim(RTrim(value));
}
// If the String object doesn't have a trim method add one.
if(typeof "".trim == "undefined"){
	// Trim leading and trailing spaces from a string.
	String.prototype.trim = function(str) {
		str = this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
}


function SwapVideo(videoId)
{
    var VideoCode = "<div style='height:350px; width:425px; text-align:center;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/" + videoId +
                    "'></param><embed src='http://www.youtube.com/v/" + videoId + "' type='application/x-shockwave-flash' width='425' height='350'></embed></object></div>";
    var VideoContainer = document.getElementById("MainVideo");
    
    VideoContainer.innerHTML = VideoCode;
}


function inputCounter(field, countfield, maxlimit, action) {
	objField = document.getElementById(field);
	objCountField = document.getElementById(countfield);
	
	if (objField.value.length > maxlimit) 
		objField.value = objField.value.substring(0,maxlimit);
	else 
		objCountField.innerHTML = maxlimit - objField.value.length;
}

// ****************************************************************************
//myField accepts an object reference, myValue accepts the text strint to add
function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();

        //in effect we are creating a text range with zero
        //length at the cursor location and replacing it
        //with myValue
        sel = document.selection.createRange();
        sel.text = myValue;
    }

    //Mozilla/firefox/Netscape 7+ support
    else if (myField.selectionStart || myField.selectionStart == '0') {

            //Here we get the start and end points of the
            //selection. Then we create substrings up to the
            //start of the selection and from the end point
            //of the selection to the end of the field value.
            //Then we concatenate the first substring, myValue,
            //and the second substring to get the new value.
            var startPos = myField.selectionStart;
            var endPos = myField.selectionEnd;
            myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
        } 
    else {
    myField.value += myValue;
    }
}
// -------------------------------------------------------------------------------

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=715,height=450');");
}

function stripTags(s){
	s = s.replace(/<br \/>/gi,"\r");
	s = s.replace(/<br\/>/gi,"\r");
	s = s.replace(/<br>/gi,"\r");
    s = s.replace(/<.*\/>/gi,"");
    s = s.replace(/<.*>/gi,"");
    s = s.replace(/<\/.*>/gi,"");
    return s;
}