﻿


     function thumb_onMouseOver(id){ 
         //           alert(e.srcElement.id);
        // alert(e);
                 var thumbprev=$get('thumbprev');
                 
					thumbprev.innerHTML='<img src="img/products/images/'+id+'.jpg" />' 
                    thumbprev.style.display='';  
					
                     var location=Sys.UI.DomElement.getLocation($get('i'+id));
                     Sys.UI.DomElement.setLocation(thumbprev,location.x+65,location.y);
               }
               
                function thumb_onMouseOut(){
                    $get('thumbprev').style.display='none';
                }
                
                
                function toggleDisabled(elem,txt){
    if ((elem != null) && (elem.disabled != 'undefined')){
        elem.disabled = !(elem.disabled);
        if (txt != ''){
            elem.value = txt;   
        }
    }
}


                 function txtwatermark_blur(evt){
                    var txtbox = $get(this.id);
                    
                    if(txtbox.value==""){
                        txtbox.value='Enter PID or Keyword';
                        txtbox.style.color='#a5a5a5';
                    }
                }
                
                function txtwatermark_focus(evt){
                 
                    var txtbox = $get(this.id);
                    
                    if(txtbox.value=='Enter PID or Keyword'){
                        txtbox.value="";
                        txtbox.style.color='';
                    }
                }


function getElementsByClassName(className)
{   
var outArray = new Array();
    var item;
    try {
        var xpathResult = document.evaluate('//*[@class = "' + className + '"]', document, null, 0, null);
        while (item = xpathResult.iterateNext())
            outArray[outArray.length] = item;
    }
    catch(err) {
        // ie fix
        var currentIndex = 0;
        var allElements = document.getElementsByTagName('*');
        for(var i=0; i < allElements.length; i++)
        {   if(allElements[i].className.match(className))
            {   outArray[currentIndex] = allElements[i];
                currentIndex++;
            }
        }
    }
    
    return outArray;
}


  function getElementsByRegex(regex,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp(regex);
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].id) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
	
	}    
	
           
window.getScrollHeight= function(){
		if (this.ie) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		if (this.khtml) return document.body.scrollHeight;
		return document.documentElement.scrollHeight;
	}
	window.getHeight= function(){
		if (this.khtml) return this.innerHeight;
		if (this.opera) return document.body.clientHeight;
		return document.documentElement.clientHeight;
	}
	
	
	window.getScrollTop= function(){
		return this.pageYOffset || document.documentElement.scrollTop;
	}
	
	function toggleDisabled(elem,txt){
    if ((elem != null) && (elem.disabled != 'undefined')){
        elem.disabled = !(elem.disabled);
        if (txt != ''){

            elem.value = txt;   
            
        }
    }
}


