﻿

var IsOpra8 = navigator.userAgent.indexOf('Opera 8') > -1 || navigator.userAgent.indexOf('Opera/8') > -1;
//var IsIE=navigator.userAgent.indexOf('MSIE')>-1;
var IsIE=navigator.appName=='Microsoft Internet Explorer'
var IsFirefox=navigator.userAgent.indexOf('Firefox')>-1
var IsNetscape=navigator.appName=='Netscape'
var IsNetscape6 = navigator.userAgent.indexOf('Netscape6') > -1;
var SupportAjaxPost = !(IsNetscape6 || IsOpra8);

function setEnterSubmitForTextBox(TextBox,CommandButtonName)
{
  if(document.captureEvents)
     document.captureEvents(Event.KEYPRESS);
  if(typeof TextBox =='string')TextBox=document.getElementById(TextBox)   
  var prevonkeypressEvent=  TextBox.onkeypress
  TextBox.onkeypress=function(e)
     {
       if(getkeyCode(e)==13)
          {
           if(typeof CommandButtonName =='string')      
               __doPostBack(CommandButtonName,'');
           else (typeof CommandButtonName =='object') 
             {
              if(CommandButtonName.onclick)
                 if(CommandButtonName.onclick()==false)
                    return false;     
              if(CommandButtonName.tagName)
              if(CommandButtonName.tagName.toUpperCase()=='A')
                 {if(CommandButtonName.href!='')
                     document.location.href=CommandButtonName.href;}
              }
          }
          if(this.prevonkeypressEvent!=null)
             this.prevonkeypressEvent(e)
     }   
}


function setEnterEventForTextBox(TextBox,FunctionNane)
{
  if(document.captureEvents)
     document.captureEvents(Event.KEYPRESS);
  if(typeof TextBox =='string')TextBox=document.getElementById(TextBox)     
  TextBox.onkeypress=function(e)
     {
       if(getkeyCode(e)==13)
          {                     
            FunctionNane();            
            var tbBox=e?e.target:event.srcElement;
            var evt=document.all?event:e;
            evt.cancelBubble=true ;   
             return false;  
          }
     }   
}


function getkeyCode(e)
{ var keyPressed;
   if(document.all)
       {keyPressed = window.event.keyCode;}
    else
       {if(e.which) keyPressed= e.which;
        else keyPressed = e.keyCode;}
    return keyPressed;
}
if(document.captureEvents)
   document.captureEvents(Event.KEYPRESS);

function NumericTextBox_onkeypress(e)
{
 //var tbBox=e?e.target:event.srcElement;
  var tbBox; 
 if((typeof e)=='undefined')
   tbBox= event.srcElement;
 else
   tbBox= e.target;
   
 var evt=document.all?event:e;
 var key=0;
 key=getkeyCode(evt) 
 if(key==8 || key==0)return true;   
 if(key==39 || key==37)return true;
 if(key>=48 && key <=57)
    {return true;}
   if(key==46)
      {if(tbBox.value.indexOf('.')==-1)
           return true}      
 evt.cancelBubble=true     
 return false; 
}





function _get(id){return getElementById(id)}
function getElementById(id)
{
 if(document.all)
    return document.all(id)
  else
    return document.getElementById(id);
}

function __SubmitForm(http_url,method)
{
try{
  var form=document.createElement("Form");
  if(!method)method="POST";
  form.method=method;
  var cmdL=new String();
  var action;
  var int_indx=http_url.indexOf("?",0);
  if(int_indx!=-1)
     {cmdL=http_url.substr(int_indx+1,http_url.length-int_indx);
      action=http_url.substring(0,int_indx);
     }
    else
     {
      action=http_url;
     } 
    
  if(!action)action=document.location.href;
  if(action.indexOf("?")!=-1)action=action.substring(0,action.indexOf("?"))
  form.action=action;
  
  if(arguments.length ==3)form.target=arguments[2];

  var args;
  if(cmdL.indexOf("&")!=-1)
     {args=cmdL.split("&");}
  else
     {args=[cmdL];}
  
  var cnt=0,arg="";
  for(var i=0;i<args.length;i++)
       {arg=args[i];
        prN=""; prV="";
        if(arg.indexOf("=")!=-1)
           { prN =arg.substr(0,arg.indexOf("=",0));
             prV =arg.substring(arg.indexOf("=")+1,arg.length);}
        else{prN=arg;}
        
        if(prN!="")
          {
           var elem=document.createElement("INPUT");
           elem.type="hidden";
           elem.name=prN;
           elem.value=prV;
           cnt++;
           form.appendChild(elem);
          }
       }
  document.body.appendChild(form)
  form.submit()
}
catch(e)
 {
  NavigateToURL(http_url);}
}



