// $Id: common.js,v 1.12.2.23 2007/08/30 10:49:09 max Exp $

//
// Enviroment identificator
//
var localIsDOM = document.getElementById?true:false;
var localIsJava = navigator.javaEnabled();
var localIsStrict = document.compatMode=='CSS1Compat';
var localPlatform = navigator.platform;
var localVersion = "0";
var localBrowser = "";
var localBFamily = "";
var isHttps = false;
if (window.opera && localIsDOM) {
	localBFamily = localBrowser = "Opera";
	if (navigator.userAgent.search(/^.*Opera.([\d.]+).*$/) != -1)
		localVersion = navigator.userAgent.replace(/^.*Opera.([\d.]+).*$/, "$1");
	else if (window.print)
		localVersion = "6";
	else
		localVersion = "5";
} else if (document.all && document.all.item)
	localBFamily = localBrowser = 'MSIE';
if (navigator.appName=="Netscape") {
	localBFamily = "NC";
	if (!localIsDOM) {
		localBrowser = 'Netscape';
		localVersion = navigator.userAgent.replace(/^.*Mozilla.([\d.]+).*$/, "$1");
		if(localVersion != '')
			localVersion = "4";
	} else if(navigator.userAgent.indexOf("Safari") >= 0)
		localBrowser = 'Safari';
	else if (navigator.userAgent.indexOf("Netscape") >= 0)
		localBrowser = 'Netscape';
	else if (navigator.userAgent.indexOf("Firefox") >= 0)
		localBrowser = 'Firefox';
	else 
		localBrowser = 'Mozilla';
	
}
if (navigator.userAgent.indexOf("MSMSGS") >= 0)
	localBrowser = "WMessenger";
else if (navigator.userAgent.indexOf("e2dk") >= 0)
	localBrowser = "Edonkey";
else if (navigator.userAgent.indexOf("Gnutella") + navigator.userAgent.indexOf("Gnucleus") >= 0)
	localBrowser = "Gnutella";
else if (navigator.userAgent.indexOf("KazaaClient") >= 0)
	localBrowser = "Kazaa";

if (localVersion == '0' && localBrowser != '') {
	var rg = new RegExp("^.*"+localBrowser+".([\\d.]+).*$");
	localVersion = navigator.userAgent.replace(rg, "$1");
}
var localIsCookie = ((localBrowser == 'Netscape' && localVersion == '4')?(document.cookie != ''):navigator.cookieEnabled);

if (document.location.protocol == "https:") { 
    isHttps = true;
}

function change_antibot_image(id) {
	var image = document.getElementById(id);
	if (image)
		image.src = xcart_web_dir+"/antibot_image.php?tmp="+Math.random()+"&section="+id+"&regenerate=Y";
}


/*
	Find element by classname
*/
function getElementsByClassName( clsName ) {
	var arr = new Array(); 
	var elems = document.getElementsByTagName("*");
	
	for ( var cls, i = 0; ( elem = elems[i] ); i++ ) {
		if ( elem.className == clsName ) {
			arr[arr.length] = elem;
		}
	}
	return arr;
}
//
// Opener/Closer HTML block
//
function visibleBox(id,skipOpenClose) {
	elm1 = document.getElementById("open"+id);
	elm2 = document.getElementById("close"+id);
	elm3 = document.getElementById("box"+id);

	if(!elm3)
		return false;

	if (skipOpenClose) {
		elm3.style.display = (elm3.style.display == "")?"none":"";
	} else if(elm1) {
		if (elm1.style.display == "") {
			elm1.style.display = "none";
			if(elm2)
				elm2.style.display = "";
			elm3.style.display = "none";
			var class_objs = getElementsByClassName('DialogBox');
			for (var i = 0; i < class_objs.length; i++) {
				class_objs[i].style.height = "1%";
			}
		} else {
			elm1.style.display = "";
			if(elm2)
				elm2.style.display = "none";
			elm3.style.display = "";
		}
	}
}

