﻿
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function show_div(s) {
    var obj;
    for (var i = 0; i <= 100; i += 1) {
        obj = document.getElementById("DIV_INFO_" + i.toString());
        if(obj!=null) obj.style.display = 'none';
    }
    
    var obj = document.getElementById(s);
    if (obj != null) obj.style.display = 'block';
}

function show_div_2() {
    var s = querySt("ID");    
    var obj = document.getElementById(s);
    if (obj != null) obj.style.display = 'block';    
}

function hide_div(s) {
    var obj = document.getElementById(s);
    obj.style.display = 'none';
}

function hide_all_div() {
    var obj;
    for (var i = 0; i <= 100; i += 1) {
        obj = document.getElementById("DIV_INFO_" + i.toString());
        if (obj != null) obj.style.display = 'none';
    }
}

function focus_div(s) {
   document.location.href = "#" + s;
}


function change_pic(img) {
    //document.getElementById('__preview').innerHTML = '<div><a rel="prettyPhoto[gallery2]" href="' + img + '"><img width="360" height="300" src="' + img + '" /></a></div>';
    document.getElementById('__preview').innerHTML = '<div style="width:380px; height:266px"><img src="' + img + '" /></div>';
    //document.getElementById('__href').setAttribute('href', img);
}

function reset_href() {
    g_img = img;
    document.getElementById('__href').setAttribute('href', '');
}


function disableEnterKey(e) {
    alert('x');
    
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;                  //firefox

    if (key == 13)
        return false;
    else
        return true;
}
    
function prompt_login() {
 showOverlay('overlay');
 GetResultFrame2('Login.aspx', 470, 750)
}

function SubmitForm() {
   document.ePayment.submit();
}

