///////////////////////////////////////////////////////////////////
//	//
//	Javascript functions for tix/SYS On-Line Film Guide	//
//	//
//	copyright (c) 2000 synercom/edi - All Rights Reserved	//
//	//
//	written by Arne F. Hermann	//
//	//
//	//
////////////////////////////////////////////////////////////////////
function tixSYS_body_onload() {
/**
* tixSYS_body_onload(); is a content replacement
*	item - this function is to keep the call valid
*	should it not be replaced. - dt - 20051121
*/
}


function getObject( obj ) {
// step 1
if ( document.getElementById ) {
obj = document.getElementById( obj );
// step 2
} else if ( document.all ) {
obj = document.all.item( obj );
//step 3
} else {
obj = null;
}
//step 4
return obj;
}

function displayObject( obj, show ) {

// step 1
obj = getObject( obj );
if (obj==null) return;

// step 2
obj.style.display = show ? 'block' : 'none';
obj.style.visibility = show ? 'visible' : 'hidden';
}



/**
* This use by pkg mode to move parent window to login via
*	the addtoplanner routine
*/
function goParent(loc){
var parentwin = window.opener;
var grandparentwin = parentwin.opener;
if(grandparentwin){
grandparentwin.location.href=loc;
window.close();
}
if(parentwin){
parentwin.location.href=loc;
window.close();
}
}



function AddToCart(FCode) {
var WinName = window.name;
document.AddCodeForm.AddCode.value = FCode;
hAddWin=window.open("/tixSYS/2007/filmguide/addtocart.php?FCode=" + FCode,"AddWindow","width=400,height=200,left=200,top=300,scrollbars=no,toolbar=no,status=no,directories=no,location=no,menubar=no,resizable=no");
}