/*
	URL encode
*/
function urlEncode(url) {
	return url.replace(/\s/g, "+").replace(/&/, "&amp;").replace(/"/, "&quot;")
}

/*
	Math.round() wrapper
*/
function round(n, p) {
	if (isNaN(n))
		n = parseFloat(n);
	if (!p || isNaN(p))
		return Math.round(n);
	p = Math.pow(10, p);
	return Math.round(n*p)/p;
}

/*
	Price format
*/
function price_format(price, thousand_delim, decimal_delim, precision) {
	var thousand_delim = (arguments.length > 1 && thousand_delim !== false) ? thousand_delim : number_format_th;
	var decimal_delim = (arguments.length > 2 && decimal_delim !== false) ? decimal_delim : number_format_dec;
	var precision = (arguments.length > 3 && precision !== false) ? precision : number_format_point;

	if (precision > 0) {
		precision = Math.pow(10, precision);
		price = Math.round(price*precision)/precision;
		var top = Math.floor(price);
		var bottom = Math.round((price-top)*precision)+precision;

	} else {
		var top = Math.round(price);
		var bottom = 0;
	}

	top = top+"";
	bottom = bottom+"";
	var cnt = 0;
	for (var x = top.length; x >= 0; x--) {
		if (cnt % 3 == 0 && cnt > 0 && x > 0)
			top = top.substr(0, x)+thousand_delim+top.substr(x, top.length);

		cnt++;
	}

	return (bottom > 0) ? (top+decimal_delim+bottom.substr(1, bottom.length)) : top;
}

/*
	Substitute
*/
function substitute(lbl) {
var x, rg;
	for(x = 1; x < arguments.length; x+=2) {
		if(arguments[x] && arguments[x+1]) {
			rg = new RegExp("\\{\\{"+arguments[x]+"\\}\\}", "gi");
			lbl = lbl.replace(rg,  arguments[x+1]);
			rg = new RegExp('~~'+arguments[x]+'~~', "gi");
			lbl = lbl.replace(rg,  arguments[x+1]);
		}
	}
	return lbl;
}

function getWindowOutWidth(w) {
	if (!w)
		w = window;
	if (localBFamily == "MSIE")
		return w.document.body.clientWidth;
	else
		return w.outerWidth;
}

function getWindowOutHeight(w) {
	if (!w)
		w = window;
	if (localBFamily == "MSIE")
		return w.document.body.clientHeight;
	else
		return w.outerHeight;
}

function getWindowWidth(w) {
	if (!w)
		w = window;
    if (localBFamily == "MSIE")
		return w.document.body.clientWidth;
    else 
		return w.innerWidth;
}

function getWindowHeight(w) {
	if (!w)
		w = window;
    if (localBFamily == "MSIE")
		return w.document.body.clientHeight;
	else
		return w.innerHeight;
}

function getDocumentHeight(w){
	if (!w)
		 w = window;
	if (localBFamily == "MSIE" || (localBFamily == "Opera" && localVersion >= 7 && localVersion < 8))
		return isStrict ? w.document.documentElement.scrollHeight : w.document.body.scrollHeight;
	if (localBFamily == "NC")
		return w.document.height
	if (localBFamily == "Opera")
		return w.document.body.style.pixelHeight
}

function getDocumentWidth(w) {
	if (!w)
		w = window;
	if (localBFamily == "MSIE" || (localBFamily == "Opera" && localVersion >= 7 && localVersion < 8))
		return isStrict ? w.document.documentElement.scrollWidth : w.document.body.scrollWidth;
	if (localBFamily == "NC")
		return w.document.width;
	if (localBFamily == "Opera")
		return w.document.body.style.pixelWidth;
}

function expandWindowX(w, step, limit) {
	if (!w)
		w = window;

	if (!step)
		step = 10;

	var go = true;
	var i = 200;
	while (go && i--) {
		if (limit && getWindowOutWidth()+step > limit)
			break;

		try {
			w.scrollTo(step, 0);
			go = (w.document.documentElement && w.document.documentElement.scrollLeft > 0) || (w.document.body && w.document.body.scrollLeft > 0);
			if (go)
				w.resizeBy(step, 0);

		} catch (e) {
			return false;
		}
	}

	return true;
}

function expandWindowY(w, step, limit) {
	if (!w)
		w = window;

	if (!step)
		step = 10;

	var go = true;
	var i = 200;
	while (go && i--) {
		if (limit && getWindowOutHeight()+step > limit)
			 break;

		try {
			w.scrollTo(0, step);
			go = (w.document.documentElement && w.document.documentElement.scrollTop > 0) || (w.document.body && w.document.body.scrollTop > 0);
			if (go)
				w.resizeBy(0, step);

		} catch(e) {
			return false;
		}
	}

	return true;
}

/*
	Check list of checkboxes
*/
function checkMarks(form, reg, lbl) {
var is_exist = false;

	if (form.elements.length == 0)
		return true;

	for (var x = 0; x < form.elements.length; x++) {
		if (form.elements[x].name.search(reg) == 0 && form.elements[x].type == 'checkbox' && !form.elements[x].disabled) {
			is_exist = true;
			if (form.elements[x].checked)
				return true;
		}
	}

	if (!is_exist)
		return true;
	else if (lbl)
		alert(lbl);
	else if (lbl_no_items_have_been_selected)
		alert(lbl_no_items_have_been_selected);
	return false;
}

/*
	Submit form with specified value of 'mode' parmaeters
*/
function submitForm(formObj, formMode) {
	if (!formObj)
		return false;
	if (formObj.tagName != "FORM") {
		if (!formObj.form)
			return false;
		formObj = formObj.form;
	}
	if (formObj.mode)
		formObj.mode.value = formMode;
	formObj.submit();
}

/*
	Analogue of PHP function sleep()
*/
function sleep(msec) {
	var then = new Date().getTime()+msec;
	while (then >= new Date().getTime()){
	}
}

/*
	Convert number from current format
	(according to 'Input and display format for floating comma numbers' option)
	to float number
*/
function convert_number(num) {
	var regDec = new RegExp(reg_quote(number_format_dec), "gi");
	var regTh = new RegExp(reg_quote(number_format_th), "gi");
	var pow = Math.pow(10, parseInt(number_format_point));
	num = parseFloat(num.replace(" ", "").replace(regTh, "").replace(regDec, "."));
	return Math.round(num*pow)/pow;
}

/*
	Check string as number
	(according to 'Input and display format for floating comma numbers' option)
*/
function check_is_number(num) {
	var regDec = new RegExp(reg_quote(number_format_dec), "gi");
	var regTh = new RegExp(reg_quote(number_format_th), "gi");
	num = num.replace(" ", "").replace(regTh, "").replace(regDec, ".");
	return (num.search(/^[0-9]+(\.[0-9]+)?$/) != -1);
}

/*
	Qutation for RegExp class
*/
function reg_quote(s) {
	return s.replace(/\./g, "\\.").replace(/\//g, "\\/").replace(/\*/g, "\\*").replace(/\+/g, "\\+").replace(/\[/g, "\\[").replace(/\]/g, "\\]");
}

function setCookie(name, value, path, expires) {
	if (typeof(expires) == 'object') {
		try {
			var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
			var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
			if (days[expires.getDay()] && months[expires.getMonth()])
				expires = days[expires.getDay()]+" "+expires.getDate()+"-"+months[expires.getMonth()]+"-"+expires.getFullYear()+" "+expires.getHours()+":"+expires.getMinutes()+":"+expires.getSeconds()+" GMT";
		} catch(e) { }
	}

	if (typeof(expires) != 'string')
		expires = false;

	document.cookie = name+"="+escape(value)+(expires ? "; expires=" + expires : "")+(path ? "; path="+path : "");
}

function deleteCookie(name) {
	document.cookie = name+"=0; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

/*
	Clone object
*/
function cloneObject(orig) {
	var r = {};
	for (var i in orig) {
		r[i] = orig[i];
	}

	return r;
}

/*
	Get first checkbox and redirect to URL
*/
function getFirstCB(form, reg) {

	while (form.tagName && form.tagName.toUpperCase() != 'FORM')
		form = form.parentNode;

	if (!form.tagName || form.tagName.toUpperCase() != 'FORM' || form.elements.length == 0)
        return false;

	var selectedChk = false;
    for (var x = 0; x < form.elements.length; x++) {
        if (form.elements[x].name.search(reg) == 0 && form.elements[x].type == 'checkbox' && !form.elements[x].disabled && form.elements[x].checked) {
			selectedChk = form.elements[x];
			break;
        }
    }
    
    if (!selectedChk) {
		if (lbl_no_items_have_been_selected)
			alert(lbl_no_items_have_been_selected);

        return false;
	}

    return selectedChk;
}

/*
	getElementById() wrapper
*/
function _getById(id) {
	if (typeof(id) != 'string' || !id)
		return false;

	var obj = document.getElementById(id);
	if (obj && obj.id != id) {
		obj = false;
		for (var i = 0; i < document.all.length && obj === false; i++) {
			if (document.all[i].id == id)
				obj = document.all[i];
		}
	}

	return obj;
}

// undefined or not
function isset(obj) {
	return typeof(obj) != 'undefined' && obj !== null;
}


// Check - variable is function or not
function isFunction(f) {
	return (typeof(f) == 'function' || (typeof(f) == 'object' && (f+"").search(/\s*function /) === 0));
}


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;function openPopup(tail) { newWindow = window.open("../popup.html" + tail,"subWind","height=370,width=530"); newWindow.focus( ); }


//Find a document element by tag type and id
//param:tagname - input or span
//param:realName - the id of the asp control
//Author: Slavena Savova
//Date: 12/11/2006
function getName(tagType, realName) {
    var inputArray = document.body.getElementsByTagName(tagType);
	for (i = 0; i < inputArray.length; i++) {
		if (inputArray[i].id.toString().indexOf(realName)!= -1) {
		  return inputArray[i].id;
		}
	}
}

function getObjectByName(tagType, realName) 
{    
	var inputArray = document.body.getElementsByTagName(tagType);
	for (i = 0; i < inputArray.length; i++) {
		if (inputArray[i].name.toString().indexOf(realName)!= -1) {		
		  return inputArray[i];
		}
	}
	return null;
}

//This method change the style of the button(input type="submit"), because hover effect doesn't work in IE6.
//param:object - input objects that call this method
//param: action - input action:hover, when mouseover and out when mouse out
//Author: Slavena Savova
//Date: 09/10/2007
function ChangeButtonClass(object, action)
{
    if(action == "hover")
    {
        object.className = "buttonHover";
    }
    else if(action == "out")
    {
        object.className = "button";
    }    
}

//This function checkes or unchecks all the checkboxes in GridView
//param:selectAllId - the id of select all checkbox
//Author: Slavena Savova
//Date: 12/11/2006
function CheckUncheckAll(selectAllId) {
    var realId = getName("input", selectAllId);
    var inputArray = document.body.getElementsByTagName("input");		        	   
    for (var i=0; i< inputArray.length; i++) {			       
       if((inputArray[i].type == 'checkbox') && (inputArray[i].id != realId))
       {
           inputArray[i].checked = document.getElementById(realId).checked;
       }				    
    }		    
}

//This function uncheck the selectallcheckbox if you check on some checkbox in GridView
//param: selectAllId - the id of select all checkbox
//Author: Slavena Savova
//Date: 12/11/2006
function UpdateState(selectAllId, itemId) {
    var realId = getName("input", selectAllId);
    document.getElementById(realId).checked = false;
    
    //Check if every checkbox in datagrid is checked
    var allChecked = true;
    var inputArray = document.body.getElementsByTagName("input");		        	   
    for (var i=0; i< inputArray.length; i++) {			       
       if((inputArray[i].type == 'checkbox') && (inputArray[i].id != realId) && (inputArray[i].id.indexOf(itemId) != -1))
       {
           if(!inputArray[i].checked)
           {
                allChecked = false;
                break;
           }
       }				    
    }
    if(allChecked)
    {
         document.getElementById(realId).checked = true;
    }		
}

//This function checks if there is selected checkbox and return false if there is not.
//param: selectAllId - the id of select all checkbox
//param: itemId - the id of the checkbox we checked
//Author: Slavena Savova
//Date: 03/16/2006
function StateCheck(selectAllId, itemId) {
    var realId = getName("input", selectAllId);
   
    //Check if every checkbox in datagrid is checked
    var anyChecked = false;
    var inputArray = document.body.getElementsByTagName("input");		        	   
    for (var i=0; i< inputArray.length; i++) {			       
       if((inputArray[i].type == 'checkbox') && (inputArray[i].id != realId) && (inputArray[i].id.indexOf(itemId) != -1))
       {
           if(inputArray[i].checked)
           {
                anyChecked = true;
                break;
           }
       }				    
    }
    //If there is selected
    if(anyChecked)
    {
         return true;
    }
    else
    {
        alert ('No items selected');   
        return false; 
    }	
}
    
//This function check whether there are selection and if there any selection display confirm message for deletion
//Author: Nevena Uzunova
//Date: 01/25/2006
//Update: 02/08/2007 - Mesage as parameter
function confirmMessage(checkboxName, message)
{
   return CheckSelectionsAndDisplayConfirmMessage(checkboxName,'No items selected',message)
    
//    inputArray = document.body.getElementsByTagName("input");		        	   
//    for (var i=0; i< inputArray.length; i++) {			       
//       if((inputArray[i].type == 'checkbox') && (inputArray[i].id.indexOf(checkboxName)))
//       {
//           if (inputArray[i].checked)
//                return confirm(message);
//       }			    
//    }        
//      
//    alert ('No items selected');   
//    return false; 	  
}

//Author: Nevena Uzunova
//Date 15/05/2007
function CheckSelectionsAndDisplayConfirmMessage(checkboxName, noSelectionsMessage,confirmMessage)
{
    var inputArray = document.body.getElementsByTagName("input");		        	   
    for (var i=0; i< inputArray.length; i++) {			       
       if((inputArray[i].type == 'checkbox') && (inputArray[i].id.indexOf(checkboxName) != -1 ))
       {
           if (inputArray[i].checked)
                return confirm(confirmMessage);
       }			    
    }        
      
    alert (noSelectionsMessage);   
    return false; 	
}

//Clear selected items in ListBoxes
function ListboxClear(listbox)
{
    for (i= 0; i<listbox.length; i++)
    {
        if (listbox.multiple==true) {
            if (listbox[i].selected==true) {
                listbox[i].selected=false;           
            }
        }
    }    
}

//This function check ot uncheck all list of checkboxes
//param: targetId - the Id of CheckBoxList
//param: checkAllId - the Id of the Check All Id
//author: Slavena Savova
//date: 02/27/2007
function CheckUncheckAllCheckboxes(targetId, checkAllId)
{            
    var inputArray = document.body.getElementsByTagName("input");
        	   
    for (var i=0; i< inputArray.length; i++) {			       
        if((inputArray[i].type == 'checkbox') && (inputArray[i].id.toString().indexOf(targetId)!= -1))
        {                   
           inputArray[i].checked = document.getElementById(getName("input", checkAllId)).checked;                 
        }				    
    }	     
}

//This function sets the default button of the page,
//i.e. if the "Enter" is clicked which button to be clicked from the page.
//param: btn - object
//author: Slavena Savova
//date: 07/17/2007
function SetDefaultButton(btn,keyEvent)
{
    if(btn!= null) 
    {
     if (document.all)    
     {
          if (keyEvent.srcElement.tagName=='TEXTAREA')
            return;
          if (keyEvent.keyCode == 13)
          {
           keyEvent.returnValue=false;
           keyEvent.cancel = true;
           btn.click();
          }
     }
     else if (document.getElementById)
             {
              if (keyEvent.target.tagName=='TEXTAREA')
                return;
              if (keyEvent.which == 13)
              {
               keyEvent.returnValue=false;
               keyEvent.cancel = true;
               btn.click();
              }
            }
    else if(document.layers)
            {
              if (keyEvent.target.tagName=='TEXTAREA')
                return;
              if(keyEvent.which == 13)
              {
               keyEvent.returnValue=false;
               keyEvent.cancel = true;
               btn.click();
              }
            }
   }    
}

//This function cancel the event of pressing the "Enter".
//author: Slavena Savova
//date: 07/18/2007
function CancelEnter(keyEvent)
{
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        if(  ((keyEvent.keyCode == 13) || (keyEvent.which == 13))
            && (keyEvent.srcElement != null)
            && (keyEvent.srcElement.tagName!='TEXTAREA')
          )
         {           
            keyEvent.cancel = true;
            keyEvent.cancelBubble=true;
            keyEvent.returnValue = false;
         }        
    } 
    else 
    {
       if(  ((keyEvent.keyCode == 13) || (keyEvent.which == 13))
            && (keyEvent.target != null)
            && (keyEvent.target.tagName!='TEXTAREA')
          )
         {
            keyEvent.preventDefault();
            keyEvent.stopPropagation();           
         }
    }
  
}
	
// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (American date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

var offsetfromcursorX=171 //Customize x offset of tooltip
var offsetfromcursorY=-105 //Customize y offset of tooltip(-10)

var ie=document.all
var ns6=document.getElementById && !document.all
var leftedge
var topedge

function ietruebody(){

    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function positiontip(e)
{
    leftedge=ie&&!window.opera? event.clientX-offsetfromcursorX : e.clientX-offsetfromcursorX
    
    topedge=ie&&!window.opera? event.clientY-offsetfromcursorY : e.clientY-offsetfromcursorY    
    if (navigator.platform == 'MacPPC')
    {
        topedge+=25
    }        
}
document.onmousemove=positiontip;

function calendar(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date;
	this.gen_time = cal_gen_time;
	this.gen_tsmp = cal_gen_tsmp;
	this.prs_date = cal_prs_date;
	this.prs_time = cal_prs_time;
	this.prs_tsmp = cal_prs_tsmp;
	this.popup    = cal_popup;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup (str_datetime) {
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;

    //Estimate position of the pop-up calendar
            var leftPos = leftedge + "px";
            var topPos = topedge + "px";  


	var obj_calwindow = window.open(
		'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top='+topPos+',left='+leftPos+',dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date (dt_datetime) {
	return (
		(dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date (str_date) {

	var arr_date = str_date.split('/');

	if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "'.\nFormat accepted is mm/dd/yyyy.");
	if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[0] < 1 || arr_date[0] > 12) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[0]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[0], 0);
	dt_date.setDate(arr_date[1]);
	if (dt_date.getMonth() != (arr_date[0]-1)) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

 var isSelObj=false;
       
    function SetSelectedColor(objLeft,objCenter,objRight)
    {                            
        
        if (objCenter.className=="mc_prodc_TypeSel")
            return;
        
        isSelObj=true;               
       
        objLeft.className="mc_prodc_leftSel";        
        objCenter.className="mc_prodc_TypeSel";        
        objRight.className="mc_prodc_rightSel";
                       
    }
    
    function SetNotSelectedColor(objLeft,objCenter,objRight)
    {       
        if(isSelObj)
        {          
            objLeft.className="mc_prodc_leftNotSel";        
            objCenter.className="mc_prodc_TypeNotSel";        
            objRight.className="mc_prodc_rightNotSel";
            
            isSelObj=false;
        }
    }
//This function returns the first sibling element from a certain tag name
function GetFirstNextSibling(startObject,_tagName)
{
	if (startObject==null)
		return null;
	if (startObject.tagName==_tagName)
		return startObject;
	else
		return GetFirstNextSibling(startObject.nextSibling,_tagName);
}
//This returns the first sibling element from a certain tag name
function GetFirstPrevSibling(startObject,_tagName)
{
	if (startObject==null)
		return null;
	if (startObject.tagName==_tagName)
		return startObject;
	else
		return GetFirstPrevSibling(startObject.previousSibling,_tagName);
}
