/*
 * Coder: Mario Hartmann [mario@hartmann.net // http://mario.hartmann.net/]
 * Copyright: 2006, Photocolor Kreuzlingen AG
 * Original version: Javascipt
 * Original product name: Photocolor Kreuzlingen AG WebFramework
 * Official site: http://www.Ifolor.ch
 * Last updated Date:11-JAN-2006
 * Derivate works, translation in other languages
 * of this code must retain this copyright notice.
*/
// =====================================================
// global variables
// -----------------------------------------------------
var m_debug				= false;			// debuggin on/off 
var m_DebugWindow;							// debug window 
var m_waitTarget = '';
var m_MsgPopUpBlocker ='Popupblocker?';
var m_hideCounter=0;
var browser = new BrowserDetect();

// =====================================================
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isFirefox    = (ua.indexOf('firefox/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE50 = (this.isIE && this.versionMinor == 5.0);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
// =====================================================
// general functions
//
// -----------------------------------------------------
//       
function JumpToAnchor(anchorName)
{
	theAnchor = GetControl(anchorName);
	if (theAnchor)
	    window.location.hash = anchorName;
}
// -----------------------------------------------------
//    
function handleEnter (field, event, postBackValue) 
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){if (postBackValue){__doPostBack(postBackValue,''); return false;}else{return false;}}else{return true};
}   
// -----------------------------------------------------
//
function AddPreloadImg(imgSrc)
{
	_newImg = new Image();
	_newImg.src = imgSrc;
	_index = m_preLoadedImages.length;
	this.m_preLoadedImages[_index]=_newImg;
}
// -----------------------------------------------------
//
function OpenInfo(link,returnVal)
{
	var theFeats = 'height=600,width=570,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
	PhotoProductsInfo = window.open(link,"PhotoProductsHelp", theFeats)
	if(PhotoProductsInfo)
	{
		PhotoProductsInfo.focus();
		if (returnVal)
			return returnVal;
		else
			return false;
	}
	return true;
}
// -----------------------------------------------------
//
function OpenHelp(link,returnVal)
{
	var theFeats = 'height=487,width=482,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no';
	PhotoProductsHelp = window.open(link,"PhotoProductsHelp", theFeats)
	if(PhotoProductsHelp)
	{
		PhotoProductsHelp.focus();
		if (returnVal)
			return returnVal;
		else
			return false;
	}
	return true;
}
// -----------------------------------------------------
//
function OpenTour(link,returnVal)
{
	var theFeats = 'height=610,width=470,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
	PhotoProductsTour = window.open(link,"PhotoProductsTour", theFeats)
	if(PhotoProductsTour)
	{
		PhotoProductsTour.focus();
		if (returnVal)
			return returnVal;
		else
			return false;
	}
	return true;
}
// -----------------------------------------------------
//
function OpenPhotoProducts(link,returnVal)
{
	var theFeats = 'height=680,width=790,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no';
	var PhotoProducts = window.open(link,"PhotoProducts", theFeats)
	if (PhotoProducts)
	{
		PhotoProducts.focus();
		if (returnVal)
			return returnVal;
		else
			return false;
	}
	else
	{
		alert(m_MsgPopUpBlocker);
		return 0;
	}
}
// -----------------------------------------------------
//
function OpenWebupload(link,returnVal)
{
	var theFeats = 'height=680,width=790,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no';
	Webupload = window.open(link,"Webupload", theFeats)
	if (Webupload)
	{
		Webupload.focus();
		if (returnVal)
			return returnVal;
		else
			return false;
	}
	else
	{
		//alert(m_MsgPopUpBlocker);
	}
	//return true;
}
// -----------------------------------------------------
//
function OpenWindow(link,width,height,name)
{
	if (!name){name=(new Date()).getTime() % 1000000000;}
	var theFeats = 'height='+width+',width='+width+',location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no';
	theWindow = window.open(link,name, theFeats)
	if(theWindow)
	{
		theWindow.focus();
		return false;
	}
	else
	{
		//alert(m_MsgPopUpBlocker);
	}
	//return true;
}
// -----------------------------------------------------
//
function ShowLoading(){}
// -----------------------------------------------------
//
function HideLoading(){}
// -----------------------------------------------------
//
function ToggleControlWithId(theControlId)
{
	theControl = GetControl(theControlId);
	if (theControl.style.visibility=="hidden") {
		theControl.style.visibility = "visible";
		theControl.style.display = "block";
	} else {
		theControl.style.visibility = "hidden";
		theControl.style.display = "none";
	}
}
// -----------------------------------------------------
//
function CheckHtmlUploadFields(theFielddPrevix)
{
	var _isEmpty = true;

	for (_counter = 1 ; _counter < 50 ; _counter++)
	{
		_filefield = GetControl(theFielddPrevix + _counter);
		if (!_filefield) {break;}
		if (_filefield.value != '')	{_isEmpty = false;break;}
	}
	if (! _isEmpty) 
	{
		if(confirm(m_NonEmptyFileFields))
		{
			if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
				_theForm = document.PCKForm;
			}
			else {
				_theForm = document.forms["PCKForm"];
			}
			//_theForm = document.forms["PCKForm"];
			_theForm.enctype = 'text/plain'; 
			//_theForm.reset();
			_isEmpty = true;
		}
		else
		{
			_isEmpty = false;		
		}
	}
	if (m_waitTarget != '' && _isEmpty==true)
	{
		_waitCtl = GetControl(m_waitTarget);
		if (_waitCtl )
		{
			_waitCtl.value = m_waitLabel;
			_waitCtl.disabled = true;
		}
	}
	return _isEmpty;
}
// -----------------------------------------------------
//
function CreateProgressBar(sessionParam,uploadUrl,progressUrl) 
{
	var _isValid = false;
	var _uploadButton;
	var _openWindow;
	var _theForm
	
	_theForm = document.forms["PCKForm"];
	_uploadButton = GetControl("uploadSubmit" );

	for (_counter = 1 ; _counter < 50 ; _counter++)
	{
		_filefield = GetControl("f_" + _counter);
		if (!_filefield)	{break;}
		if ((_filefield.value.length > 0 &&(!(_filefield.value.substring(_filefield.value.length-4,_filefield.value.length).toLowerCase()=='.jpg')
				|| (_filefield.value.substring(_filefield.value.length-5,_filefield.value.length).toLowerCase()== '.jpeg'))))
		{
			alert(m_NonValidFileMessage);
			_filefield.focus();
			return;
		}
		if (_filefield.value != '')	{_isValid = true;}
	}
	
	if (_isValid)
	{
		this.ShowLoading();
		_UniqueID = (new Date()).getTime() % 1000000000;
		if (browser.isIE4up && browser.isWin) 
		{
			_Features = 'dialogTop:50px;dialogLeft:50px;dialogHeight:145px;dialogWidth:600px;scroll:no;location:no;menubar:no;resizable:no;scrollbars:no;status:no;toolbar:no;';
			window.showModelessDialog  ("Controls/Progress/Frame.aspx?" + sessionParam + "&" + "URL=" + progressUrl   + "&pid="+ _UniqueID , _UniqueID, _Features);
		}
		else
		{
			_Features = 'height=115,width=600,location=no,menubar=no,resizable=no,scrollbars=no,scroll=no,status=no,toolbar=no';
			window.open  ("Controls/Progress/Frame.aspx?" + sessionParam + "&" + "URL=" + progressUrl   + "&pid="+ _UniqueID , _UniqueID, _Features);
		}
		_theForm.action = uploadUrl + sessionParam + '&UploadID=' + _UniqueID ;
		
		_theForm.submit();
	}
}
// -----------------------------------------------------
//
function ShowPicture(img)
{
	var width= 600;
	var height= 450;
	var uplFile = GetControl("f_"+img );
	
	if (uplFile && uplFile.value.length > 0 && CheckFile(uplFile))
	{
		_uplFileValue = encodeURI(uplFile.value);
		var preview = window.open('','preview','width='+width+',height='+height+',top=20,left=20,location=0,directories=0,status=no,menuBar=no,toolbar=no,scrollBars=no,resizable=yes');
		preview = preview.document;
		preview.open();
	preview.writeln("<html><head><title>&nbsp;</title>")
	preview.writeln("</head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 bgcolor='#000000'>");
	preview.writeln("<a href=\"javascript:self.close();\">");
/*	if(browser.isIE) 
		{preview.writeln("<img src=\"file://localhost/" +_uplFileValue + "\" border=0 >");}
	else if(browser.isFirefox) 
		{preview.writeln("<img src=\"file:///" +uplFile.value.replace(/\/,'/') + "\" border=0 >");}
	else 
*/
	{preview.writeln("<img src=\"file://localhost/" +_uplFileValue + "\" border=0 alt=\"\">");}	
	preview.writeln("</a>");
	preview.writeln("<SCRIPT type=text/javascript><!-- ");
	preview.writeln("resize();");
	preview.writeln("function resize(){");
	preview.writeln("var _w="+width+"; var _h="+ height+"; var _f=_w/_h ;");
	preview.writeln("if (!document.images[0].complete){setTimeout('resize()',100)}else{");
	preview.writeln("var _iw=document.images[0].width; var _ih=document.images[0].height; var _if=_iw/_ih;");
	preview.writeln("if (_if > 1 ) {");
	preview.writeln("document.images[0].width= _w;");
	preview.writeln("document.images[0].height= _h *_if /_f;");
	preview.writeln("}else{");
	preview.writeln("document.images[0].width= _w *_if /_f;");
	preview.writeln("document.images[0].height= _h;");
	preview.writeln("}");
	preview.writeln(" window.resizeTo(document.images[0].width+5,document.images[0].height+5);}}");
	preview.writeln(" //--></SCRIPT>");
	preview.writeln("</body></html>");
	preview.close();
	preview.focus();
	}
}
// -----------------------------------------------------
//
function LoadImage(srcImgId, imgSrc, doResize,faktor)
{
	Debug ("LoadImage:" + imgSrc);	
	if(doResize==null) {_doResize=false;}else {_doResize=doResize;}
	if(faktor==null) {faktor=1;}
	
	Debug("faktor:" + faktor);
	Debug("doResize:" + doResize);
	
	_srcImgageControl = GetControl(srcImgId);
	
	_theImage=new Image();
	_theImage.src= imgSrc ;

	if (_theImage.width > 0 && _srcImgageControl != null)
	{
		if (browser.isIE4up) 
		{
			_srcImgageControl.style.filter ="blendTrans(duration=3)" ;
			_srcImgageControl.filters[0].apply()
			_srcImgageControl.src = _theImage.src;
			_srcImgageControl.filters[0].play();
		}
		else
		{
			_srcImgageControl.src = _theImage.src ;
		}
		
		if(_doResize)
		{
			_srcImgageControl.width = _theImage.width * faktor;
			_srcImgageControl.height= _theImage.height * faktor;
		}
	}
	else
	{
		_pause = 5000; //SET PAUSE BETWEEN RETRY(5000=5 seconds)
		setTimeout("LoadImage('"+srcImgId+"','"+imgSrc+"',"+ _doResize +","+ faktor +")",_pause);
	}
}
// -----------------------------------------------------
//
function ChangeStyle(theControl,cssClass)
{
	theControl.className = cssClass;
	return true;
} 
// -----------------------------------------------------
//
function ChangeStyleWithId(theControlId,cssClass)
{
	if (!GetControl(theControlId)){return;}
	return ChangeStyle(GetControl(theControlId),cssClass);
} 
// -----------------------------------------------------
//
function ChangeStyleWithIds(theArray,cssClass)
{
	for (i=0;i<theArray.length;i++)
		ChangeStyleWithId(theArray[i],cssClass);
}

