
function ShowDialog(url)
{
	showModelessDialog(url,window, "resizable: no; help: no; status: no; scroll: no; ");
}

function ShowPage(url, width, height)
{
	var para = "height=" + height + ",width= " + width + ",status=yes,toolbar=no,menubar=no,location=no"
	window.open(url,null, para);
}

function addDays(myDate, days) {				
	var datearray = myDate.split('/');				
	var d3 = new Date(datearray[2].substring(0, 4),datearray[1]-1,datearray[0]);				 
	var newdate = new Date(d3.getTime() + days*24*60*60*1000);				
	var dd = newdate.getDate();
	var mm = newdate.getMonth()+1; // 0 based
	var yy = newdate.getYear();
	if (yy < 1000) yy +=1900; // Y2K fix
	return (mm + '/' + dd +'/' + yy);
}

function OpenPageOnNewWindow(hostName,regionName,imgurl,evt){
    var hostname = window.location.hostname;
    var path = window.location.search;
    var lang = "";
    if(path.indexOf("&lang=") > -1){
        lang = path.substr(path.indexOf("&lang="),11);
    }
    var url = hostName + "/" + regionName + "/views/photoDetail.aspx?ImgUrl=" + imgurl + lang;
    var objwidth = 100;
    var objheight = 100;
    var feature = "width=" +objwidth +",height=" + objheight + ",toolbar=no,menubar=no,resizeable=no,statusbar=no,location=no,scrollbars=no";
    window.open(url,"",feature);
}

function OpenPageOnNewWindow(url, evt){
    var hostname = window.location.hostname;
    var path = window.location.search;
    var lang = "";
    if(path.indexOf("&lang=") > -1){
        lang = path.substr(path.indexOf("&lang="),11);
    }   
    var objwidth = 100;
    var objheight = 100;
    var feature = "width=" +objwidth +",height=" + objheight + ",toolbar=no,menubar=no,resizeable=no,statusbar=no,location=no,scrollbars=no";
    window.open(url,"",feature);
}

function OpenNewWindow(url){    
    window.open(url,"","");
}

function ResizeImage(img, mWidth, mHeight){
    var image=new Image();
    image.src=img.src;
   
  var oldW = image.width;
  var oldH = image.height;
 // alert("oldwide:"+oldW+"oldHieght:"+oldH);
    
    if(image.width > 0 && image.height > 0){
        if(image.width/image.height >= mWidth/mHeight){
            if(image.width > mWidth){ 
         //   alert("1");
                img.width = mWidth;
                img.height = (image.height * mWidth)/image.width;
            }else{
         //   alert("2");
                img.width=image.width; 
                img.height=image.height;
            }
        }else{
            if(image.height>mHeight){
          //  alert("3"); 
                img.height = mHeight;
                img.width = (image.width * mHeight)/image.height; 
            }else{
          //  alert("4");
                img.width=image.width; 
                img.height = image.height;
            }
        }
    }   
}

function LinkTrack()
{
    var linkObject = arguments[0];
    var traceImg = document.createElement("img");
    var myUrl = window.location.href.toString().replace("http://","");
    var Urlparese = myUrl.split("/");
    var linkName;
    if(arguments.length == 1)
    {
        linkName = linkObject.name;
    }
    else if(arguments.length == 2)
    {
        linkName = arguments[1];
    }
    if(linkName.substring(0,4) == 'UIID')linkName=linkObject.name.substr(5);
    if(linkObject.href != null)
    {
        traceImg.setAttribute("src", "http://"+location.host+"/"+Urlparese[1]+"/handler/LinkLog.ashx?LinkName=" +linkName +"&URL="+escape(window.location.href)+"&LinkHref="+escape(linkObject.href));
    }
    else
    {
    	traceImg.setAttribute("src", "http://"+location.host+"/"+Urlparese[1]+"/handler/LinkLog.ashx?LinkName=" +linkName +"&URL="+escape(window.location.href)+"&LinkHref=");
    }	 
}

function SlideImage()
{   
    var obj = document.getElementById("imgDiv");
    var obj1 = document.getElementById("tmpImageDiv2");
    var objlen = obj.offsetWidth;
    if(_moveSpan > 0 && (obj1.offsetWidth - obj.scrollLeft) <= 0){
        //Post image move to right
        obj.scrollLeft = 0;
    }
    if(_moveSpan < 0 && obj.scrollLeft <= 0)
    {
        //Post image move to left
        obj.scrollLeft = obj1.offsetWidth;
    }
    obj.scrollLeft += _moveSpan;
}

function SlideToLeft(){
    if(_moveSpan < 0){
        _moveSpan *= -1;
    }
}
function SlideToRight(){
    if(_moveSpan > 0){
        _moveSpan *= -1;
    }
}

if (window.addEventListener)
{
    window.addEventListener("load", SlideShowOnLoad, false);
}
else if (window.attachEvent)
{
    window.attachEvent("onload", SlideShowOnLoad);    
}
else
{
    window.onload=SlideShowOnLoad;
}

function SlideShowOnLoad(){    
   var tempObj = document.getElementById("tmpImageDiv1");
    var maxObj = document.getElementById("imgDiv");   
     
    
    if (tempObj && maxObj) {     
		   
        var demoWidth = tempObj.offsetWidth;        
        var maxWidth = parseInt(maxObj.style.width);   
        
           
        if(demoWidth <= maxWidth) {
        
            //set Move left btn and Move right btn visible = false
            //document.getElementById("rollLeftDiv").style.display = "none";
            //document.getElementById("rollRightDiv").style.display = "none";
            return;            
        }               
        document.getElementById("tmpImageDiv2").innerHTML = document.getElementById("tmpImageDiv1").innerHTML;               
        startMove();        
    }
     
}

function startMove(){ 
    if(_MoveMarquee == null)
    {
        _MoveMarquee = "move";
        
        _MoveMarquee = setInterval(SlideImage,_MoveSpeed);
    }
    return;
}
function stopMove(){
    window.clearInterval(_MoveMarquee);
    window.clearInterval(_MoveMarquee);
    _MoveMarquee = null;
}


function ClickToPrint()
     {        
        var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
            disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
        var content_vlue = document.getElementById("print_content").innerHTML; 
  
        var docprint=window.open("","",disp_setting); 
       docprint.document.open(); 
       docprint.document.write('<html><head><title>Inel Power System</title>'); 
       docprint.document.write('</head><body onLoad="self.print()"><left>');          
       docprint.document.write(content_vlue);          
       docprint.document.write('</center></body></html>'); 
       docprint.document.close(); 
       docprint.focus();
}

function replaceString(sString, sReplaceThis, sWithThis) 
{ 
	if (sReplaceThis != "" && sReplaceThis != sWithThis)
		{ 
		var counter = 0; 
		var start = 0; 
		var before = ""; 
		var after = ""; 
		while (counter<sString.length) { 
		start = sString.indexOf(sReplaceThis, counter); 
		if (start == -1){ 
			break; 
		} else { 
		
			before = sString.substr(0, start); 
			after = sString.substr(start + sReplaceThis.length, sString.length); 
			sString = before + sWithThis + after; 
			counter = before.length + sWithThis.length; 
		} 
	} 
} 
return sString; 
} 