function ParentRefresh() {
    parent.location.reload();
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function AdjustPageHeight(el)
{
    var obj = document.getElementById(el);
    var h = obj.offsetHeight;
    //alert(h);
    if(h < 500)
    {
        obj.style.height = '500px';
    }    
}

function createDiv(name, e)
{
    // Create the transparent, gray, overlay
    var el = document.createElement("div");
    el.id = name;

    // Make it so that when the grey background is clicked,
    // the gallery and background are hidden
    el.onclick = e;
    		
    //alert(document.body);
    
    // Add the overlay into the DOM
    document.body.appendChild(el);
        
}

function replaceDivContent(divName, content) {
    ddrivetip('Loading..');

    var div = document.getElementById(divName);
    div.innerHTML = "";
    div.innerHTML = content;
}            

// Hide the grey overlay and the current gallery
//function hideOverlay(name) {
//    // and hide the overlay and gallery
//    
//    var obj = document.getElementById(name);
//    if(obj != null) hide(id(name));
//}

function hideOverlay(div1, div2) {
    //hide(id(div1));
    hide(id(div2));
}

// Show the grey overlay
function showOverlay(name) {
    // Find the overlay
    var over = id(name);
		
    // Make it as tall and wide as the entire page
    // (this helps with scrolling)
    over.style.height = pageHeight() + "px";
    over.style.width = pageWidth() + "px";
		
    // And fade it in
    //fadeIn(over, 50, 10);
    show(over);
    
    //alert(over);
}

//--------------------------------------------------------------------

function toggleDisplay(theID,id,offsetX, offsetY)
{
    var curX;
    var curY;
    
    if(theID != '')
    {   
        var obj = document.getElementById(theID);
        var pos = findPos(obj);
        curX = pos[0] + offsetX;
        curY = pos[1] + offsetY;
    }
    else
    {
        curX = offsetX;
        curY = offsetY;
    }
    //alert(curX + ' - ' + curY);
    
    var obj2 = document.getElementById(id);
    if(obj2.style.display == 'none')
        {
           obj2.style.display = 'block';
           obj2.style.left = curX+"px";
           obj2.style.top = curY+"px";
           
           showOverlay('overlay');
        }
    else
        {
          obj2.style.display = 'none';
          obj2.style.left = "-1000px";
          obj2.style.top = "-1000px";
          
           hideOverlay('overlay');
        }
}

function toggleDisplay2(theID, id, offsetX, offsetY) {
    var curX;
    var curY;

    if (theID != '') {
        var obj = document.getElementById(theID);
        var pos = findPos(obj);
        curX = pos[0] + offsetX;
        curY = pos[1] + offsetY;
    }
    else {
        curX = offsetX;
        curY = offsetY;
    }
    //alert(curX + ' - ' + curY);

    var obj2 = document.getElementById(id);
    if (obj2.style.display == 'none') {
        showOverlay('overlay');
        obj2.style.display = 'block';
        obj2.style.left = curX + "px";
        obj2.style.top = curY + "px";
    }
    else {
//        obj2.style.display = 'none';
//        obj2.style.left = "-1000px";
//        obj2.style.top = "-1000px";
        hideOverlay(id,'overlay');
    }
}

function toggleDisplay3(id) {
    var obj = document.getElementById(id);
    if (obj.style.display == 'none') {
        showOverlay('overlay');
        obj.style.cursor = 'pointer';
        obj.style.zIndex = '9999999';
        obj.style.position = 'absolute';
        obj.style.display = 'block';
        obj.style.top = "50px";
    }
    else {
        hideOverlay(id, 'overlay');
    }
}

//--------------------------------------------------------------------

function TestAlert()
{
    alert('test 123');
}

//--------------------------------------------------------------------

function showVideo(theID, target, offsetY, file)
{	   	
    var obj = document.getElementById(theID);
    var pos = findPos(obj);
  
    var curX = pos[0];
    var curY = pos[1] + offsetY; 
	
    var tipobj = document.getElementById(target);
    tipobj.style.display = 'block';
    tipobj.style.left=curX+"px";
    tipobj.style.top=curY+"px";
    
    var tipobj2 = document.getElementById(target+'Frame');
    tipobj2.src = 'TestVideo.aspx?VF=' + file;    
}

function hideVideo(target)
{	    
    var tipobj = document.getElementById(target);
    tipobj.style.display = 'none';
    
    var tipobj2 = document.getElementById(target+'Frame');
    tipobj2.src = '';
}

//--------------------------------------------------------------------

function selectit(theField)
{
	theField.focus();
	theField.select();
}

//--------------------------------------------------------------------

// A function to retrieve a cookie
function get_cookie(cookie_name)
{
var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

if (results)
return (unescape (results[2]));
else
return null;
}

function delete_cookie(cookie_name)
{
    var d = new Date();
    document.cookie = cookie_name + "=1;expires=" + d.toGMTString() + ";" + ";";
}
  
//--------------------------------------------------------------------

function go(obj)
{
    if(obj.value != "") document.location = obj.value;
}

function jump(obj)
{
    if(obj != "" && obj != "-1") window.location.href = obj;
	else history.go(-1);
}

function confirmAction(str) {
    execScript('n = msgbox("' + str + '","4132")', "vbscript");
    return (n == 6);
}

//function window.confirm(str) {
//    execScript('n = msgbox("' + str + '","4132")', "vbscript");
//    return (n == 6);
//}

function jump_parent(obj) {
    if (obj != "" && obj != "-1") window.top.location.href = obj;
    else history.go(-1);
}

function jumpSpecial(obj1, obj2)
{
	if(obj1 != "" && obj2 != "") window.location.href = "Compare_Price.aspx?TID=" + obj1 + "&SID=" + obj2;
}


function bookmarksite(){
if (document.all)
window.external.AddFavorite(location.href, document.title);
else if (window.sidebar)
window.sidebar.addPanel(document.title, location.href, "");
}

function PopupWin(url,w,h){
///Parameters url=page to open, w=width, h=height
newwindow=window.open(url, "external", "width=" + w +",height=" + h + ",resizable=yes,scrollbars=yes,status=no,location=no,toolbar=no,menubar=yes");
if (window.focus) {newwindow.focus()}
}

function PopupWin2(url,w,h){
///Parameters url=page to open, w=width, h=height
newwindow=window.open(url, "external", "width=" + w +",height=" + h + ",resizable=no,scrollbars=yes,status=no,location=no,toolbar=no,menubar=no");
if (window.focus) {newwindow.focus()}
}

function findPos(obj) {
    //alert(obj);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	//alert(curleft + " , " + curtop);	 
	return [curleft,curtop];
}

//-------------------------------------------------------------------------------------------------------------------------

document.onmousemove=positiontip

var curX;
var curY;

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=13 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

//document.write('<div id="dhtmltooltip" style="visibility:hidden; font-family:Verdana; font-weight:bold; font-size:11px; border:solid 2px #d43f0b; color:Black; padding:2px 0px 2px 2px"></div>') //write out tooltip DIV
//document.write('<img id="dhtmlpointer" style="visibility:hidden" src="App_Themes/default/images/Pointer-1.gif">') //write out pointer image

var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
var pointerobj2=document.all? document.all["dhtmlpointer2"] : document.getElementById? document.getElementById("dhtmlpointer2") : ""

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
//if (ie||ns6)

function ddrivetip(thetext, thewidth, thecolor){
	    
	    var obj = document.getElementById("dhtmltooltip_text");
	    
	    if(obj != null)
	    {
	        obj.innerHTML = thetext;
	        enabletip=true;
		    return true;
        }
        else
        {
            enabletip=false;
		    return false;
        }
}

function hideddrivetip(){		
	var tipobj = document.getElementById("dhtmltooltip");
	tipobj.style.display = 'none';
	tipobj.style.left="-1000px";
	tipobj.style.top="-1000px";
	
	var pointerobj = document.getElementById("dhtmlpointer");
	pointerobj.style.visibility="hidden";
	
	var pointerobj2 = document.getElementById("dhtmlpointer2");
	pointerobj2.style.visibility="hidden";
	
	enabletip=false;		
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function positiontip(e){	
	if (enabletip){
	    var pointerobj = document.getElementById("dhtmlpointer");
	    pointerobj.style.display = 'block';
        var pointerobj2 = document.getElementById("dhtmlpointer2");
        pointerobj2.style.display = 'block';

        var tipobj = document.getElementById("dhtmltooltip");
        tipobj.style.display = 'block';
         	
		var nondefaultpos=false
		curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		if (rightedge<tipobj.offsetWidth){
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			pointerobj2.style.left=curX+offsetfromcursorX-34+"px"
			pointerobj2.style.visibility="visible"
			pointerobj.style.visibility="hidden"
		}
		else if (curX<leftedge)
			{ 
			    tipobj.style.left="5px" 
			}
		    else
		    {
			    tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			    pointerobj.style.left=curX+offsetfromcursorX+10+"px"
			    pointerobj.style.visibility="visible"
			    pointerobj2.style.visibility="hidden"
		    }

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			
			pointerobj.style.visibility="hidden"
			pointerobj2.style.visibility="hidden"
		}
		else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
			pointerobj2.style.top=curY+offsetfromcursorY+"px"			
			
		    //alert('3')
		}
		
//		if (!nondefaultpos)
//			{pointerobj.style.visibility="visible"}
//		else
//		    {pointerobj.style.visibility="hidden"}
	}
}

