String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,''); }
function $id(id){ return document.getElementById(id); }

function GetFCKContentPlainText(sFCKEditorID, sPainTextFieldID, sDivPlainTextID)
{
	var oEditor = FCKeditorAPI.GetInstance(sFCKEditorID) ;
		
	document.getElementById(sDivPlainTextID).innerHTML=oEditor.GetXHTML(false);
	document.getElementById(sPainTextFieldID).value = GetInnerText(document.getElementById(sDivPlainTextID)); //document.getElementById(divName).innerText;
	
	return true;
}

function GetInnerText(el) {
	var txt = '', i;
	for (i = el.firstChild; i; i = i.nextSibling) {
		if (i.nodeType == 3)
			txt += i.data;
		else if (i.nodeType == 1)
			txt += GetInnerText(i);
	}
	return txt;
}

function setDate( inField, btnName, dateFormat)
{
      Calendar.setup({
        inputField     :    inField,
        ifFormat       :    dateFormat,
        button         :    btnName,
        align          :    "TR",
        singleClick    :    true,
        firstDay	   :	1
    });
}

function setDefaultDateToAttachedControl(oControl, sAttachedDateControlID, sAttachedHiddenDateControlID) {
    var oAttachedDateControl = $id(sAttachedDateControlID);
    var oAttachedHiddenDateControl = $id(sAttachedHiddenDateControlID);
        
    if (oAttachedDateControl==null || oAttachedHiddenDateControl==null) { return; }
    
    if (oAttachedDateControl.value=='') {
        oAttachedHiddenDateControl.value = oControl.value;
    }    
}

function ShowHideObjectByID(sObjectID, bShow)
{
    var oObject = $id(sObjectID);
    
    oObject.style.display = "none";
    //if (bShow==true) { oObject.style.display = "block"; }
    if (bShow==true) { oObject.style.display = ""; }
}

function SetObjectCSSClassByID(sObjectID, sCSSClass)
{
    var oObject = $id(sObjectID);
    
    oObject.className = sCSSClass;    
}

function EnableValidatorByID(sValidatorID, bEnable)
{
    var oValidator = $id(sValidatorID);
    
    oValidator.enabled = bEnable;    
    
    var oAsterix = $id(sValidatorID + '_asterix');
    
    if (oAsterix) {
        if (bEnable) { oAsterix.style.visibility = 'visible'; }
        else { oAsterix.style.visibility = 'hidden'; }
    }
}

function SetValidatorsErrorMessage(sValidatorID, sErrorMessage)
{
    var oValidator = $id(sValidatorID);
    
    oValidator.errormessage = sErrorMessage;    
    oValidator.title = oValidator.errormessage;
}

function SetLabelsText(sLabelID, sText)
{
    var oLabelID = $id(sLabelID);
    
    if (oLabelID!=null) {
        oLabelID.innerHTML = sText;    
    }
}


function PreviewImage(sURL) {	
	popup(sURL, 'PreviewImage', 50, 50, 50, 50, "yes", "no","no");
}

function popup(url, wname, wid, hei, lft, tp, hasScroll, hasMenu, hasToolBar){		
	param = "toolbar="+hasToolBar+",menubar="+hasMenu+",scrollbars="+hasScroll+",resizable=yes,status=yes,location=no";
	
	var newWindow;
	
	if ( document.layers ){
		newWindow = window.open(url, wname, param + ',height='+hei+',width='+wid+',screenX='+lft+',screenY='+tp);
	}else{
		newWindow = window.open(url, wname, param + ',height='+hei+',width='+wid+',left='+lft+',top='+tp);
	}
	
	newWindow.focus();
}

function ShowHideTR(sTrID, sSenderID, sImageID) {      
    var curItem = $id(sTrID);
    var oSender = $id(sSenderID);
    var oImage = $id(sImageID);
    
    if (curItem && oSender)
    {
        if (curItem.style.display != 'none') {
            $id(sTrID).style.display = "none";	        
            if (oSender!=null) { 
                oSender.title = "Show";
                oImage.src="images/show.gif";
            }
        } else {            
            $id(sTrID).style.display = '';           
            if (oSender!=null) { 
                oSender.title = "Close"; 
                oImage.src="images/hide.gif";
            }        
        }    
    }
}

//This script is used to fix the problem with DefaultButtons (ASP.NET hack)
function defaultButtonFix() {
    __defaultFired = false;
} 
 
