    //This function returns the control with the given id
    function FindControl(controlID) {
	    for ( var i = 0; i < document.forms.length; i++ ) {
		    var theForm = document.forms[i];
		    var theControl = theForm[controlID];
		    if ( theControl != null ) {
			    return theControl;
		    }
	    }
	    return null;
    }
    
    //Prashant Jha : This function will return the control which has this string as part of its TagName.
	function FindControlByTagName(controlIDLike, tagType)
	{
		var elem = document.getElementsByTagName(tagType);
		for(var j = 0 ;  j < elem.length; j++)
		{
			var element = elem[j];
			var id = element.id;
	
			if(id.search(controlIDLike) != -1)
			{
			  return element;
			}
		}
	}
    
    //This function will return all the controls which has this string as part of its id.
      function FindControlLike(controlIDLike) {
		  
		var controlArray = new Array();
		for ( var i = 0; i < document.forms.length; i++ ) {
		    var theForm = document.forms[i];
		    var elem = theForm.elements;
		    
		    for(var j = 0;j < elem.length; j++)
		    {	
				var theControl = elem[j];
				var id = theControl.id;	
				
				if(id.search(controlIDLike) != -1)
				{
				    // alert("matched here");
					controlArray[controlArray.length] = theControl;
				}
			}
	    }
	    return controlArray;
    }
    
    //This function will trim the whitespaces of a string
    function Trim(s)  
    {
        // Remove leading spaces and carriage returns
          
        while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
        {
            s = s.substring(1,s.length);
        }

        // Remove trailing spaces and carriage returns

        while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
        {
            s = s.substring(0,s.length-1);
        }
        return s;
    }
    
    function onText(str){ window.status = str; return true }
    function offText(){ window.status = ""; return true }
    
    function currentArea(product, navArea) 
    {

	    if(navArea == "store" && document.archive != null){
		    document.archive.src = "/images/" + product + "_archive_over.gif";
    	
	    }
	    else if(navArea == "work" && document.collaborate != null){		
		    document.collaborate.src = "/images/" + product + "_collaborate_over.gif";
    	
	    }
	    else if(navArea == "send" && document.send != null){
		    document.send.src = "/images/" + product + "_send_over.gif";
	    }	
    		
}

    function isNull(s) { return ((s == null) || (s == "")); }

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}