//--------------------------------------------------------------------

function ddrivetip2(target){
   var tipobj = document.getElementById(target);
   tipobj.style.display = 'block';
}

function ddrivetip3(theID, target, offsetY, thewidth, refresh){
	    var obj = document.getElementById(theID);
	    var pos = findPos(obj);
	    
	    if (refresh==1)
	    {
	        //var tipobjParam = document.getElementById(target+'Frame'); 
	        //tipobjParam.src = 'GetBrand.aspx';
	    }
	    
	    //alert(pos[0] + " , " + pos[1]);	    
	    positiontip3(pos, offsetY, target, obj.style.width);

	   return true;
}

function positiontip3(pos, offsetY, target, thewidth){	
        var tipobj = document.getElementById(target);	    
	    tipobj.style.display = 'block';
	    tipobj.style.width = thewidth;
	    
	    //var tipobjContent = document.getElementById(target+'Content'); 
	    //tipobjContent.style.width = thewidth+'px';
	    
	    //tipobjContent.innerHTML = "<tr><td>xxx xxx xxx</td></tr>";
	   	
	    var curX = pos[0];
	    var curY = pos[1] + offsetY;	    
	    //alert(curX + " , " + curY); 
	    
	    tipobj.style.left=curX+"px";
	    tipobj.style.top=curY+"px";
	}

	function ddrivetip5(theID, target, offsetX, offsetY) {
	    var obj = document.getElementById(theID);
	    var pos = findPos(obj);
	    var curX = pos[0] + offsetX;
	    var curY = pos[1] + offsetY;
	    
	    var tipobj = document.getElementById(target);
	    tipobj.style.display = 'block';
	    tipobj.style.left = curX + "px";
	    tipobj.style.top = curY + "px";

	    return true;
	}

	function positiontip6(target, w, h) {
	    var PW = pageWidth();
	    var PH = pageHeight();
	    var X = (PW - w) / 2;
	    var obj = document.getElementById(target);
	  
	    obj.style.cursor = 'pointer';
	    obj.style.zIndex = '9999999';
	    obj.style.position = 'absolute';
	    obj.style.display = 'block';
	    obj.style.top = "50px";
	    obj.style.left = X + "px";
	    obj.style.height = h + "px";
	    obj.style.width = w + "px";
	}


//--------------------------------------------------------------

var g_categories_data;
var g_div_pos;
var g_div_name;

function replace_data(s) {
    var s2 = s.replace(/@@/g, "'");
    return s2;        
}

function set_cat_data(s) {
    g_categories_data = s.replace(/@@/g, "'");
}

function set_cat_data_2(s) {
    //alert(s);
    window.open(s);
}

function set_class(id, cls) {
    var obj = document.getElementById(id);
    obj.setAttribute("class", cls);
}

//--------------------------------------------------------------