// -----------------------------------------------------
//
function ActiveXUploadComplete()
 {
	if(GetControl('cart_table') != null)	{ChangeStyleWithId ('cart_table','cart_table_highlighted'); }
	if(GetControl('DivFilesInfoInner') != null)	{ChangeStyleWithId ('DivFilesInfoInner','DivInnerMinHigh'); }
 }
// -----------------------------------------------------
//
 function SetFocus (theControlName)
 {
	theControl = GetControl(theControlName);
	if (theControl!= null)
		theControl.focus();
 }
// -----------------------------------------------------
//
 function GetRadioGroup(theControlId)
 {
	var returnControl = null;
	returnControl =  document.getElementsByName(theControlId);
	return returnControl;
 }
// -----------------------------------------------------
//
  function GetRadioGroupSelectedItem(theControlId)
 {
	var _group  = GetRadioGroup(theControlId);
	for( _cnt =0; _cnt< _group.length;_cnt++)
		{
		if (_group[_cnt].checked == true)
			return _group[_cnt];
		}
	return null;
 }
// -----------------------------------------------------
//
function GetControl(theControlId)
{
	var returnControl = null;
	if (browser.isIE4)
		returnControl = document.all[escape(theControlId)];
	else 
	{
		returnControl = document.getElementById( theControlId);
	if (returnControl == null) 
		returnControl =  document.getElementsByName(theControlId)[0];	
	}
	return returnControl;
}
// -----------------------------------------------------
//
function OpenAGB()
{
		_Features = 'height=570,width=795,location=no,menubar=no,resizable=yes,scrollbars=yes,scroll=yes,status=no,toolbar=no';
	window.open ('http://agb.Ifolor.ch/' , 'AGB', _Features)

}
// -----------------------------------------------------
//
function CheckFile(theControl)
{
	if ((theControl.value.length > 0 &&(!(theControl.value.substring(theControl.value.length-4,theControl.value.length).toLowerCase()=='.jpg')
	|| (theControl.value.substring(theControl.value.length-5,theControl.value.length).toLowerCase()== '.jpeg'))))
	{
		alert(m_NonValidFileMessage);
		theControl.focus();
		return false;
	}
	return true;
}
// -----------------------------------------------------
//
function CheckFileWithId(theControlId)
{
	return CheckFile(GetControl(theControlId));
}
// -----------------------------------------------------
//
function ChangePostalCity (thePostalCitySelectorId, thePostalCodeId, theCityId)
{
	thePostalCitySelectorControl = GetControl(thePostalCitySelectorId);
	thePostalCodeControl = GetControl(thePostalCodeId);
	theCityControl = GetControl(theCityId);

	theValue = thePostalCitySelectorControl.options[thePostalCitySelectorControl.selectedIndex].value;

	thePostalCodeControl.value = theValue.substring(0,theValue.indexOf("|"));
	theCityControl.value = theValue.substring(theValue.indexOf("|")+1,theValue.length);
	
	var _control = GetControl(thePostalCitySelectorId);
	_control.style.visibility = "hidden";
	_control.style.display = "none";
}
// -----------------------------------------------------
//
function FillDropDown (theControlId,theControlValue,fromValue,toValue,stepValue)
{
	var _ddboxCtl = GetControl(theControlId);
	//Debug("_ddboxCtl.id:" + _ddboxCtl.name);
	if (theControlValue == null) theControlValue =  theControlValue =1;
	if (fromValue == null) fromValue =  fromValue =1;
	if (toValue == null) toValue =  toValue =10;
	if (stepValue == null)  stepValue=  stepValue =1;
	
	
	if (_ddboxCtl != null)
	{
		for (_cnt = fromValue ; _cnt <= toValue; _cnt+=stepValue)
		{
			_ddboxCtl.options[_ddboxCtl.options.length]= new Option(_cnt,_cnt,false,false);
			if (_cnt==theControlValue)
			{
				_ddboxCtl.options[_ddboxCtl.options.length-1].selected =true;
				_ddboxCtl.options[_ddboxCtl.options.length-1].defaultSelected =true;
			}
			Debug( _ddboxCtl.options.length-1 +  ":" + _ddboxCtl.options.selectedIndex +  ":" +_ddboxCtl.options[_ddboxCtl.options.length-1].text+  ":" + _ddboxCtl.options[_ddboxCtl.options.length-1].value);
        	}
        }
}
// -----------------------------------------------------
//
function SetColor (imgId,color,radioId)
{
	_imgCtl = GetControl(imgId);
	_radioCtl = GetControl(radioId);
	_imgCtl.style.background='#'+ color ;
}
// -----------------------------------------------------
//
function HideSelectBoxes()
{
	m_hideCounter++;
	for (i=0;i<document.forms[0].length;i++)
	{
		var element=document.forms[0].elements[i]
		Debug(element.name);
		if(element.type.toLowerCase().indexOf("select") > -1)
		{
			element.wasVisible = (element.style.visibility!='hidden');
			element.style.visibility='hidden';
		}
	}
}
// -----------------------------------------------------
//
function ReShowSelectBoxes()
{
	m_hideCounter--;
	if (m_hideCounter <=0)
	{
		m_hideCounter = 0;
		for (i=0;i<document.forms[0].length;i++)
		{
			var element=document.forms[0].elements[i]
			if(element.type.toLowerCase().indexOf("select") > -1)
			{
				//if (element.wasVisible == null || element.wasVisible == true)
				//if (element.style.visibility=='hidden')
				Debug(element.name);
				if (element.wasVisible)
					element.style.visibility='visible';
			}
		}
	}
}
// -----------------------------------------------------
//
function HideActiveXControls()
{
	if ( GetControl('X_CtlUpload')){HideLayer(GetControl('XBG_CtlUpload'))}
}
// -----------------------------------------------------
//
function ReShowActiveXControls()
{
	if (GetControl('X_CtlUpload')){ShowLayer(GetControl('XBG_CtlUpload'))}
}
// -----------------------------------------------------
//
function HideLayer(ctlLayer)
{
	if(ctlLayer)
	{
		if (browser.isIE || browser.isFirefox)  {ctlLayer.style.visibility = 'hidden';}	
		else {ctlLayer.visibility = 'hide';}
	}
}
// -----------------------------------------------------
//
function ShowLayer(ctlLayer) 
{	
	if(ctlLayer)
	{
		if (browser.isIE || browser.isFirefox)  {ctlLayer.style.visibility = 'visible';}	
		else {ctlLayer.visibility = 'show';}
	}
} 
// -----------------------------------------------------
//
function CheckIntValue(theInputControl,fromInt,toInt)
{
  if (isNaN(theInputControl.value)){theInputControl.value = parseInt((fromInt+toInt)/2);}
 _intVal = parseInt(theInputControl.value);
 if (_intVal)
	{
	if (_intVal < fromInt)
		{
			theInputControl.value = fromInt;
			return false;
		}
		else if (_intVal > toInt)
		{
		theInputControl.value = toInt;
			return false;
		}
		else
		{
		return true;
		}
	}
	return false;
 }
 //
 //