/*Prashant- These method use for image rollover  */
//Rollover image from cursor.
var offsetfrommouse=[15,-25]; 
var currentImageHeight;
var imageSrc;
var captionId;
var hoverImgHtml = "";
//The image will appear on hover in this div. 
//Check for cross browser DOM.
if (document.getElementById || document.all)
{
	document.write('<div id="hoverimageid">');
	document.write('</div>');
}
//Used to get style for image rollover.
function getImageHover(){
if (document.getElementById)
	return document.getElementById("hoverimageid").style
else if (document.all)
return document.all.hoverimageid.style
}
//Used to get id of DIV for image rollover.
function getImageHoverStyleId(){
if (document.getElementById)
return document.getElementById("hoverimageid")
else if (document.all)
return document.all.hoverimageid
}
//Image rollover layout.
function bodyOfImage()
{
	//If page uses a doctype at the top of the page that causes IE6 to go into standards compliant mode (ie: XHTML strict), 
	//the way to accessing the DSOC properties in IE6 changes, namely, from document.body to document.documentElement.
	//whenever you're referencing the DSOC properties, your code should take into account the possibility of IE6 strict mode, 
	//and choose between document.documentElement and document.body, respectively.
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
//Function used to display image on hover.
function showImagePreview(imageSource, captId, assetHeight, assetWidth, maxSize)
{
	//If mediaType of image is "images" or "postscript" and user has comp 
	//Preview permission then image rollover will appear.
	//Set currentImageHeight with maxsize so that on the mouse move image 
	//display can manage.
	currentImageHeight = maxSize;
	//Set the value of all the global variable.
	imageSrc = imageSource;
	captionId = captId;
	//If asset height/width is null means if height and width of image is null in pni_caption table
	//(Generally for postscript mediatype) then return maxsize of image.
	if(isNaN(parseInt(assetHeight)) && isNaN(parseInt(assetWidth)))
	{
		getHeightWidthForImage(captionId);
	}
	else
	{
		var imageHtWt = new Array();
		//Find scaled height/width of image(Here we are scaling fullsize height/width of image).
		imageHtWt = getImageScaledHeightWidth(parseInt(assetHeight), parseInt(assetWidth), parseInt(maxSize));
		//Display image rolloover if height and width of asset is in correct format
		if(isDefinedValue(imageHtWt[0]) && isDefinedValue(imageHtWt[1]))
			displayImageRollover(imageHtWt[0], imageHtWt[1]);
	}
}
//Used to get scaled height/width of image.
function getImageScaledHeightWidth(assetHeight, assetWidth, maxSizeValue)
{
	var scaledHtWt = new Array();
	var divider;
	if((assetHeight < maxSizeValue) && (assetWidth < maxSizeValue))
	{
		scaledHtWt[0] = assetHeight;
		scaledHtWt[1] = assetWidth;
	}
	else if(assetHeight >= assetWidth)
	{
		scaledHtWt[0] = maxSizeValue;
		divider = assetHeight / maxSizeValue;
		scaledHtWt[1] = assetWidth / divider;
		scaledHtWt[1] = (scaledHtWt[1] + 0.5);
		scaledHtWt[1] = Math.floor(scaledHtWt[1]);
	}
	else if(assetHeight < assetWidth)
	{
		scaledHtWt[1] = maxSizeValue;
		divider = assetWidth / maxSizeValue;
		scaledHtWt[0] = assetHeight / divider;
		scaledHtWt[0] = (scaledHtWt[0] + 0.5);
		scaledHtWt[0] = Math.floor(scaledHtWt[0]);
	}
	return scaledHtWt;
}
//Display image rollover.
function displayImageRollover(imageHt, imageWt)
{
	var delayForMouseoverHover = 1000; //1 sec
	//Here method call for mousemove. The image will move with mouse cursor.
	document.onmousemove=moveImageWithCursor;
	//This is layout for image rollover. Currently Image rollover contains the image, captionId and asset Name.
	//We can add more items. 
	
	hoverImgHtml = '<div class="hoverlayout">';
	hoverImgHtml = hoverImgHtml + '<div align="center" class="hoverImageLayout" style="width:'+ currentImageHeight + '"><img src="' + imageSrc + '" height='+ imageHt +' width='+ imageWt +' border="0"></div>';
	
	hoverImgHtml = hoverImgHtml + '</div>';
	var version=0;
	//Check whether the IE version is less than 7. For IE(i.e. IE6, IE5) the iframe is required
	//to cover <select> box.This is bug for IE which lesser version(i.e. <IE7).
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	var temp=navigator.appVersion.split("MSIE");
	version=parseFloat(temp[1]);
	if(version < 7)
	{
		getImageHoverStyleId().innerHTML =  hoverImgHtml;
		var iframeHeight = getImageHoverStyleId().offsetHeight + "px";
		var iframeWidth  = getImageHoverStyleId().offsetWidth + "px";
		getImageHoverStyleId().innerHTML = ('<iframe src="/images/spacer.gif" style="position: absolute;left: 0px;top: 0px;z-index: -1;filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" height="'+ 
			iframeHeight +'" width="'+ iframeWidth +'" scrolling="no" frameborder="0"></iframe>'+ hoverImgHtml);
	}
	else
		getImageHoverStyleId().innerHTML =  hoverImgHtml;
	}
	else
		getImageHoverStyleId().innerHTML =  hoverImgHtml;
	//Set delay. Currently image will after 1 sec. on hover.
	window.setTimeout('makeVisible()', delayForMouseoverHover);
	//getImageHover().visibility="visible";
}
//Display image rollover after some delay.
function makeVisible()
{
	getImageHover().visibility="visible";
}

//Hide image on mouseout.
function hideImagePreview()
{
	getImageHover().visibility="hidden";
	hoverImgHtml = "";
	document.onmousemove="";
	getImageHover().left="-500px";
}