function ddrivetip4(theID, target, offsetY) {
    var obj = document.getElementById(theID);
    var pos = findPos(obj);
    var Width = obj.style.width.replace("px", "");

    obj.setAttribute("class", "Categories-2");
    g_div_name = theID;
    positiontip4(pos, offsetY, target, Width);

    return true;
}

function positiontip4(pos, offsetX, target, Width) {
    var tipobj = document.getElementById(target);
    tipobj.style.display = 'block';

//    var obj = document.getElementById('SubMenu');
//    obj.innerHTML = "<div onmouseout=\"hideddrivetipDynamic('TestDivMenu2')\" >" +
//    "<table style='border:solid 2px black'><tr><td><a href=" + g_categories_data + ">" + g_categories_data + "</a></td></tr></table></div>";

    g_categories_data = g_categories_data.replace(/%%/g, "\"");
    
    var obj = document.getElementById('SubMenu');
    obj.innerHTML = "<div onmouseout=\"hideddrivetipDynamic('TestDivMenu2')\" >" + g_categories_data + "</div>";

    //alert(obj.innerHTML);

    pos[0] = pos[0] - offsetX + parseInt(Width);
    var curX = pos[0];
    var curY = pos[1];
    g_div_pos = pos;

    tipobj.style.left = curX + "px";
    tipobj.style.top = curY + "px";
}

function hideddrivetipDynamic(obj) {
    var tipobj = document.getElementById(obj);
    tipobj.style.display = 'none';

    set_class(g_div_name, "Categories-1");
}

function showddrivetipDynamic(obj) {
    set_class(g_div_name, "Categories-2");
    
    var tipobj = document.getElementById(obj);
    tipobj.style.display = 'block';
   
    tipobj.style.left = pos[0] + "px";
    tipobj.style.top = pos[1] + "px";    

    //alert(tipobj.style.left + " , " + tipobj.style.top);
}

//--------------------------------------------------------------------

function toggleElementDisplayAuto(id)
{  
    if(document.getElementById(id).style.display == 'none')
        {
          document.getElementById(id).style.display = 'block'; 
          document.getElementById(id).style.top = scrollY + "px"
          document.getElementById(id).style.zIndex="99999";    
        }
    else
        { document.getElementById(id).style.display = 'none'; }
}

function toggleElementDisplayAuto2(id)
{  
    var id1 = id + "A";
    var id2 = id + "B";
    var id3 = id;
    
    if(document.getElementById(id1).style.display == 'none')
        {
          document.getElementById(id1).style.display = 'block';
          
          if(id3 != '')
          {
            var obj = document.getElementById(id3);
            var pos = findPos(obj);
            var curX = pos[0];
            var curY = pos[1];
          
            window.scrollTo(curX, curY); 
          }
        }
    else
        { document.getElementById(id1).style.display = 'none'; }
        
   if(document.getElementById(id2).style.display == 'none')
        {
          document.getElementById(id2).style.display = 'block';
        }
   else
        { document.getElementById(id2).style.display = 'none'; }
}

function toggleElementDisplayAuto3(id)
{  
    var elm = document.getElementById(id);
    var elmA = document.getElementById(id+"A"); 
    var elmB = document.getElementById(id+"B");
    
    if(elmA.style.display == 'none')
        {
        smoothDisplay(id, "Collapse");
        }
    else
        { elmA.style.display = 'none'; }
        
   if(elmB.style.display == 'none')
        {
         smoothDisplay(id, "Expand"); 
        }
   else
        { elmB.style.display= 'none'; }
}

//--------------------------------------------------------------------

var _h;
var _max;
var _elm;
var _t;
var _stepSize; 
var _Interval = 10;
var _steps = 8;

function LoopHeightExpand()
{   
    var elmA = document.getElementById(_elm+"A");
    var elmB = document.getElementById(_elm+"B");
    var elmC = document.getElementById(_elm+"C");    
    
    if(_max == 0)
    {  
        elmC.style.display = 'block';
        elmB.style.display = 'block';
        _max = elmB.offsetHeight;
        _stepSize = parseInt(_max/_steps);
        elmC.style.display = 'none';
        _t = setTimeout("LoopHeightExpand()",_Interval);
    }
    
    if(_h < _max) 
     {
        elmB.style.height = _h + "px";
        elmB.style.display = 'block';
        
        _h += _stepSize;
        _t = setTimeout("LoopHeightExpand()",_Interval);
     }
     
     if(_h >= _max) 
     {
        elmB.style.height = _max + "px";
        elmC.style.display = 'block';
     }       
}

