//call ststs and then navigate to another location
//using it only when not using ZShyperlink or SZhyperlinkImage
function HLSN(PID, CID, SZU, QS, NAV)
{
HLS(PID, CID, SZU, QS);
if(NAV != '-1')
location = NAV;
}
//make the actual call for the stats 
function HLS(PID, CID, SZU, QS) 
{ 
var u = "/stats/ClickStat.aspx?PID=";
u = u.concat(PID).concat("&CID=").concat(CID).concat("&SZU=").concat(SZU);
if(QS != '-1')
u = u.concat("&QS=").concat(QS);
//update the image if we already added it
if(document.images["HLSim"])
document.images["HLSim"].src = u;
else
{	
var im = new Image(); 
im.width = 0; 
im.id = "HLSim"; 
document.body.appendChild(im); 
document.images["HLSim"].src = u; 
im.style.display = "none";
im = null;//release the memory
}
}
//----------------------------------------------------------
//download the file and then redirect to another file after 3 sec - lets the aspx that does the downloat dime to work
//Nav - path to navigate after download
function DownloadRedirect(NAV,DfileNav)
{
if(NAV != null && DfileNav != null)
{
location = DfileNav;
setTimeout("location='" + NAV +"'",3000);
}
}
//var dWin;
function DownloadImg(NAV) 
{
if(NAV != null)
{
location = NAV;
//the following lines will "solve" the IE problem - this doesn't solve the problem right
//		if(dWin != null && !dWin.closed)
//			dWin.close();
//		dWin = window.open(NAV,"","top=40,left=40,width=200,height=200")
//		setTimeout("dWin.close();",2000); //close the window after 2 seconds
}
}
//----------------------------------------------------------
document.onkeypress = doKeyPress; 
//TODO - check if we need this function
function doKeyPress(e) { 
if (window.event.keyCode==13)  // Enter key
return;
}
//-----------------------------------------------------------
//will search for the string sRedDel, if it exists will redirect to the url that comes after it
//sData: input string from the callback - "Redirect:http://www.google.com"
//sCtrl: Id of the control we are operating on
//bPS: if 1 then we should do postBack if there is no redirect via sRedDel
//bRD: set at the AjaxControl, if = True : will round all the child elements of this control
function DoAjax(sData, sCtrl, bPS, bRD)
{
var sRedDel = "Redirect:";
if( StrNcompare(sData,sRedDel,0) == 1)
{
document.location.href= sData.substr(sRedDel.length); //if we got here - redirect
return; //so we won't show the url till we redirect
}
if(bPS == 1)
document.location.href = sData;
else
{ 	
var elem = document.getElementById(sCtrl);
elem.innerHTML = sData; //perform ajax operation
if(bRD == "True")
makeElementCorners(elem);
}
}
//------------------------------------------------------
//return 1 if sMatch is found within sSource starting at index nSidx
function StrNcompare(sSource, sMatch, nSidx)
{
var nCompIdx = nSidx;
for(idx = 0; idx < sMatch.length; ++idx)
{
if(sSource.charAt(nSidx) != sMatch.charAt(idx))
return 0;
++nSidx;	
}
return 1;//for found match
}
// Write flash object with or without params, this function may be called from <script> context anywhere in the html code 
function WriteFlashCode(swfSrc, ObjId, w, h, wmode, FlashVars) 
{
document.write('<object ' + 'id=' + ObjId + ' width="'+ w +'" height="'+ h +'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">');
document.write('<param name="movie" value="'+ swfSrc +'" />');
document.write('<param name="quality" value="high" />');        
document.write('<param name="wmode" value="'+ wmode +'" />');
if (FlashVars != null)
document.write('<param name="FlashVars" value="'+ FlashVars +'" />');
document.write('<embed src="'+ swfSrc + '"  wmode="'+ wmode + '"');
if (FlashVars != null)
document.write(' FlashVars="' + FlashVars + '"');
document.write(' quality="high" "width="'+ w +'" height="'+ h +'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" />');
document.write('</object>');
}
function WriteToDocument (_sData)
{
document.write(_sData);
}	
//hide cHide and show cShow
//input should be an object and not an id
function toglCtrlVis(cHide,cShow)
{
if(cHide != null)
cHide.style.display = "none";
if(cShow != null)
cShow.style.display = "inline";
}
//just hide an element by its ID
function HideCtrlById(objId)
{
var el = document.getElementById(objId);
if(el) el.style.display = 'none';
}
//just Show an element by its ID
function ShowCtrlById(objId)
{
var el = document.getElementById(objId);
if(el) el.style.display = 'inline';
}
//toggle the visibility of a control by it's ID
//input: string 
function toggleCtrlById(objId) 
{
var el = document.getElementById(objId);
if(el == null) return;
if ( el.style.display != 'none' ) 
el.style.display = 'none';
else 
el.style.display = '';
}
// get's ID of element, calculate Top according to scrollY position, then shows it
// can send top, left = null/0 - default values will be set
function ShowElem(id, top, left)
{
if (id == null) return;
oElem = document.getElementById(id);
if(oElem == null) return;
// set default values for Top & Left if no positions has sent
if (top == null || top == 0)
top = (document.body.scrollTop + 200);
if (left == null || left == 0)
left = ((screen.width / 2) - 200);
oElem.style.top = top;
oElem.style.left = left;
oElem.style.display = 'block';
}
//--------------------------------
//attach this function to the client onclick event of a button to make it submit only at the first click 
function DisableBtn() {
document.forms[0].submit();
window.setTimeout("InnerDisableButton('" + window.event.srcElement.id + "')", 0);
}
//helper function to the above function
function InnerDisableButton(buttonID) {
document.getElementById(buttonID).disabled=true;
}
//-----------------------------------------------------------
//copy the data from an asp:textBox to the clipbord
//NOTE: dont work on fireFox
function CopyToClipboard(sControl, sMessage)
{
//debugger;
if(sControl == "")
return;
var Control = document.getElementById(sControl);
if(Control == null)
return;
Control.select(); // text selection
var oo = document.createElement('textarea'); 
document.body.appendChild(oo);
oo.style.display = 'none';//hide the appended element
oo.innerText = Control.innerText; //if the textBox is multiline
oo.value = Control.value; //for single line textBox
Copied = oo.createTextRange();    
Copied.execCommand("Copy"); // copy selected text to Clipboard
alert(sMessage);
}
//--------------------------------------- cookies ---
///cookies functions, taken from http://www.dustindiaz.com/top-ten-javascript/
//also look at http://www.quirksmode.org/js/cookies.html for more info
function getCookie( name )
{
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ';', len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
//expires - days to expire, leave it empty so the cookie will die when you close the browser
//path - leave empty or set it to '/' - which means the cookie is valid throughout the entire domain
//domain - to which domain the cookie should be sent. If you don't specify it, it becomes the domain of the page that sets the cookie 
function setCookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
var cookieStr = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' );
document.cookie = cookieStr;
}
function deleteCookie( name, path, domain )
{
if ( getCookie( name ) ) document.cookie = name + '=' +
( ( path ) ? ';path=' + path : '') +
( ( domain ) ? ';domain=' + domain : '' ) +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
//--------------------------------------- cookies ---
//function BindElems(sEID, sScriptOver, sScriptOut, sBindEID, sBindScriptOver, sBindScriptOut)
//{
//    if(sEID == null || sBindEID == null)
//        return;
//        
//    objElem = document.getElementById('sEID');
//    if(objElem == null)
//        return;
//        
//    objBindElem = document.getElementById('sBindEID');
//    if(objBindElem == null)
//        return;
//        
//    alert(objElem.onMouseOver());
//}
//returns the current scroll position
//from http://www.quirksmode.org/viewport/compatibility.html
function GetScroll()
{
var x,y;
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
var arrScroll = new Array(x,y) 
return arrScroll;
}
//gets the size of the total page (usually the body element). 
function GetPageSize()
{
var x,y;
var scrollH = document.body.scrollHeight;
var offsetH = document.body.offsetHeight
if (scrollH > offsetH) // all but Explorer Mac
{
x = document.body.scrollWidth;
y = document.body.scrollHeight;
}
else // Explorer Mac;//would also work in Explorer 6 Strict, Mozilla and Safari
{
x = document.body.offsetWidth;
y = document.body.offsetHeight;
}
var arrSize = new Array(x,y) 
return arrSize;
}
//---------- iframe functions start
//open the Iframe at a specified size
function DoMDF (sSrc, width, height)
{
if (sSrc == null) return false;
//verify width and height
width = (width && width > 0) ? width : 100; 
height = (height && height > 0) ? height : 100; 
toggleCtrlById("MDFAll"); //first show the wrapper div
var elPageCover = document.getElementById ("MDFP");	
var elIframeContainer = document.getElementById ("MDFC");	
var elIframe = document.getElementById ("MDFIframe");	
//get pageSize and scroll
var pSize = GetPageSize(); 
if(pSize == null)
arrSize = new Array(width,height)
var ScrollLoc = GetScroll();
if(ScrollLoc == null)
ScrollLoc = new Array(0,0);	 
if(elPageCover != null)
{
elPageCover.style.display = "inline";
//	elPageCover.style.width = pSize[0] + "px"; //the table at the skin takes care of this
elPageCover.style.height = pSize[1] + "px";
}
if(elIframeContainer != null)
{
elIframeContainer.style.display = "inline";
elIframeContainer.style.width = width + "px";
elIframeContainer.style.height = height + "px";
var ScrollLoc = GetScroll();
if(ScrollLoc)
{
var left = (pSize[0] - width)/2;//this will position the Iframe at the center
elIframeContainer.style.left = left;
elIframeContainer.style.top = ScrollLoc[1];
}
}
if(elIframe != null)
{	
elIframe.style.width = width + "px";
elIframe.style.height = height + "px";
elIframe.src = sSrc;
}
pSize = null;
ScrollLoc = null;
return false;
}
//close the modal
function CloseMDF(){ toggleCtrlById("MDFP"); toggleCtrlById("MDFC"); }
//refresh the parent from an iframe
function RefreshParent() { window.parent.location.href = window.parent.location.href; }
//---------- iframe functions end