function replace(text,findWhat,replaceWith)
{
 var reg=new RegExp(findWhat.toString(),"g");
 reg.ignoreCase=true;
 reg.multiline=true;
 return text.replace(reg,replaceWith);
}

function trim(str)
{return str.replace(/^[ ]*(.*[^ ])*[ ]*$/ig,"$1");}




function Val(str)
{
 str=trim(str);
 str=str.replace(/[,]*/ig,"")
 if(str.match(/^(-){0,1}\d{0,}(.){0,1}\d{1,}$/))
   return eval(str)
 else
   return 0;
}

function IsValedEMail(sEmail)
{var strRegExp=/[\w]{1}[\w+-.]{1,}[@][\w]{2,}[.][\W\w]{1,}$/i;
 return sEmail.search(strRegExp)==0;
}

function toMoney(Amount)
{
   Amount=Amount.toString();
   if(Amount.indexOf('.')==-1)
     Amount+=".00";
   else
    {
     var index=Amount.indexOf('.');
     var len=Amount.substring(index+1).length;
     if(len==1)
       Amount+='0';
     else if (len>2)
       Amount=Amount.substring(0,index+3)
   }
   return '$'+Amount;
}


function toDecimalMoney(Amount)
{
   Amount=Amount.toString();
   Amount=Amount.replace(/[,]*/ig,"")
   var dec;
   var index=Amount.indexOf('.');
   if(index==-1)
      {
       dec='00'; 
      }
   else
     {
     dec=Amount.substring(index+1)
       Amount=Amount.substring(0,index)       
     }
   var len=Amount.length;    
   var retValue='';
   var d=0;
   var counter=0;
   for(var i=0;i<len;i++)
   {     
     counter++;
     retValue=Amount.substring(len-i-1,len-i)+retValue
     if(counter % 3 ==0 && i != 0 && i != len-1)
      retValue=','+retValue;
   }
   if(retValue=='')return ''
   return retValue+'.'+dec;
}


function NavigateToURL(url,target)
{ 
 if(target)
   {
    if(target!='')
       {
        window.open(url,target);
        return;
       }
   }
    location.href=url;
   if(IsOpra8)
   {setTimeout('ReNavigateToURL("'+url+'")',50)}
}

function ReNavigateToURL(url)
{location.href=url;
 return;
// var a=document.createElement("A"); 
// a.setAttribute('href',url);
// a.click()
}