function LoopHeightCollapse()
{   
    var elmA = document.getElementById(_elm+"A");
    var elmB = document.getElementById(_elm+"B");
    var elmC = document.getElementById(_elm+"C");
    
    elmA.style.display = 'block';
    if(_max >= 0) 
     {
        elmC.style.display = 'none';
        elmA.style.height = _max + "px";
       
        if (_stepSize < 10) _stepSize = 10;
        var temp = _max - _stepSize;
        if (temp <= 0 ) 
        {
            elmA.style.display = 'block';
            elmA.style.height = "20px";
            elmB.style.display = 'none';
            elmC.style.display = 'none';
        }
        else 
        {
            _max -= _stepSize;            
            _t = setTimeout("LoopHeightCollapse()",_Interval);
        }
     }   
}

function smoothDisplay(id, direction)
{
    _elm = id;  
    
    
    if(direction=="Expand")
    { 
       _max = 0;
       _h = 0;
       LoopHeightExpand();
    }
    else
    {
       _max = document.getElementById(_elm+"C").offsetHeight;
       _stepSize = parseInt(_max/_steps);
       LoopHeightCollapse();
    }
}
  
function pause(millisecondi)
{
   var now = new Date();
   var exitTime = now.getTime() + millisecondi;
   while(true)
   {
      now = new Date();
      if(now.getTime() > exitTime) return;
   }
}

//--------------------------------------------------------------------

function focusElement(id)
{
    var obj = document.getElementById(id);
    
    if(obj != null)
      {
        var pos = findPos(obj);
        var curX = pos[0];
        var curY = pos[1];
      
        window.scrollTo(curX, curY); 
      }
}

//--------------------------------------------------------------------

function doFocus(id)
{
    s = "<script type='text//javascript'>document.onload=focusElement('" + id + "')<//script>";
    document.write(s);
}

//##############################################################################################
// Utils-2
//##############################################################################################

// Get a style property (name) of a specific element (elem)
function getStyle(elem, name) {
    // If the property exists in style[], then it’s been set recently (and is current)
    if (elem.style[name])
        return elem.style[name];

    // Otherwise, try to use IE’s method
    else if (elem.currentStyle)
        return elem.currentStyle[name];

    // Or the W3C’s method, if it exists
    else if (document.defaultView && document.defaultView.getComputedStyle) {
        // It uses the traditional ‘text-align’ style of rule writing, instead of textAlign
        name = name.replace(/([A-Z])/g, "-$1");
        name = name.toLowerCase();

        // Get the style object and get the value of the property (if it exists)
        var s = document.defaultView.getComputedStyle(elem, "");
        return s && s.getPropertyValue(name);

        // Otherwise, we’re using some other browser
    } else
        return null;
}

// Find the X (Horizontal, Left) position of an element
function pageX(elem) {
    var p = 0;

    // We need to add up all of the offsets for every parent
    while (elem.offsetParent) {
        // Add the offset to the current count
        p += elem.offsetLeft;

        // and continue on to the next parent
        elem = elem.offsetParent;
    }

    return p;
}

// Find the Y (Vertical, Top) position of an element
function pageY(elem) {
    var p = 0;

    if (elem != null) {
        // We need to add up all the offsets for every parent
        while (elem.offsetParent) {
            // Add the offset to the current count
            p += elem.offsetTop;

            // and continue on to the next parent
            elem = elem.offsetParent;
        }
    }
    return p;
}

// Find the horizontal positioing of an element within its parent
function parentX(elem) {
    // If the offsetParent is the element's parent, break early
    return elem.parentNode == elem.offsetParent ?
        elem.offsetLeft :

    // Otherwise, we need to find the position relative to the entire
    // page for both elements, and find the difference
        pageX(elem) - pageX(elem.parentNode);
}

// Find the vertical positioing of an element within its parent
function parentY(elem) {
    // If the offsetParent is the element's parent, break early
    return elem.parentNode == elem.offsetParent ?
        elem.offsetTop :

    // Otherwise, we need to find the position relative to the entire
    // page for both elements, and find the difference
        pageY(elem) - pageY(elem.parentNode);
}

// Find the left position of an element
function posX(elem) {
    // Get the computed style and get the number out of the value
    return parseInt(getStyle(elem, 'left'));
}

// Find the top position of an element
function posY(elem) {
    // Get the computed style and get the number out of the value
    return parseInt(getStyle(elem, 'top'));
}


// A function for setting the horizontal position of an element
function setX(elem, pos) {
    // Set the 'left' CSS property, using pixel units
    elem.style.left = pos + 'px';
}

// A function for setting the vertical position of an element
function setY(elem, pos) {
    // Set the 'left' CSS property, using pixel units
    elem.style.top = pos + 'px';
}

// A function for adding a number of pixels to the horizontal
// position of an element 
function addX(elem, pos) {
    // Get the current horz. position and add the offset to it.
    setX(posX(elem) + pos);
}