// internal window functions
function WindowSize()
{ // window size object
	this.w = 0;
	this.h = 0;
	return this.update();
}
WindowSize.prototype.update = function()
{
	var d = document;
	
	this.w =(window.innerWidth) ? window.innerWidth
	: (d.documentElement && d.documentElement.clientWidth) ? d.documentElement.clientWidth
	: d.body.clientWidth;
	this.h =(window.innerHeight) ? window.innerHeight
	: (d.documentElement && d.documentElement.clientHeight) ? d.documentElement.clientHeight
	: d.body.clientHeight;
	return this;
};
function PageSize()
{ // page size object
	this.win = new WindowSize();
	this.w = 0;
	this.h = 0;
	return this.update();
}
PageSize.prototype.update = function()
{
	var d = document;
	this.w = 
	  (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX
	: (d.body.scrollWidth > d.body.offsetWidth) ? d.body.scrollWidth
	: d.body.offsetWidt;
	this.h = 
	  (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY
	: (d.body.scrollHeight > d.body.offsetHeight) ? d.body.scrollHeight
	: d.body.offsetHeight;
	this.win.update();
	if (this.w < this.win.w) this.w = this.win.w;
	if (this.h < this.win.h) this.h = this.win.h;
	return this;
};
function PagePos()
{ // page position object
	this.x = 0;
	this.y = 0;
	return this.update();
}
PagePos.prototype.update = function()
{
	var d = document;
	this.x =
	  (window.pageXOffset) ? window.pageXOffset
	: (d.documentElement && d.documentElement.scrollLeft) ? d.documentElement.scrollLeft
	: (d.body) ? d.body.scrollLeft
	: 0;
	this.y =
	  (window.pageYOffset) ? window.pageYOffset
	: (d.documentElement && d.documentElement.scrollTop) ? d.documentElement.scrollTop
	: (d.body) ? d.body.scrollTop
	: 0;
	return this;
};

function lbcenter(id,notopen)
{
		if (notopen) return;
	 	var width=parseInt($get(id).style.width.replace("px",""));	
		var height=parseInt($get(id).style.height.replace("px",""));
	   
	    page = new PageSize();
	    pos  = new PagePos();
		$get(id).style.left=Math.round((page.win.w - width) / 2 )+"px";
   	    $get(id).style.top=Math.round((page.win.h - height) / 2)+pos.y+"px";

		$get('overlay').style.height = page.h+"px";
	}
	
 function lbclose()
	{
	    for (var i = 0; i < arguments.length; i++) {
		    var element = $get(arguments[i]);
		        if (element!=null){
		            if(element.style.display!='none'){
			            $get('overlay').style.display  = "none";
			            element.style.display  = "none";
			            
			            if(window.onCloseHandler!=null && element.id!='progress'){
                            onCloseHandler();
                        }
		            }
    		   }
		   
	    }
	}

// type = im(image), if(iframe), wr(webrequest),ws (webservice)
function lbshow(id,w,h,url,type,post)
{
	var iwin=$get(id);
	if(iwin!=null){
	if(iwin.style.display!='block'){
		$get('overlay').style.display  = "block";
	    if(type!=null){
    		iwin.style.width=w+"px";
			iwin.style.height=h+"px";
			
	        var content=$get('lbcontent', iwin);
		    if(type=='im'){
		 	    iwin.style.width=w+15+"px";
			    iwin.style.height=h+48+"px";
		        content.innerHTML="<img src='"+url+"' />";
		    }
		    if(type=='if'){
		        content.innerHTML="<div id='loader'><img src=img/loading.gif align=absmiddle /> Loading. Please wait...</div><iframe style='overflow-x:none;height:"+(h-45)+"px;width:100%;' onload=javascript:parent.document.getElementById('loader').style.display='none'; id='if"+id+"' frameborder='0'   src='"+url+"'></iframe>";
		    }
		    else if(type=='wr'){
		        PostWebRequest(url,content.id,post);
		    }
		
		}
        lbcenter(id,false);        
		iwin.style.display  = "block";
	}
	}
}

function PostWebRequest(url,outputid,post)
{

    $get(outputid).innerHTML="<img src=img/loading.gif align=absmiddle /> Loading. Please wait...";
    
		        $get(outputid).style.display  = "block";

    var wRequest = new Sys.Net.WebRequest();
        
    wRequest.set_url(url);

    wRequest.set_httpVerb("POST");
   
    wRequest.add_completed(OnWebRequestCompleted);

	    
    wRequest.set_body(post);
    wRequest.get_headers()["Content-Length"] = post.length;
    wRequest.set_userContext(outputid);

    wRequest.invoke();            
}

function OnWebRequestCompleted(executor, eventArgs) 
{    
    if(executor.get_responseAvailable()) 
    {
       var outputid = executor.get_webRequest().get_userContext();
  
        var output=$get(outputid);
        output.innerHTML = "";
  
      var ret=executor.get_responseData().replace(/[\f\n\r\t\v]*/g, "");
    
      var reg = /<!--so-->(.*)<!--eo-->/;
var ar = reg.exec(ret);
 output.innerHTML = ar[1];

    }

}

