﻿//<!--

function $$(id)
{
    return document.getElementById(id);
}

function ObjectWrite(value){
    document.write(value);
}

function trim(value){
    return rtrim(ltrim(value));    
}

function ltrim(value){
    var v_length = value.length;
    if(v_length < 1){
        return"";
    }
    var w_space = String.fromCharCode(32);
    var strTemp = "";

    var iTemp = 0;

    while(iTemp < v_length){
        if(value.charAt(iTemp) != w_space){
            strTemp = value.substring(iTemp, v_length);
            break;
        }
        iTemp = iTemp + 1;
    } //End While
    
    return strTemp;
    
}

function rtrim(value){
    var w_space = String.fromCharCode(32);
    if(v_length < 1){
        return "";
    }    
    
    var strTemp = value;
    var v_length = value.length;
    var iTemp = v_length;

    while(iTemp > 0){
        if(value.charAt(iTemp) != w_space){
            strTemp = value.substring(0, iTemp);
            break;
        }else if (iTemp == 1){
            strTemp = "";
            break;
        }else{        
            iTemp = iTemp - 1;
        }
    } //End While
    
    return strTemp;
}

function isEmail(elm) {
	if (elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value != "")
	    return true;
	return false;
} 
 
function isFilled(elm) {
	if (elm.value == "" || elm.value == null)
	    return false;
	return true;
}

function clickControlOnEnter(event, id){
    if (isEnter(event)){
        $$(id).click();
        return false;
    }
}

function isEnter(event){
    if (event.keyCode == 13){
        return true;
    }
    return false; 
}

function textCounterMax(textctl, countctl, maxlimit) {
  if (textctl.value.length > maxlimit){ // if too long...trim it!
    textctl.value = textctl.value.substring(0, maxlimit);
  } else { // update 'characters left' counter
    countctl.innerHTML = maxlimit - textctl.value.length;
  } 
}

function textCounter(textctl, countctl) {
    countctl.innerHTML = textctl.value.length;
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function DateAsUTC(dateString){
    var localDate = new Date(dateString);
    var utcDate = new Date(Date.UTC(localDate.getFullYear(), localDate.getMonth(), localDate.getDate(), localDate.getHours(), localDate.getMinutes(), localDate.getSeconds(), localDate.getMilliseconds()));
    return utcDate;
}

function formatLocalTimeFromUTC(utcDate){
  var hour = utcDate.getHours();
  var min = utcDate.getMinutes();
  var sec = utcDate.getSeconds();
  var AMPM = ' AM';
  var returnvalue = '';

  if (hour == 12){
    returnvalue='12';
    AMPM=' PM';
  }else if (hour > 12){
    returnvalue=(hour - 12).toString();
    AMPM=' PM';
  }else if (hour == 00){
    returnvalue='12';
  }else{
    returnvalue=hour.toString();
  }
  
  returnvalue=returnvalue+':';
  
  if (min <= 9) {
    returnvalue=returnvalue+'0';
  }
  returnvalue=returnvalue+min.toString();   
  returnvalue=returnvalue+AMPM;
  returnvalue=returnvalue

  return returnvalue;
}

/*
	StreamAudio Player Launch
*/

if(navigator.appVersion.indexOf("AOL") > -1)
{
	//AOL
	var opt1 = 'width=472,height=257';
	var opt2 = 'width=472,height=257';
} else if(navigator.platform.indexOf("Win") > -1)	{
	//IE and NS Windows
	var opt1 = 'width=472,height=257,top=420,left=520,screenY=420,screenX=520';
	var opt2 = 'width=472,height=257,top=250,left=300,screenY=250,screenX=300';
} else if(navigator.platform.indexOf("Mac") > -1)	{

	//IE and NS Mac
	if(navigator.appName.indexOf("Microsoft") > -1)	{
	var opt1 = 'width=455,height=270,top=420,left=520,screenY=420,screenX=520';
	var opt2 = 'width=455,height=270,top=250,left=300,screenY=250,screenX=300';
	} else if(navigator.appName.indexOf("Netscape") > -1)	{
	var opt1 = 'width=472,height=277,top=420,left=520,screenY=420,screenX=520';
	var opt2 = 'width=472,height=277,top=250,left=300,screenY=250,screenX=300';
	}
}

function openPlayer(URL)
{
   if(screen.width >= 1000)	{
	   window.open(URL,'Streamaudio_Player',opt1);
	}

   if(screen.width <= 800) {
      window.open(URL,'Streamaudio_Player',opt2);
	}
}

function openPhotoAlbum(Url){
   var photooptwidth = 820;
   var photooptheight = 593;
   if (navigator.platform.indexOf('Mac') > -1) {
      if (navigator.appName.indexOf('Netscape') > -1){
         photooptwidth = photooptwidth + 2;
         photooptheight = photooptheight + 4;
      }
   }
   var photooptleft = screen.availWidth / 2 - (photooptwidth / 2);
   var photoopttop = screen.availHeight / 2 - (photooptheight / 2);
   var photoopt = photoopt = 'width=' + photooptwidth.toString() + ',height=' + photooptheight.toString() + 'top=' + photoopttop.toString() + ',left=' + photooptleft.toString() + ',screenY=' + photoopttop.toString() + ',screenX=' + photooptleft.toString();

	var windw = window.open(Url,'Photo_Album',photoopt);
	if (windw != null) windw.focus();
}

//-->