// A function that can be used to add a number of pixels to the
// vertical position of an element
function addY(elem, pos) {
    // Get the current vertical position and add the offset to it
    setY(posY(elem) + pos);
}

// Get the actual height (using the computed CSS) of an element
function getHeight(elem) {
    // Gets the computed CSS value and parses out a usable number
    return parseInt(getStyle(elem, 'height'));
}

// Get the actual width (using the computed CSS) of an element
function getWidth(elem) {
    // Gets the computed CSS value and parses out a usable number
    return parseInt(getStyle(elem, 'width'));
}

// Find the full, possible, height of an element (not the actual,
// current, height)
function fullHeight(elem) {
    // If the element is being displayed, then offsetHeight
    // should do the trick, barring that, getHeight() will work
    if (getStyle(elem, 'display') != 'none')
        return elem.offsetHeight || getHeight(elem);

    // Otherwise, we have to deal with an element with a display
    // of none, so we need to reset its CSS properties to get a more
    // accurate reading
    var old = resetCSS(elem, {
        display: '',
        visibility: 'hidden',
        position: 'absolute'
    });

    // Figure out what the full height of the element is, using clientHeight
    // and if that doesn't work, use getHeight
    var h = elem.clientHeight || getHeight(elem);

    // Finally, restore the CSS properties back to what they were
    restoreCSS(elem, old);

    // and return the full height of the element
    return h;
}

// Find the full, possible, width of an element (not the actual,
// current, width)
function fullWidth(elem) {
    // If the element is being displayed, then offsetWidth
    // should do the trick, barring that, getWidth() will work
    if (getStyle(elem, 'display') != 'none')
        return elem.offsetWidth || getWidth(elem);

    // Otherwise, we have to deal with an element with a display
    // of none, so we need to reset its CSS properties to get a more
    // accurate reading
    var old = resetCSS(elem, {
        display: '',
        visibility: 'hidden',
        position: 'absolute'
    });

    // Figure out what the full width of the element is, using clientWidth
    // and if that doesn't work, use getWidth
    var w = elem.clientWidth || getWidth(elem);

    // Finally, restore the CSS properties back to what they were
    restoreCSS(elem, old);

    // and return the full width of the element
    return w;
}

// A function used for setting a set of CSS properties, which
// can then be restored back again later
function resetCSS(elem, prop) {
    var old = {};

    // Go through each of the properties
    for (var i in prop) {
        // Remember the old property value
        old[i] = elem.style[i];

        // And set the new value
        elem.style[i] = prop[i];
    }

    // Retun the set of changed values, to be used by restoreCSS
    return old;
}

// A function for restoring the side effects of the resetCSS function
function restoreCSS(elem, prop) {
    // Reset all the properties back to their original values
    for (var i in prop)
        elem.style[i] = prop[i];
}

// A function for hiding (using display) an element
function hide(elem) {
    // Find out what it's current display state is
    var curDisplay = getStyle(elem, 'display');

    //  Remember its display state for later
    if (curDisplay != 'none')
        elem.$oldDisplay = curDisplay;

    // Set the display to none (hiding the element)
    elem.style.display = 'none';
}

// A function for showing (using display) an element
function show(elem) {
    // Set the display property back to what it use to be, or use
    // 'block', if no previous display had been saved
    elem.style.display = elem.$oldDisplay || 'block';
}

// Set an opacity level for an element
// (where level is a number 0-100)
function setOpacity(elem, level) {
    // If filters exist, then this is IE, so set the Alpha filter
    if (elem.filters)
        elem.filters.alpha.opacity = level;

    // Otherwise use the W3C opacity property
    else
        elem.style.opacity = level / 100;
}

function fadeIn(elem) {
    // Start the opacity at  0
    setOpacity(elem, 0);

    // Show the element (but you can see it, since the opacity is 0)
    show(elem);

    // We're going to do a 20 'frame' animation that takes
    // place over one second
    for (var i = 0; i <= 100; i += 5) {
        // A closure to make sure that we have the right 'i'
        (function() {
            var pos = i;

            // Set the timeout to occur at the specified time in the future
            setTimeout(function() {

                // Set the new opacity of the element
                setOpacity(elem, pos);

            }, (pos + 1) * 10);
        })();
    }
}

// Find the horizontal position of the cursor
function getX(e) {
    // Normalize the event object
    e = e || window.event;

    // Check for the non-IE position, then the IE position, and finally return 0
    return e.pageX || e.clientX + document.body.scrollLeft || 0;
}

// Find the vertical position of the cursor
function getY(e) {
    // Normalize the event object
    e = e || window.event;

    // Check for the non-IE position, then the IE position, and finally return 0
    return e.pageY || e.clientY + document.body.scrollTop || 0;
}

