var block_arr = new Array();
var minimum_top = 20;
var minimum_left = 20;
var zIndexValue = 200;

/* ************** Start of user popup functions ********** */
var timeout	= 100;
var infoTimer	= 0;
var divObj	= 0;
// close showed layer
function closeUserPopup(){
	if(divObj) divObj.style.display = 'none';
}

// close user info and reset timer
function closeUserPopupAndTimer(){
	infoTimer = window.setTimeout(closeUserPopup, timeout);
}

// reset timer
function resetUserInfoTimer(){
	if(infoTimer)
	{
		window.clearTimeout(infoTimer);
		infoTimer = null;
	}
}
/* ************** End of user popup functions ********** */

/* ************** Start Search text functions ************** */
//for search text box
var displayDefaultValue = function(obj, dValue){
	var objValue = obj.value;
	if (objValue == '')
		obj.value = dValue;
}
//for search text box
var clearDefaultValue = function(obj, dValue){
	var objValue = obj.value;
	if (objValue.toLowerCase() == dValue.toLowerCase())
		obj.value = '';
}
var checkforSearchText = function(obj, dValue, msg){
	clearDefaultValue(obj, dValue);
	var objValue = obj.value;
	if (objValue)
		return true;
	alert_manual(msg, obj);
	//obj.focus();
	return false;
}
/* ************** End Search text functions ************** */

/* ************** Start X functions ************** */
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
function createCookie(name,value,days) {
	if (days) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate()+days);
		var expires = "; expires="+exdate.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}
function readCookie(c_name)
{
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1){
    		c_start=c_start + c_name.length+1;
    		c_end=document.cookie.indexOf(";",c_start);
    		if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	}
  	}
return "";
}

function checkCookie(cookieName)
{
	if (cookieName!=null && cookieName!=""){
  		alert('Welcome again '+cookieName+'! : '+readCookie(cookieName));
  	}else{
  		alert('No cookie found');
  	}
}
/* ************** End X functions ************** */

function LTrim(str){
	  	var whitespace = new String(" \t\n\r");

	  	var s = new String(str);

	  	if (whitespace.indexOf(s.charAt(0)) != -1) {
	    // We have a string with leading blank(s)...

	    	var j=0, i = s.length;
	    	// Iterate from the far left of string until we
	    	// don't have any more whitespace...
	    	while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	    		j++;

		    // Get the substring from the first non-whitespace
		    // character to the end of the string...
		    s = s.substring(j, i);
		  }
	  	return s;
	}

function RTrim(str){
	  	// We don't want to trip JUST spaces, but also tabs,
	  	// line feeds, etc.  Add anything else you want to
	  	// "trim" here in Whitespace
	  	var whitespace = new String(" \t\n\r");

	  	var s = new String(str);

	  	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		    // We have a string with trailing blank(s)...

		    var i = s.length - 1;       // Get length of string

		    // Iterate from the far right of string until we
		    // don't have any more whitespace...
		    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		    	i--;

		    // Get the substring from the front of the string to
		    // where the last non-whitespace character is...
		    s = s.substring(0, i+1);
	  	}
	  	return s;
	}

function Trim(str){
  		return RTrim(LTrim(str));
	}

function getAbsoluteOffsetTopConfirmation(obj){
	    var top = obj.offsetTop;
	    var parent = obj.offsetParent;
	    while (parent != document.body)
			{
		        top += parent.offsetTop;
		        parent = parent.offsetParent;
		    }
	    return top;
	}

function getAbsoluteOffsetLeftConfirmation(obj){
	    var left = obj.offsetLeft;
	    var parent = obj.offsetParent;
	    while (parent != document.body)
			{
		        left += parent.offsetLeft;
		        parent = parent.offsetParent;
		    }
	    return left;
	}

function getPageSizeWithScroll(){
		if (window.innerHeight && window.scrollMaxY) {// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
			xWithScroll = window.innerWidth + window.scrollMaxX;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yWithScroll = document.body.scrollHeight;
			xWithScroll = document.body.scrollWidth;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = document.body.offsetHeight;
			xWithScroll = document.body.offsetWidth;
	  	}
		arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
		//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
		return arrayPageSizeWithScroll;
	}

//Hide all confirmation blocks
function hideAllBlocks(){
		var obj;
		var enable_frm = '';
		if(arguments.length == 1)
			var enable_frm = arguments[0];
		if(obj = $('selAlertbox'))
			obj.style.display = 'none';
		for(var i=0;i<block_arr.length;i++){
				if(obj = $(block_arr[i]))
					{	obj.style.display = 'none';
						disableAll('1', enable_frm);
					}
			}
		if(obj = $('hideScreen'))
			obj.style.display='none';

		if(obj = $('selAjaxWindow'))
			obj.style.display='none';

		if(obj = $('selAjaxWindowInnerDiv'))
			obj.innerHTML='';

		if ((catObj = $('category')) || (sub_catObj = $('sub_category'))){
			br=getBrowser();
			if (br[0] == 'msie' && getMajorVersion(br[1]) == '6'){
				if (catObj = $('category'))
					catObj.style.display = '';

				if (sub_catObj = $('sub_category'))
					sub_catObj.style.display = '';
			}
		}

		return false;
	}