function getEmail(theName, theExtras, theLink, theDomain) {

var theEmail = theName + "@" + theDomain;

    if (theName == "") {
	
	    theName = "ERROR";
	    theLink = "ERROR";
	    myEmail = theName;
	    myLink = theLink;
	    
    } else {
    
	    if ((theExtras == "") && (theLink =="")){
		    myEmail = theEmail;
		    myLink = theEmail;
	    }
	    
	    if ((theLink == "") && (theExtras != "")){
		    myLink = theEmail;
		    myEmail = theEmail+theExtras;
	    }
	    
	    if 	((theLink != "") && (theExtras != "")){
		    myLink = theLink;
		    myEmail = theEmail+theExtras;
	    }
	    
	    if 	((theLink != "") && (theExtras == "")){
		    myLink = theLink;
		    myEmail = theEmail;
	    }
    }
    
	document.write('<a href="mailto:' + myEmail + '" class="email">' + myLink + '</a>');
}


function DisplayFlashObject(sFlashMovieURL, nMovieWidth, nMovieHeight, sLoop, sQuality, sAltImageURL, sAltImageTooltip) {
	if (!useRedirect) {
		if(hasRightVersion) {
			var oeTags = ""
			oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'width="' + nMovieWidth + '"  height="' + nMovieHeight + '" id="myMovieName"'
			+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,4,0" >'
			+ '<param name="movie" value="' + sFlashMovieURL + '" /><param name="quality" value="' + sQuality + '" />'
			//+ '<param name="bgcolor" value="#FFFFFF" />'
			+ '<param name="wmode" value="transparent" />'			
			+ '<param name="loop" value="' + sLoop + '" />'
			+ '<embed src="' + sFlashMovieURL + '" quality="high" ' //bgcolor="#FFFFFF" '
				+ 'width="' + nMovieWidth + '" height="' + nMovieHeight + '" name="myMovieNames" '
				+ 'play="true" '
				+ 'wmode="transparent" '
				+ 'loop="' + sLoop + '"'
				+ 'quality="' + sQuality + '"'
				+ 'allowScriptAccess="sameDomain"'
				+ 'type="application/x-shockwave-flash"'
				+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
			+ '<\/embed>'
          + '<\/object>';
          document.write(oeTags);   // embed the Flash Content SWF when all tests are passed
      }
      /* flash is too old or we can't detect the plugin */
      else {
          oeTags = '<img src="' + sAltImageURL + '" width="' + nMovieWidth + '" height="' + nMovieHeight + '" alt="' + sAltImageTooltip + '" title="' + sAltImageTooltip + '" border="0" usemap="#map1" />';
          document.write(oeTags);
      }
  }
}

function PreventSubmitOnKeyPress(sObjectID) {
    try {
        if (!document.all) {
            var oObject = $id(sObjectID);
            
            if (oObject.addEventListener) {  
                oObject.parentNode.addEventListener("keypress", 
                    function(e) { 
                        if (e && e.keyCode && e.keyCode==13) {
                            e.stopPropagation(); 
                        }
                    }, false);  
            }  
        }
    } catch (e) {}
} 

function SelectAllItemsInDDL(oDDL)
{		
	for (i = 0; i < oDDL.options.length; i++) {
		oDDL.options[i].selected=true; 	
		oDDL.options[i].is_clicked=true;
	}
}

function SelectAllItemsInDDLByID(sDDL_ID){
	var oDDL = document.getElementById(sDDL_ID);
	
	SelectAllItemsInDDL(oDDL)
}

function DeselectAllItemsInDDL(oDDL)
{		
	for (i = 0; i < oDDL.options.length; i++) {
		oDDL.options[i].selected=false; 	
		oDDL.options[i].is_clicked=false;
	}
}

function DeselectAllItemsInDDLByID(sDDL_ID){
	var oDDL = document.getElementById(sDDL_ID);
	
	DeselectAllItemsInDDL(oDDL)
}

function GoToPreviousStepURL(sURL, bCheckForChanges) {
    //location.href=sURL;
    promptBeforeExiting(sURL);
}

function EmailThisPage()
{
    mail_str = "mailto:?subject=Check out this page: " + document.title;
    mail_str += "&body=I thought you might be interested in the '" + document.title + "' page";
    mail_str += ". You can view it at: " + location.href;
    location.href = mail_str;
}

function IsChecked(chkID)
{
	var objChk = document.getElementById(chkID);

	return objChk.checked;
}