// Get the X position of the mouse relative to the element target
// used in event object 'e'
function getElementX(e) {
    // Find the appropriate element offset
    return (e && e.layerX) || window.event.offsetX;
}

// Get the Y position of the mouse relative to the element target
// used in event object 'e'
function getElementY(e) {
    // Find the appropriate element offset
    return (e && e.layerY) || window.event.offsetY;
}

// Returns the height of the web page
// (could change if new content is added to the page)
function pageHeight() {
    return document.body.scrollHeight;
}

// Returns the width of the web page
function pageWidth() {
    return document.body.scrollWidth;
}

// A function for determining how far horizontally the browser is scrolled
function scrollX() {
    // A shortcut, in case we're using Internet Explorer 6 in Strict Mode
    var de = document.documentElement;

    // If the pageXOffset of the browser is available, use that
    return self.pageXOffset ||

    // Otherwise, try to get the scroll left off of the root node
        (de && de.scrollLeft) ||

    // Finally, try to get the scroll left off of the body element
        document.body.scrollLeft;
}

// A function for determining how far vertically the browser is scrolled
function scrollY() {
    // A shortcut, in case we're using Internet Explorer 6 in Strict Mode
    var de = document.documentElement;

    // If the pageYOffset of the browser is available, use that
    return self.pageYOffset ||

    // Otherwise, try to get the scroll top off of the root node
        (de && de.scrollTop) ||

    // Finally, try to get the scroll top off of the body element
        document.body.scrollTop;
}

// If you wanted to scroll the browser up to the top of the browser, you could do:
window.scrollTo(0, 0);

// If you wanted to scroll to the position of a specific element, you could do:
window.scrollTo(0, pageY(document.getElementById('body')));

// Find the height of the viewport
function windowHeight() {
    // A shortcut, in case we're using Internet Explorer 6 in Strict Mode
    var de = document.documentElement;

    // If the innerHeight of the browser is available, use that
    return self.innerHeight ||

    // Otherwise, try to get the height off of the root node
        (de && de.clientHeight) ||

    // Finally, try to get the height off of the body element
        document.body.clientHeight;
}

// Find the width of the viewport
function windowWidth() {
    // A shortcut, in case we're using Internet Explorer 6 in Strict Mode
    var de = document.documentElement;

    // If the innerWidth of the browser is available, use that
    return self.innerWidth ||

    // Otherwise, try to get the width off of the root node
        (de && de.clientWidth) ||

    // Finally, try to get the width off of the body element
        document.body.clientWidth;
}


// Find the element by ID
function id(name) {
    return document.getElementById(name);
}

//##############################################################################################
// Tabs
//##############################################################################################


function TabClick_1(id, id2, color1, color2) {
    HideAllTabs_1(id2, color2);
    document.getElementById(id).style.display = 'block';

    var obj = document.getElementById(id + "x");
    obj.style.color = color1;
    obj.style.position = 'relative';
    obj.style.top = '1px';
    obj.style.backgroundImage = 'none';
}

function HideAllTabs_1(id2, color2) {
    var j = id2;
    for (i = 1; i < 10; i++) {
        if (document.getElementById('__div' + j) != null) {
            document.getElementById('__div' + j).style.display = 'none';

            var obj = document.getElementById('__div' + j + 'x');
            obj.style.color = color2;
            obj.style.position = 'relative';
            obj.style.top = '0px';
            obj.style.backgroundImage = 'url(App_Themes/default/images/Tab-1.gif)';
        }
        j++;
    }

}

function TabClick_2(id, id2, color1, color2) {
    HideAllTabs_2(id2, color2);
    document.getElementById(id).style.display = 'block';

    var obj = document.getElementById(id + "x");
    //    obj.style.color = color1;
    //    obj.style.position = 'relative';
    //    obj.style.top = '5px';
    //    obj.style.backgroundImage = 'none';

    obj.className = 'TabMenu-2';
    resizeFrame2(id + '_frame');
}

var g_div100 = 20;
var g_div101 = 20;
var g_div102 = 20;
var g_div103 = 20;
var g_div104 = 20;

