﻿function showprofile(profileid, folder, thespanid)
{
       //alert("in method!");
		var xmlHttp
		//build product information to be sent to the server
		var params = "folder=" + replaceIllegalCharactersWithEquals(folder) + "&profileid=" + replaceIllegalCharactersWithEquals(profileid);
		//server page for dealing with adding a product
		var url = "GetProfile.aspx";
		var theBasketStr=""

		//build a connection
		xmlHttp = newConnection();
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		//handle the result
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				try
				{
					//new basket returned from the server
					theBasketStr=xmlHttp.responseText;
					showDiv("showProfilePlaceholder","99999")
					*fixPosXPB("showProfilePlaceholder", 220, "postioningplacement")
					fixPosYPB("showProfilePlaceholder", 0, "postioningplacement")
					document.getElementById("showProfilePlaceholder").innerHTML = theBasketStr;
					
					
				}
				catch (exc)
				{
					document.write("ex is " + xmlHttp.responseText);
				}
				
				
						
			}
		}
		//post product data to the server
		xmlHttp.send(params);
	
	
		//return false so no page reload takes place
	return false;
	    
}

//close any div
function closeDiv(divName)
{
	document.getElementById(divName).style.display="none";
	document.getElementById(divName).style.zIndex="1";
}

// show any div ia a z index and display value, default is 99999
function showDiv(divName, zIndex)
{
	if (zIndex.length < 1)
	{
		zIndex = "99999";
	}
	document.getElementById(divName).style.display="";
	document.getElementById(divName).style.zIndex=zIndex;
}

//get rid of white space from end of string
function trimEnd(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}

//get the current browser width, this is useful for when browser windows are resized
function getBrowserWidth() {
  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;
  }
  return myWidth;
  //window.alert( 'Height = ' + myHeight );
}

//fixes the element(theElementID) a set  x distance(ex) away from a element anchor(positionWith)
function fixPosXPB(theElementID, ex, positionWith)
{
	
	
	var theElement = document.getElementById(theElementID);
	var obj = document.getElementById(positionWith);
	var curleft = 0;
				
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	
	theElement.style.left=(parseInt(curleft)+parseInt(ex) - ((parseInt(getBrowserWidth())-800)/2)) + "px";
   
   
}

//fixes the element(theElementID) a set  y distance(ey) away from a element anchor(positionWith)
function fixPosYPB(theElementID, ey, positionWith)
{
    
	var theElement = document.getElementById(theElementID);
	var obj = document.getElementById(positionWith);	
	var curtop = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
		
	theElement.style.top = (parseInt(curtop)+parseInt(ey)) + "px";
	
	
   
			
}


function replaceIllegalCharactersWithEquals(theStr)
{
	theStr = theStr.replace(/^\s+|\s+$/g, '');
	theStr = theStr.replace("&", '%amp%');
	theStr = theStr.replace("?", '%que%');
	theStr = theStr.replace("@", '%at%');
	theStr = theStr.replace("#", '%hash%');
	theStr = theStr.replace("!", '%exp%');
	theStr = theStr.replace("$", '%dollor%');
	theStr = theStr.replace("£", '%pound%');
	theStr = theStr.replace("\'", '%squ%');
	theStr = theStr.replace("\"", '%dqu%');
	theStr = theStr.replace("+","%2B");
	theStr = theStr.replace("=","%eq%");
	
	return theStr;
	
}

function hideshowmoredetails(dowhat, spanid, imagetableid, descriptionid)
{
    if (dowhat=='show')
    {
        document.getElementById(spanid).onclick = function(){hideshowmoredetails('hide', spanid, imagetableid, descriptionid)};
        document.getElementById(imagetableid).style.display="";
        document.getElementById(descriptionid).style.display=""; 
        document.getElementById(spanid).innerHTML = "Hide";
         
    }
    else
    {
        document.getElementById(spanid).onclick = function(){hideshowmoredetails('show', spanid, imagetableid, descriptionid)};  
         document.getElementById(imagetableid).style.display="none";
        document.getElementById(descriptionid).style.display="none"; 
        document.getElementById(spanid).innerHTML = "Detail";
    }
}