function changePosition(fromObj)
	{
		var obj = fromObj;
		obj.style.display = 'block';
		if (navigator.appName == "Microsoft Internet Explorer")
			{
				var scrolltop = document.documentElement.scrollTop;
				var scrollleft  = document.documentElement.scrollLeft;
				var innerheight = document.documentElement.clientHeight;

				if(innerheight == 0)
					{
						innerheight = document.body.scrollHeight;
					}
				var innerwidth  = document.documentElement.clientWidth;
				if(innerwidth == 0)
					innerwidth = document.body.scrollWidth;
				var divwidth = obj.offsetWidth;
				var divheight = obj.offsetHeight;
				/*if(innerwidth > 1024)
	 				innerwidth = 1024;
	 			if(innerHeight > 602)
	 				innerHeight = 602;*/
			}
		else
			{
				var scrolltop = window.pageYOffset;
				var scrollleft = window.pageXOffset;
				var innerheight = window.innerHeight;
				var innerwidth = window.innerWidth;
				var divwidth = obj.offsetWidth;
				var divheight = obj.offsetHeight;
			}
		//alert(innerwidth+'---'+innerheight);
		if(obj.style.position == 'fixed')
			{
				var movedivleft = (parseInt(innerwidth)/2)-(parseInt(divwidth)/2);
				var movedivtop = (parseInt(innerheight)/2)-(parseInt(divheight)/2);
				//alert(movedivleft);
				//alert(movedivleft);
			}
		else
			{
				var movedivleft = (parseInt(innerwidth)/2)+(parseInt(scrollleft))-(parseInt(divwidth)/2);
				var movedivtop = (parseInt(innerheight)/2)+(parseInt(scrolltop))-(parseInt(divheight)/2);

			}

		obj.style.top = movedivtop + 'px';
		obj.style.left = movedivleft + 'px';
		//alert(obj.style.top +'------------'+obj.style.left);
		obj.style.zIndex = zIndexValue;
		if(obj = $('hideScreen'))
			{

				var ss = getPageSizeWithScroll();
				var ua = navigator.userAgent.toLowerCase();

				if(ua.indexOf("msie") != -1){
					obj.style.width=ss[0]+"px";
				}
				obj.style.height=ss[1]+"px";
				obj.style.display='block';
			}

		return false;
	}

var closLightWindow = function(){
	hideAllBlocks();
	return false;
}

var alert_manual = function()
	{
		var obj;
		var alert_value = arguments[0];
		var need_id = '';
		if(arguments.length == 2)
			need_id = arguments[1];
		if(obj = $('selAlertMessage'))
			obj.innerHTML = alert_value;
		if(fromObj = $('selAlertbox'))
			changePosition(fromObj);
		if(obj = $('selAlertOkButton'))
			{
			obj.focus();
				if(need_id)
					obj.onclick = function(){ hideAllBlocks(); need_id.focus();}
			}
		return false;
	}

//Display confirmation Block
//place, block, form_name, id_array, value_array, property_array, add_top_position, add_left_position
//property_array, add_top_position, add_left_position --- optional
var Confirmation = function(){
	var obj, inc, form_field;
	hideAllBlocks();

	var block = arguments[0];
	var form_name = arguments[1];
	var id_array = arguments[2];
	var value_array = arguments[3];
  	var property_array = new Array();
	multiCheckValue ='';
	if(arguments.length>=5)
		property_array = arguments[4];

	for(inc=0; inc<value_array.length;inc++){
		if(!property_array[inc])
			property_array[inc] = 'value';
		form_field = eval('document.'+form_name+'.'+id_array[inc]);
		if(form_field && form_field[property_array[inc]]!=null)
			form_field[property_array[inc]] = value_array[inc];
		else if(obj = $(id_array[inc]))
			obj[property_array[inc]] = value_array[inc];

	}
	if(fromObj = $(block))
		{
			changePosition(fromObj);
			popupFrmObj = eval('document.'+form_name);
			popupFrmElementsLength = popupFrmObj.elements.length;
			for (inc=0; inc<popupFrmElementsLength-1; inc++)	{
				if (popupFrmObj.elements[inc].className == 'clsCancelButton' || popupFrmObj.elements[inc].className == 'clsPopupcancel' || popupFrmObj.elements[inc].className == 'clsPopCancelButton')
					popupFrmObj.elements[inc].focus();
				else if (popupFrmObj.elements[inc].className == 'clsSubmitButton' || popupFrmObj.elements[inc].className == 'clsPopupsubmit' || popupFrmObj.elements[inc].className == 'clsPopSubmitButton')
					popupFrmObj.elements[inc].focus();
			}
		}
	return false;
}