function IsCookieEnabled ()
{
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (60*1000));	// valid: one minute (60seconds*1000 hundreds)
	SetCookie ('CookieEnabled', 1, exp);
	cookieEnabled = GetCookie('CookieEnabled');
	if (cookieEnabled==null){return false}else{return true}
}
//
//
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}
//
//
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 null;
}
//
//
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
// -----------------------------------------------------
//
function SettingsError(failureUrl)
{
	GoToPage(failureUrl);
}
// -----------------------------------------------------
//
function CheckBrowserSettings(successRedirUrl,failureBaseRedirUrl)
{
	if (failureBaseRedirUrl){_failureUrl = failureBaseRedirUrl;}else{_failureUrl = 'ErrorPage.aspx';}
	// check cookie enabled
	if (!IsCookieEnabled()) 
	{
		GoToPage('ErrorCookie.aspx'+ window.location.search);
	}
	else
	{
		CheckBrowserSettingsForApplication(failureBaseRedirUrl);	
	}
	if (successRedirUrl){GoToPage(successRedirUrl)}
}
// -----------------------------------------------------
//
//
function GoToPage(page)
{
	if (ShowLoading){ShowLoading();}
   window.location.href = page;
   return false;
}
// -----------------------------------------------------
//
//
var m_EncodeDecodeStr="#_.!~*'(),/?:@&=+$"+String.fromCharCode(13)+String.fromCharCode(10);
// -----------------------------------------------------
//
//
function decodeURIpck(val)
{
	Debug("-decodeURIpck:"+val);
	if (!browser.isIE50)
		val = decodeURI(val);
	//else
	{
		_cnt = 0;
		_str=m_EncodeDecodeStr;
		while(_cnt < m_EncodeDecodeStr.length)
		{
			_replaceValue  = m_EncodeDecodeStr.charAt(_cnt);
			_searchChar =  "%" + HEX(_str.charCodeAt(_cnt));
			
			while(val.indexOf( _searchChar ) >-1 )
				val = val.replace(_replaceValue, +_searchChar);
			_cnt++;
		}
	}
	return val;
}
// -----------------------------------------------------
//
//
function encodeURIpck(val)
{
	if (!browser.isIE50)
		val = encodeURI(val);
	//else
	{
		//_retVal =  escape(val);
		_cnt = 0;
		_str=m_EncodeDecodeStr;
		while(_cnt < _str.length)
		{
			_searchChar = _str.charAt(_cnt);
			_replaceValue = HEX(_str.charCodeAt(_cnt));
			while(val.indexOf(_str.charAt(_cnt)) >-1 )
				val = val.replace(_searchChar, "%" +_replaceValue);
			_cnt++;
		}
	}
	return val;
}
// -----------------------------------------------------
//
//
function HEX (d)
{
  max = Math.pow(16,8);
  if (d > max){return;}
  if (d < 0) {return;}
  var z = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
  var x = "";
  var i = 1, v = d, r = 0;
  while (v > 15) {v = Math.floor(v / 16);i++;}
  v = d;
  for (j=i; j >= 1; j--){x = x + z[Math.floor(v / Math.pow(16, j-1))];v = v - (Math.floor(v / Math.pow(16, j-1)) * Math.pow(16, j-1));}
  if(x.length < 2){	x="0" + x;}
  return x;
}
// -----------------------------------------------------
//
//
function __doPckPostBack (eventTarget, eventArgument,showWaiting)
{
	// __doPostBack(eventTarget, eventArgument) 
	var _theForm;
	var _waitingCtl;	
	var _waitingCtlText;	
	if (showWaiting){_waitingCtl= GetControl(eventTarget);}
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {_theForm = document.forms["PCKForm"];}
	else {_theForm = document.PCKForm;}

	_theForm.__EVENTTARGET.value = eventTarget.split("$").join(":");
	_theForm.__EVENTARGUMENT.value = eventArgument;

	if (_waitingCtl)
	{
		_waitingCtlText =_waitingCtl.value;
		_waitingCtl.value=m_waitText;
		_waitingCtl.disabled=true;
		
	}
	if (_theForm.onsubmit()!= false)
	{		
		_theForm.submit();
	}
	else
	{
		if (_waitingCtl)
		{
			_waitingCtl.value=_waitingCtlText;
			_waitingCtl.disabled=false;
		}
	}
}
// -----------------------------------------------------
//
function Debug(msg)
{
	if (m_debug == true)
	{
		if(m_DebugWindow==null || m_DebugWindow.closed)
		{
			this.window.moveTo(430,0);
			m_DebugWindow = window.open('','DebugWindow','width=400,height=1000,top=10,left=10,location=0,directories=0,status=no,menuBar=no,toolbar=no,scrollBars=no,resizable=yes');
			var DebugDoc = m_DebugWindow.document;
			DebugDoc.open();
			DebugDoc.writeln("<html><head><title>&nbsp;</title>")
			DebugDoc.writeln("<script language='javascript'><!--") ;
			DebugDoc.writeln("function AddMsg(msg){newEntry = new Option(msg,msg,false,true);document.Form1.msg.options[document.Form1.msg.length] = newEntry;}");
			DebugDoc.writeln("function ClearMsg(){while (document.Form1.msg.length > 0){ document.Form1.msg.options[0] = null;}}");
			DebugDoc.writeln("//--></script>") ;
			DebugDoc.writeln("</head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>");
			DebugDoc.writeln("<form name=Form1>")
			DebugDoc.writeln("<SELECT id='msg' style='z-index: 106; left:0px; width: 99%; position: absolute; top: 0px; height: 90%' size=11 name='msg'>");
			DebugDoc.writeln("<input type=button value=Clear onclick=\"ClearMsg();\" style='z-index: 106; left:0px; width: 95%; position: absolute; top: 90%; height:15px'></form></body></html>");
			DebugDoc.close();
			DebugDoc.focus;
		}
		if (m_DebugWindow)
			m_DebugWindow.AddMsg(msg);
		else
			alert(msg);
	}
}
// -----------------------------------------------------
// end
// -----------------------------------------------------