function resizeFrame2(frm) {
    var is_chrome = false;
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { is_chrome = true; }
    if (navigator.userAgent.toLowerCase().indexOf('safari') > -1) { is_chrome = true; }

    var f = document.getElementById(frm);
    if (frm.indexOf("div100") != -1) {
        f.style.height = (f.contentWindow.document.body.scrollHeight + g_div100) + "px";
        if (is_chrome) { g_div100 = 0; }
    }
    else if (frm.indexOf("div101")!= -1) {
        f.style.height = (f.contentWindow.document.body.scrollHeight + g_div101) + "px";
        if (is_chrome) { g_div101 = 0; }
    }
    else if (frm.indexOf("div102") != -1) {
        f.style.height = (f.contentWindow.document.body.scrollHeight + g_div102) + "px";
        if (is_chrome) { g_div102 = 0; }
    }
    else if (frm.indexOf("div103") != -1) {
        f.style.height = (f.contentWindow.document.body.scrollHeight + g_div103) + "px";
        if (is_chrome) { g_div103 = 0; }
    }
    else if (frm.indexOf("div104") != -1) {
        f.style.height = (f.contentWindow.document.body.scrollHeight + g_div104) + "px";
        if (is_chrome) { g_div104 = 0; }
    }
}

function resizeFrame() {
    var is_chrome = false;
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { is_chrome = true; }
    if (navigator.userAgent.toLowerCase().indexOf('safari') > -1) { is_chrome = true; }

    var f = document.getElementById('__div100_frame');
    if (is_chrome) { f.style.height = (f.contentWindow.document.body.scrollHeight + 0) + "px"; }
    else { f.style.height = (f.contentWindow.document.body.scrollHeight + 20) + "px"; }
    

//    f = document.getElementById('__div101_frame');
//    f.style.height = (f.contentWindow.document.body.scrollHeight + i) + "px";

//    f = document.getElementById('__div102_frame');
//    f.style.height = (f.contentWindow.document.body.scrollHeight + i) + "px";

//    f = document.getElementById('__div103_frame');
//    f.style.height = (f.contentWindow.document.body.scrollHeight + i) + "px";

//    f = document.getElementById('__div104_frame');
//    f.style.height = (f.contentWindow.document.body.scrollHeight + i) + "px";
}

function HideAllTabs_2(id2, color2) {
    var j = id2;
    for (i = 100; i < 110; i++) {
        if (document.getElementById('__div' + j) != null) {
            document.getElementById('__div' + j).style.display = 'none';

            var obj = document.getElementById('__div' + j + 'x');
            //obj.style.color = color2;
            //obj.style.position = 'relative';
            //obj.style.top = '0px';
            //obj.style.backgroundImage = 'url(App_Themes/default/images/Tab-1.gif)';
            obj.className = 'TabMenu-1';
        }
        j++;
    }

}

//function TabClick_2(id, id2, color1, color2)
//{  
//    HideAllTabs_2(id2,color2);  
//    document.getElementById(id).style.display = 'block';
//    
//    var obj = document.getElementById(id + "x");
//    obj.style.color = color1;
//}

//function HideAllTabs_2(id2,color2)
//{  
//    var j = id2;
//    for(i=1;i<10;i++)
//    {
//        if(document.getElementById('__div' + j) != null)
//        {
//            document.getElementById('__div' + j).style.display = 'none';
//            
//            var obj = document.getElementById('__div' + j + 'x');
//            obj.style.color = color2;
//        } 
//        j++;  
//    }    
//}

//--------------------------------------------------------------------------------------

function VerticalTabClick_1(id, id2, color1, color2) {
    VerticalHideAllTabs_1(id2, color2);

    var el = document.getElementById(id);
    var el2 = document.getElementById(id + 'x');

    el.style.display = 'block';
    el.style.position = 'absolute';
    el.style.border = 'solid 1px #bbb8b9';
    el.style.top = el2.offsetTop + 'px';
    el.style.left = (el2.offsetLeft + 260) + 'px';
    el.style.zIndex = '8000';
    //    if(el2.offsetHeight < 50)
    //      {  
    //        el.style.height = '50px';
    //      }
    //    else
    //      {
    //         el.style.height = (el2.offsetHeight) + 10 + 'px';
    //      }

    el2.style.color = color1;
    el2.style.position = 'relative';
    el2.style.border = 'solid 1px #bbb8b9';
    el2.style.borderRight = 'solid 1px #ffffff';
    el2.style.backgroundColor = '#ffffff'; //#f3f3f3
    el2.style.zIndex = '9000';
}

function VerticalHideAllTabs_1(id2, color2) {
    var j = id2;
    for (i = 1; i < 30; i++) {
        try {
            var elm1 = '__div' + j;
            var elm2 = elm1 + 'x';

            if (document.getElementById(elm1) != null) {
                document.getElementById(elm1).style.display = 'none';

                var obj = document.getElementById(elm2);
                obj.style.color = color2;
                obj.style.position = 'relative';
                obj.style.border = 'solid 1px #f6f6f6';
                obj.style.backgroundColor = '#f6f6f6';
                obj.style.zIndex = '7000';
            }
            j++;
        }
        catch (err) {
            alert(err);
        }
    }
}