function AddToPkg(FCode,PageFrom) {
document.AddCodeForm.AddCode.value = FCode;
hAddWin=window.open("addtoplannerpkg.php?FCode=" + FCode + "?PageFrom="+PageFrom,"AddWindow","width=400,height=200,left=200,top=300,scrollbars=no,toolbar=no,status=no,directories=no,location=no,menubar=no,resizable=no");
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//	Function to correct for 2.x Mac date bug.
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0)	// Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew);
}
//	Function to return the value of the cookie specified by "name".
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return "NOTSET";
}
//	Function to create or update a cookie.
function SetCookie (name,value,expires,path,domain,secure) {
//var tett = new Date();

//alert(tett.toGMTString(expires));
path="/";
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
//	Function to delete a cookie. (Sets expiration date to start of epoch)
function DeleteCookie (name,path,domain) {
path="/";
if (GetCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function UpdateTotals(FCode,SChgType,SChgAmt,MaxTix) {

var Amount = 0;
var Quantity = 0;
var DAmount = "";
var HChgAmount = 0;
var pr="";
var qq = "";
var Elem = "";
var numelems = document.OrderForm.length;
for (var ii=0; ii < numelems; ii=ii+1) {
Elem = document.OrderForm.elements[ii];
FCode = Elem.name;
if (FCode.substr(0,1) == "Q"){
pr = eval("document.OrderForm.Price" + FCode.substr(1) + ".value");
qq = Elem.selectedIndex;
Amount += qq * pr;
if (FCode.substr(1,1) != "i") {
//eval qty for NON-ITEMS (i.e. tickets) only
Quantity += parseFloat(qq);
}
if (Quantity > MaxTix) {
alert("You can only select a maximum of " + MaxTix + " tickets on a single ticket order.	\nThe Qty for this show will be reset to zero.")
Quantity = Quantity - Elem.selectedIndex;
Elem.selectedIndex = 0;
}
}
}
//Fix the format of Amount...
if (Amount > 0) {
// Add in will-call handling charge
switch (SChgType) {
case 'P':	//Percentage of Order Total
Amount = parseFloat(Amount) + (Amount * parseFloat(SChgAmt));
break;
case 'F':	//Flat Rate per Order
Amount = parseFloat(Amount) + parseFloat(SChgAmt);
HChgAmount = parseFloat(SChgAmt);
break;
case 'T':	//Flat Rate per Ticket
Amount = parseFloat(Amount) + (parseFloat(SChgAmt) * Quantity);
HChgAmount = parseFloat(SChgAmt) * Quantity;
break;
}

if (document.getElementById('MailOrder').checked) {
// Hamptons Specific for $1 mail charge
//Amount = Amount + 1;
//document.OrderForm.MailOrderChg.value = "1.00";
}

//Format to [nnn]n.dd
Amount = (Math.ceil(Amount * 100))/100;
DAmount = "A"+Amount;
DAmount = DAmount.substr(1);
if (DAmount.indexOf(".") < 1) {
DAmount = DAmount + ".00";
}
else {
DAmount = DAmount + "00";
DAmount = DAmount.substr(0,DAmount.indexOf(".")+3);
}

HChgAmount = "A"+HChgAmount;
HChgAmount = HChgAmount.substr(1);
if (HChgAmount.indexOf(".") < 1) {
HChgAmount = HChgAmount + ".00";
}
else {
HChgAmount = HChgAmount + "00";
HChgAmount = HChgAmount.substr(0,HChgAmount.indexOf(".")+3);
}

}
document.OrderForm.OrderAmount.value = DAmount;
document.OrderForm.HChgAmount.value = HChgAmount;
document.OrderForm.NumberTix.value = Quantity;
}

//php document related functions
function swapImgRestore() { //v3.0
var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.p) d.p=new Array();
var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function findObj(n, d) { //v4.0
var p,i,x;	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function swapImage() { //v3.0
var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.p) d.p=new Array();
var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function swapImgRestore() { //v3.0
var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function findObj(n, d) { //v3.0
var p,i,x;	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}
function swapImage() { //v3.0
var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function WinOpen(height,width,url)
{
window.open(
url,
"RegHelp",
"toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no,height="+height+",width="+width);
}
function WinOpenFullAttr(height,width,url,popname,fullattr)
{
window.open(
url,
popname,
fullattr + "," + "height=" + height + ",width=" + width);
}
// Form Processing Javascript
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
//setTimeout('alert("Your form has been submitted.	Notice how the submit and reset buttons were disabled upon submission.")', 2000);
return true;
}
else {
alert("Your order is now being processed. This may take a minute or two, so please be patient. Do NOT click the submit button again or you will get an error.");
//return false;
}
}
function phpFilmNotePopup(FC) {
var H = screen.height - 300;
H = 470;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("filmnote.php?FCode=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
FilmNotePopup.focus();
}
function phpProgNotePopup(FC) {
var H = screen.height - 300;
H = 500;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("/tixSYS/2007/filmguide/prognote.php?notepg=1&ProgCode=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
FilmNotePopup.focus();
}
function phpEventNotePopup(FC) {
var H = screen.height - 300;
H = 500;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("/tixSYS/2007/filmguide/eventnote.php?notepg=1&EventNumber=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
FilmNotePopup.focus();
//if( FilmNotePopup ) { alert('went up'); }
//if( !FilmNotePopup ) { alert('not up'); }
}
function phpDirBioPopup(FC) {
var H = screen.height - 300;
H = 500;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("/tixSYS/2007/filmguide/dirbio.php?notepg=1&DirectorID=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
//if( FilmNotePopup ) { alert('went up'); }
//if( !FilmNotePopup ) { alert('not up'); }
FilmNotePopup.focus();
}
function phpVenuePopup(FC) {
var H = screen.height - 300;
H = 500;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("/tixSYS/2007/filmguide/venue.php?notepg=1&VenueCode=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
//if( FilmNotePopup ) { alert('went up'); }
//if( !FilmNotePopup ) { alert('not up'); }
FilmNotePopup.focus();
}






function phpTrailerPopup(FC) {
var H = screen.height - 300;
H = 500;
var W = 720;
var AtX = 25;
var AtY = 25;
FilmNotePopup=window.open("trailer.php?EventNumber=" + FC,"popup","width=" + W + ",height=" + H +",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=no,status=yes,directories=no,location=no,resizable=yes,menubar=no");
}

function ShowHide(id, visibility) {
divs = document.getElementsByTagName("div");
divs[id].style.visibility = visibility;
}
function IMDBFilmPopup(theFilmURL){
var H = screen.height - 200;
var W = screen.width - 200;
var AtX = 50;
var AtY = 50;
FilmNotePopup=window.open("http://us.imdb.com/title/tt" + theFilmURL,"imdb","width=" + W + ",height=" + H + ",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=yes,status=yes,directories=yes,location=yes,resizable=yes,menubar=yes");
}
function IMDBDirectorPopup(theDirNum){
var H = screen.height - 200;
var W = screen.width - 200;
var AtX = 50;
var AtY = 50;
FilmNotePopup=window.open("http://us.imdb.com/name/nm" + theDirNum,"imdb","width=" + W + ",height=" + H + ",left=" + AtX + ",top=" + AtY + ",scrollbars=yes,toolbar=yes,status=yes,directories=yes,location=yes,resizable=yes,menubar=yes");
}
function validateQuickForm(theform) {
var result = false;
var numElements = theform.elements.length;
var broken = true;
var numEntries = 0;
var brokenEntries = 0;
for (i = 0; i < numElements; i++){
var contentLength = theform.elements[i].value.length;
if(contentLength > 0){
numEntries++;
if(contentLength < 5){
brokenEntries++;
}
}
}
if((brokenEntries > 0) || (numEntries == 0)){
alert("There appears to be a problem with your form.\n	You must enter at least ONE Film Code\n and Film Codes must all be 5 characters in length.");
result = false;
}
else{
result = true;
}
return result;
}
function replaceSubstring(inputString, fromString, toString) {
// Goes through the inputString and replaces every occurrence of fromString with toString
var temp = inputString;
if (fromString == "") {
return inputString;
}
if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
var midStrings = new Array("~", "`", "_", "^", "#");
var midStringLen = 1;
var midString = "";
// Find a string that doesn't exist in the inputString to be used
// as an "inbetween" string
while (midString == "") {
for (var i=0; i < midStrings.length; i++) {
var tempMidString = "";
for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
if (fromString.indexOf(tempMidString) == -1) {
midString = tempMidString;
i = midStrings.length + 1;
}
}
} // Keep on going until we build an "inbetween" string that doesn't exist
// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + midString + toTheRight;
}
// Next, replace the "inbetween" string with the "toString"
while (temp.indexOf(midString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(midString));
var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} // Ends the check to see if the string being replaced is part of the replacement string or not
return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

/* GRID */
function movegrid(){ // centers grid in window.
var gridWidth = document.getElementById('venuebar').style.width;
gridWidth = replaceSubstring(gridWidth, "px", "")
var winW = 630, winH = 460;
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}
var leftoffset = (winW - gridWidth)/2 - 35;
var allDivs = document.all.tags('div');
var leftpx;
for(var i = 0; i < allDivs.length; i++){
leftpx = allDivs[i].style.left;
if(leftpx.length > 0){
leftpx = leftpx.substring(0,leftpx.indexOf('px'));
var newleft = parseInt(leftpx) + leftoffset;
allDivs[i].style.left = newleft;
}
}
}
var speed, currentpos=curpos1=0, alt=1, curpos2=-1
function initializeScroll(){
if (window.parent.scrollspeed!=0){
speed=window.parent.scrollspeed
scrollwindow();
}
}
function scrollwindow(){
temp=(document.all)? document.body.scrollLeft : window.pageXOffset;
alt=(alt==0)? 1 : 0;
if(alt==0){
curpos1=temp;
}
else{
curpos2=temp;
}
window.scrollBy(speed,0);
}


/* MM IMAGE SWAPPING */
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* IMAGE SWAPPING */
function changeImage(imageName, newImage) {
document.images[imageName].src = newImage;
}

/* COOKIES */
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {begin += 2;}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {end = dc.length;}
return unescape(dc.substring(begin + prefix.length, end));
}

/* MESSAGES */
function tixSYS_displayTestMessages() {
tm = document.getElementById("test_messages");
//tm.onclick = function () {
//	tm.style.display = 'none';
//}
//setTimeout('tm.style.display = "none";', 15000);
}
function tixSYS_displayUserMessages() {
um = document.getElementById("userMessages");
um.onclick = function () {
um.style.display = 'none';
}
setTimeout('um.style.display = "none";', 15000);
}

function AMEXTermsPopup() {
window.open("AMEXPopup.php",'AMEXPopup','toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=470,height=520,top=100');
}


function sha1Hash(msg)
{
// constants [§4.2.1]
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];


// PREPROCESSING

msg += String.fromCharCode(0x80); // add trailing '1' bit to string [§5.1.1]

// convert string msg into 512-bit/16-integer blocks arrays of ints [§5.2.1]
var l = Math.ceil(msg.length/4) + 2;  // long enough to contain msg plus 2-word length
var N = Math.ceil(l/16);              // in N 16-int blocks
var M = new Array(N);
for (var i=0; i<N; i++) {
M[i] = new Array(16);
for (var j=0; j<16; j++) {  // encode 4 chars per integer, big-endian encoding
M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) |
(msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
}
}
// add length (in bits) into final pair of 32-bit integers (big-endian) [5.1.1]
// note: most significant word would be ((len-1)*8 >>> 32, but since JS converts
// bitwise-op args to 32 bits, we need to simulate this by arithmetic operators
M[N-1][14] = ((msg.length-1)*8) / Math.pow(2, 32); M[N-1][14] = Math.floor(M[N-1][14])
M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;

// set initial hash value [§5.3.1]
var H0 = 0x67452301;
var H1 = 0xefcdab89;
var H2 = 0x98badcfe;
var H3 = 0x10325476;
var H4 = 0xc3d2e1f0;

// HASH COMPUTATION [§6.1.2]

var W = new Array(80); var a, b, c, d, e;
for (var i=0; i<N; i++) {

// 1 - prepare message schedule 'W'
for (var t=0;  t<16; t++) W[t] = M[i][t];
for (var t=16; t<80; t++) W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);

// 2 - initialise five working variables a, b, c, d, e with previous hash value
a = H0; b = H1; c = H2; d = H3; e = H4;

// 3 - main loop
for (var t=0; t<80; t++) {
var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants
var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
e = d;
d = c;
c = ROTL(b, 30);
b = a;
a = T;
}

// 4 - compute the new intermediate hash value
H0 = (H0+a) & 0xffffffff;  // note 'addition modulo 2^32'
H1 = (H1+b) & 0xffffffff;
H2 = (H2+c) & 0xffffffff;
H3 = (H3+d) & 0xffffffff;
H4 = (H4+e) & 0xffffffff;
}

return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
}

function removeNonNumeric( strString )
{
// Variables
var strValidCharacters = "1234567890";
var strReturn = "";
var strBuffer = "";
var intIndex = 0;


// Loop through the string
for( intIndex = 0; intIndex < strString.length; intIndex++ )
{
// Get this character
strBuffer = strString.substr( intIndex, 1 );

// Is this a number
if( strValidCharacters.indexOf( strBuffer ) > -1 )
{
// Yes
strReturn += strBuffer;
}
}

// Return the value
return strReturn;
}


//
// function 'f' [§4.1.1]
//
function f(s, x, y, z)
{
switch (s) {
case 0: return (x & y) ^ (~x & z);           // Ch()
case 1: return x ^ y ^ z;                    // Parity()
case 2: return (x & y) ^ (x & z) ^ (y & z);  // Maj()
case 3: return x ^ y ^ z;                    // Parity()
}
}

//
// rotate left (circular left shift) value x by n positions [§3.2.5]
//
function ROTL(x, n)
{
return (x<<n) | (x>>>(32-n));
}

//
// extend Number class with a tailored hex-string method
//   (note toString(16) is implementation-dependant, and
//   in IE returns signed numbers when used on full words)
//
Number.prototype.toHexStr = function()
{
var s="", v;
for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
return s;
}