//Check for correct value
//Function checks if value is not in correct format 
//return false
function isDefinedValue(chkValue)
{
	if(chkValue == "" || chkValue == null || chkValue == 'undefined')
		return false;
	return true;
}
//Used to move image with mouse cursor.
function moveImageWithCursor(e)
{	
	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];
	var docwidth=document.all? bodyOfImage().scrollLeft+bodyOfImage().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.min(bodyOfImage().scrollHeight, bodyOfImage().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight);	
	if (typeof e != "undefined")
	{
		if (docwidth - e.pageX < currentImageHeight){
			xcoord = e.pageX - xcoord - (currentImageHeight + 25);
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentImageHeight + 40)){
			ycoord += e.pageY - Math.max(0,(40 + currentImageHeight + e.pageY - docheight - bodyOfImage().scrollTop));
		} else {
			ycoord += e.pageY;
		}
	} 
	else if (typeof window.event != "undefined")
	{		
		if (docwidth - event.clientX < currentImageHeight){
			xcoord = event.clientX + bodyOfImage().scrollLeft - xcoord - (currentImageHeight + 25);
		} else {
			xcoord += bodyOfImage().scrollLeft+event.clientX;
		}
		if (docheight - event.clientY < (currentImageHeight + 60)){
			ycoord += event.clientY + bodyOfImage().scrollTop - Math.max(0,(60 + currentImageHeight + event.clientY - docheight));
		} else {
			ycoord += bodyOfImage().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? bodyOfImage().scrollLeft+bodyOfImage().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.max(bodyOfImage().scrollHeight, bodyOfImage().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	getImageHover().left=xcoord+"px";
	getImageHover().top=ycoord+"px";
}

// global flag
var isIE = false;

 // global request and XML document objects
var req;
var htwt;
function getHeightWidthForImage(captionId)
{
    var parameters = "type=imagedimensions&assethtwt_caption_id=" +captionId;
    parameters += GetRandomParameter();
    var result =loadXMLDocument("/common/ProcessXMLHttpReq.aspx?" + parameters);

    if(!result)
    {

    }
}

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
//from processRequestChange we call function to display image
//rollover.
function loadXMLDocument(url)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();

        req.onreadystatechange = processRequestChange;
        req.open("GET", url, true);
        req.send(null);    
    }
     // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject)
    {
        isIE = true;
        req = getxmlhttp();
        if (req)
        {
            req.onreadystatechange = processRequestChange;
            req.open("GET", url, true);
            req.send();
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
}
//This function is used to override the cache.
function GetRandomParameter()
{
	return "&XMLR296=" + (Math.round((Math.random()* 10000000000)));
}
//function used to collect height and width of image 
//and call displayImageRollover to display rollover
 function processRequestChange()
 {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            var imageHgtWdt = new Array();
            var htwt = (req.responseText).split(",");
            imageHgtWdt = getImageScaledHeightWidth(parseInt(htwt[0]), parseInt(htwt[1]), parseInt(currentImageHeight));
            //Display image rolloover if height and width of asset is in correct format
            if(isDefinedValue(imageHgtWdt[0]) && isDefinedValue(imageHgtWdt[1]))
                displayImageRollover(imageHgtWdt[0], imageHgtWdt[1]);
         }
        else if (req.status == 400)
        {
            if(req.responseText.search(/MediaPartner Session Expired/) != -1 )
            {
                window.location = window.location;
                return;
            }
        }
           /* else {
            alert("There was a problem to find height and width of image:\n" +
                req.statusText);
         }*/
    }
}

// Function escapes embedded single quotes in a string
function escapeQuote(str)
{
    if(str == null || str == "") 
        return "";
    
    // Escape embedded single quotes(') by (\')
    str2 = str.replace(/'/g, "\\\'");
    return str2;
}

//Function to get the version of IE
function getIEVersion()
{
	var temp=navigator.appVersion.split("MSIE");
	var version=parseFloat(temp[1]);   
	return version;
}
//Kyocera Customization 
function show()
{
return true;
}

function hide()
{
    return true;
}
function openPopUpWindow(url, wHeight, wWidth)
{
	var win = eval("window.open(url,'pop_up','height=' + wHeight + ',width=' + wWidth + ',scrollbars=yes,resizable=yes')");
	win.focus();
}