function OpenWindow(filename, name, width, height, focus) {
    if (!width) width = screen.width;
    if (!height) height = screen.height;

    var x = (screen.width - width) / 2
    var y = (screen.height - height) / 2;
    var win= window.open(filename, name, "scrollbars=no,toolbar=no,resizable=no,width=" + width + ",height=" + height + ",top=" + y + ",left=" + x);
    if (focus && win)
        win.focus();
}














  var isW3C=true;
  
  function GetScrollTop()
  {
    //return document.documentElement.scrollTop;
    return (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  }
  function GetScrollLeft()
  {
    //return document.documentElement.scrollLeft;
    return  (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  }
  function GetWidth()
  {
    if(window.innerWidth)
         return window.innerWidth 
   return document.documentElement.clientWidth;
  }
  function GetHeight()
  {
  if(window.innerHeight)
     return window.innerHeight
   return document.documentElement.clientHeight;
  }
  function GetFullHeight()
  {  
   var h=document.body.offsetHeight;
   if(!h)
      {
      if(window.innerHeight)
         h=window.innerHeight 
      else
        h=GetHeight()
     }  
    return h;     
  }
  function GetFullWidth()
  {  
   var w=document.body.offsetWidth;
   if(!w)
      {
      if(window.innerWidth)
         w=window.innerWidth 
      else
         w=GetWidth()
     }  
    return w;     
  }
  
  
  
  
  function GetElementWidth(ElementId)
  {
   var Element=(typeof ElementId).toLowerCase()=='string'? _get(ElementId):ElementId;
   if(Element)
      {
       if(Element.offsetWidth && Element.offsetWidth>0)
          return Element.offsetWidth;  
          
       if(Element.clientWidth && Element.clientWidth>0)
          return Element.clientWidth;     
      }
   return 0;
  }  
  function GetElementHeight(ElementId)
  {
    var Element=(typeof ElementId).toLowerCase()=='string'? _get(ElementId):ElementId;
   //if(Element)return Element.clientHeight
   if(Element)
      {
       if(Element.offsetHeight && Element.offsetHeight>0)
          return Element.offsetHeight; 
       if(Element.clientHeight && Element.clientHeight>0)
          return Element.clientHeight;      
      }
   return 0;
  }
  
  
 
  
 
  function Centerize(Element)
  {
  var w=Element.clientHeight;
  var h=Element.clientWidth;
  var x,y
   x=GetScrollLeft()+
         ((GetWidth()-w)/2)
    y=GetScrollTop()+
         ((GetHeight()-h)/2)
    Element.style.top=y+'px';
    Element.style.left=x+'px';
    //Element.style.width=w+'px';
    Element.style.height=h+'px';      
  }
  
  
  
  
function ShowPanelOnElement(ElementId,PanelId,sender,e)
{
  var x,y;
  var PageX,PageY;
  if (!e) { var e = window.event; };//IE 
  if(e.x || e.y)
  {
    PageX=e.x;PageY=e.y;
    //if(document.all)   PageX+=2;PageY+=2;    
  }
  else
  {
   if (e.pageX || e.pageY)
        {/*Moz*/ PageX= e.pageX;PageY = e.pageY;}
        else if (e.clientX || e.clientY)
        {/*IE*/ 
          PageX = e.clientX - 2;
          PageY = e.clientY - 2;//IE correction 
        }
  }
  //alert(PageY)
  var Element=_get(ElementId);
  var Width  = GetElementWidth(Element),
      Height = GetElementHeight(Element);

  var oX =Element.offsetLeft;
  var oY =Element.offsetTop;  
  while(Element.parentNode)
  {// finds the absolute position of the object        
   //if(!(Element.tagName=='TR' || Element.tagName=='TBODY' || Element.tagName=='TABLE'))
   if(!(Element.tagName=='TBODY') && !(Element.tagName=='TR'))
    {
     oX=oX+Element.parentNode.offsetLeft; 
     oY=oY+Element.parentNode.offsetTop; 
    }
   if(Element==document.getElementsByTagName('body')[0]){break} 
   else{Element=Element.parentNode;} 
  } 
 
   if(IsIE || IsFirefox) 
   { 
    if(oX>=4)oX-=4;
    if(oY>=4)oY-=2;    
   }
  var Panel=_get(PanelId);
  Panel.style.width =Width+'px';
  Panel.style.height=Height+'px';
  Panel.style.top =(oY)+'px';
  Panel.style.left=(oX)+'px';
  Panel.style.display=''  
}

function GetDimension(ElementId) {
    //if (typeof Element == 'string')
    Element = _get(ElementId);

    var retValue = new Object();
    retValue.w = GetElementWidth(Element),
    retValue.h = GetElementHeight(Element);
    
    var oX = Element.offsetLeft;
    var oY = Element.offsetTop;
    while (Element.parentNode) {// finds the absolute position of the object        
        //if(!(Element.tagName=='TR' || Element.tagName=='TBODY' || Element.tagName=='TABLE'))
        if (!(Element.tagName == 'TBODY') && !(Element.tagName == 'TR')) {
            oX = oX + Element.parentNode.offsetLeft;
            oY = oY + Element.parentNode.offsetTop;
        }
        if (Element == document.getElementsByTagName('body')[0]) { break }
        else { Element = Element.parentNode; }
    }

//    if (IsIE || IsFirefox) {
//        if (oX >= 4) oX -= 4;
//        if (oY >= 4) oY -= 2;
//    }
    retValue.x = oX;
    retValue.y = oY;
    return retValue;
}

  function GetPoint(e)
  {  
  var x,y;
  if (!e) { var e = window.event; };//IE 
  var AddScroolValue=false;
  if((e.x || e.y))
     {x=e.x;y=e.y; AddScroolValue=true;}
  else
  {
   if (e.pageX || e.pageY)
        {/*Moz*/ x= e.pageX;y = e.pageY;}
        else if (e.clientX || e.clientY)
        {/*IE*/ 
         AddScroolValue=true;
          x = e.clientX - 2;
          y = e.clientY - 2;//IE correction 
        }
  }
  //alert(y+' - '+GetScrollTop())
   var retValue=new Object();
   retValue.x=x+ (AddScroolValue?GetScrollLeft():0);
   retValue.y=y+ (AddScroolValue?GetScrollTop():0);
   //alert(retValue.y)
   return retValue;
  }
    function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}
  
  
  
  
  
  
  
////////////////////////////////////////
////////////////////////////////////////
//       Document OnClick Event       //
////////////////////////////////////////
////////////////////////////////////////

var _Popup_Controls=new Array();
var _document_OnClick_Events=new Array();
var _PrevuseDocumentClickEventHandler=null;

 function _RegesterPupupControl(cotrolID)
    {_Popup_Controls.push(cotrolID);}


    function _document_onclick(e) {
        var element = e ? e.target : event.srcElement;
        if (element)
        { if (element.getAttribute('hidepopuponclick') == 'false') return }
        _HidePupupControl();
    }
    function _HidePupupControl() {
        for (var i = 0; i < _Popup_Controls.length; i++) {
            var control = document.getElementById(_Popup_Controls[i])
            //        var parentID=_Popup_Controls[i].substring(0,_Popup_Controls[i].lastIndexOf('_'))
            //        if(parentID==srcID) continue;
            //        if(parentID+'_'==srcID.substring(0,parentID.length+1))continue;
            if (control)
            { control.style.display = 'none'; }
        }
    }
 ////////////////////////////////////////
////////////////////////////////////////
//                                    //
////////////////////////////////////////
////////////////////////////////////////


 
 
 
 
////////////////////////////////////////
////////////////////////////////////////
//           Hide Items               //
////////////////////////////////////////
////////////////////////////////////////

var Temporary_ControlsClass=function()
  {
   this._Temporary_Controls=new Array();
   this._intervalID=null;
  }

Temporary_ControlsClass.prototype=
{
   TimerFunction:"HideTemporaryControls"
   ,
   _Temporary_Controls:null
   ,
  RegisterTemporaryControl:function(cotrolID)
       {         
         this._Temporary_Controls.push(cotrolID);
       }
   ,
   interval:3000
   ,
   start:function()
   {  
     this.stop();
     this._intervalID=setInterval(this.TimerFunction+"()",this.interval);
   }
   ,
   stop:function()
   {        
      if(this._intervalID!=null)
      {
        clearInterval(this._intervalID);
        this._intervalID=null;
      }    
   }
}

var Temporary_Controls=new Temporary_ControlsClass();
function HideTemporaryControls()
{
  for(var i=0;i<Temporary_Controls._Temporary_Controls.length;i++)
  {
   var control=document.getElementById(Temporary_Controls._Temporary_Controls[i]);
   if(control)
      {var attr=control.getAttribute('hideit');       
       if(attr!='true')
          {control.setAttribute('hideit','true');}
       else
          {control.style.display='none';}
      }
  }
}





function getRndDate()
{
 var dt=new Date();
 return dt.toString()
}


////////////////////////////////////////
////////////////////////////////////////
//                                    //
////////////////////////////////////////
////////////////////////////////////////

var Messages=new Object();
Messages.NotAuthenticated='Please you nead to login';
var MessageType=new Object();
MessageType.MESSAGE=0;
MessageType.WARNING=1;
MessageType.ERROR=2;
MessageType.INFORMATION=3
function ShowMessage(message,Type)
{
 //switch(Type)
 alert (message)
 return false;
}










function updateCharCount(tbBox)
{
  var MAX_CHAR=tbBox.getAttribute('maxlength');
  var perfix=tbBox.getAttribute('perfix');
  var text;
  var lblMsg=_get(perfix+'_Msg')
  if(tbBox.value.length>MAX_CHAR)
  { 
    text=lblMsg.getAttribute('exceeded')+(tbBox.value.length-MAX_CHAR)
  }
  else
  {
  text=lblMsg.getAttribute('remaining')+(MAX_CHAR-tbBox.value.length)
  }
  lblMsg.innerHTML=text
}



function DiscardCommentBox(perfix)
{
 var tbBox=_get(perfix+'_Comment');
 tbBox.value=''
 updateCharCount(tbBox)
}


function CheckCommentBox(perfix,TextBoxName,TextBoxTitle,reqLogin) {
    if (reqLogin) {
        if(!IsUser)return  ShowMessage(Messages.NotAuthenticated,MessageType.ERROR)
    }
if(!TextBoxName)
    TextBoxName='_Comment';
 var tbBox=_get(perfix+TextBoxName);
 var MAX_CHAR=tbBox.getAttribute('maxlength');
 if(!TextBoxTitle)
    TextBoxTitle='Comment';
 if(tbBox.value.length>MAX_CHAR && MAX_CHAR>0)
 {
 ShowMessage(TextBoxTitle=' too long.',MessageType.WARNING)
 return false;
 }
 if(tbBox.value.length==0)
 {
 ShowMessage('Please type your '+TextBoxTitle+'.',MessageType.WARNING)
 return false;
 }
}
























function SetAsTaglePanel(PanelId, ButtonId, Hideit) {
    var Panel = document.getElementById(PanelId);
    Panel.setAttribute('_tp_panelheight', Panel.offsetHeight)
    Panel.setAttribute('_tp_buttonid', ButtonId)
    Panel.style.overflow = 'hidden';
    if (Hideit != false)
        Panel.style.display = 'none';
    ChangeTaglePanelButtonHandlerImage(Panel);
    var ctrlHandler = document.getElementById(ButtonId);
    if (ctrlHandler) {
        ctrlHandler.style.cursor = 'pointer';
        ctrlHandler.onclick = function() { TaglePanel(PanelId); };
    }
}

function ChangeTaglePanelButtonHandlerImage(PanelId) {

    var Panel = (typeof PanelId).toLowerCase() == "string" ? document.getElementById(PanelId) : PanelId;
    var image = '../images/'
    var ButtonHandler = document.getElementById(Panel.getAttribute('_tp_buttonid'));
    if (ButtonHandler) {
        if (Panel.style.display == 'none')
        { image += 'max.gif'; }
        else
        { image += 'min.gif'; }
        ButtonHandler.src = image;
    }
}
function TaglePanel(PanelId) {

    var Panel = document.getElementById(PanelId);
    var height = Panel.getAttribute('_tp_panelheight')


    if (typeof height == "String")
        height = height.replace('px', '');

    if (!height || height == '') {
        if (Panel.style.display == 'none')
        { Panel.style.display = 'block' }
        else
        { Panel.style.display = 'none' }
        ChangeTaglePanelButtonHandlerImage(Panel)
        return;
    }
    var speed = 50;
    var stepCount = 20;
    var step = height / stepCount

    if (Panel.style.display == 'none') {
        try {
            Panel.style.height = step + 'px';
            Panel.style.display = '';
            for (var i = 1; i <= stepCount; i++)
                setTimeout("document.getElementById('" + PanelId + "').style.height=(" + step + "*" + i + ")+'px'", speed * (i + 1))
            ChangeTaglePanelButtonHandlerImage(PanelId)
            //setTimeout("document.getElementById('"+PanelId+"').style.height=("+height+")+'px'",70*(stepCount+1))
        }
        catch (e)
    { Panel.style.display = '' }
    }
    else {
        try {
            for (var i = stepCount, j = 0; i > 0; i--, j++)
                setTimeout("document.getElementById('" + PanelId + "').style.height=(" + step + "*" + i + ")+'px'", speed * (stepCount - i))
            setTimeout("document.getElementById('" + PanelId + "').style.display='none';" +
                       "ChangeTaglePanelButtonHandlerImage('" + PanelId + "')", speed * (stepCount))
        } catch (e)
   { Panel.style.display = 'none' }
    }
}


function IsValidEMail(sEmail) {   
    var strRegExp = /[\w]{1}[\w+-.]{1,}[@][\w]{2,}[.][\W\w]{1,}$/i;
    return sEmail.search(strRegExp) == 0;
}

function IsValidGuid(sEmail) {
    var strRegExp = /[\^[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}$/i;
    return sEmail.search(strRegExp) == 0;
}

function ClickToURL(url) {
    url = SiteUrl + 'click.aspx?url=' + escape(url);
    window.open(url);
}

