var session_check = 'heck||||||||||valid||||||||login';
var session_check_replace = 'check||||||||||valid||||||||login';

//function for check box manage
function CheckAll(form_name,check_all,isO,noHL)
	{
		var trk=0;	
		var frm = eval('document.'+form_name);
		var check_frm = eval('document.'+form_name+'.'+check_all);
		
		for (var i=0;i<frm.elements.length;i++)
		{
			var e=frm.elements[i];
			if ((e.name != check_all) && (e.type=='checkbox'))
			{
				if (isO != 1)
				{
					trk++;
					if(e.disabled!=true)
						e.checked=check_frm.checked;
				}			
			}
		}
	}
	
/******* Start Trim Functions ************/
function Trim(TRIM_VALUE)
	{
		if(TRIM_VALUE.length < 1)
			{
				return "";
			}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
			{
				return "";
			}
		else
			{
				return TRIM_VALUE;
			}
	} 
			
function RTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 1)
			{
				return "";
			}
		var iTemp = v_length -1;
		while(iTemp > -1)
			{
				if(VALUE.charAt(iTemp) == w_space)
					{
					}
				else
					{
						strTemp = VALUE.substring(0,iTemp +1);
						break;
					}
				iTemp = iTemp-1;

			}
		return strTemp;
	} 

function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
			{
				return "";
			}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length)
			{
				if(VALUE.charAt(iTemp) == w_space)
					{
					}
				else
					{
						strTemp = VALUE.substring(iTemp,v_length);
						break;
					}
				iTemp = iTemp + 1;
			} 
		return strTemp;
	}
/***********End trim functions********/
function RegularExpressionReplace(expression, subject, replaced) 
	{
	  var re = new RegExp(expression, "g");
	  return subject.replace(re, replaced);
	}
function StringReplcae(find_string, replace_string, subject)
	{
		return RegularExpressionReplace(find_string, subject, replace_string);	
	}
function replace_string(str, search_str, replace_str)
	{
			var condition = true;
			var inc= 1;
			while(condition)
				{
					str = str.replace(search_str,replace_str);
					if(str.indexOf(search_str)<0)
						condition = false;
					inc++;
				}
			return str;
	}

function setFullScreenBrowser(){
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}
//**************** confirmation box related functions Start *******************/
//Change position of the confirmation block
function getAbsoluteOffsetTopConfirmation(obj){
  
	    var top = obj.offsetTop;
	    var parent = obj.offsetParent;
	    while (parent != document.body && parent.tagName != "HTML")
			{
		        top += parent.offsetTop;
		        parent = parent.offsetParent;
		    }
 
	    return top;
	}

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

function $(elmt){
	return document.getElementById(elmt);
}

//Hide all confirmation blocks
function hideAllBlocks(){
		var obj;
		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';
			}
		if(obj = $('hideScreen'))
			obj.style.display='none';
		
		return false;
	}

//Get multible check box value with comma seperator
var multiCheckValue='';
var minimum_top = 20;
var minimum_left = 20;
var zIndexValue = 200;
// form_name, check_all_name, alert_value, place
var getMultiCheckBoxValue = function(){
	var form_name = arguments[0];
	var check_all_name = arguments[1];
	var alert_value = arguments[2];
	var place = 0;
	var add_left_position = 0
	var add_top_position = 0;	
	if(arguments.length>=4)
		place = arguments[3];			
	if(arguments.length>=5)
		add_top_position = arguments[4];
	if(arguments.length>=6)
		add_left_position = arguments[5];
		
	var frm = eval('document.'+form_name);
	var ids = '';
	for(var i=0;i<frm.elements.length;i++){
		var e=frm.elements[i];
		if ((e.name != check_all_name) && (e.type=='checkbox') && e.checked)
			ids += e.value+',';			
	}
	if(ids){
		multiCheckValue =ids.substring(0,ids.length-1);				
		return true;
	}
	if(place)
		alert_manual(alert_value, place, add_top_position, add_left_position);
	else
		alert(alert_value);
	return false;
}

var alert_manual = function()
	{
		var obj;
		var alert_value = arguments[0];
		var place = arguments[1];
		var add_left_position = 0
		var add_top_position = 0;			
		if(arguments.length>=3)
			add_top_position = arguments[2];
		if(arguments.length>=4)
			add_left_position = arguments[3];		
		if(obj = $('selAlertMessage'))
			obj.innerHTML = alert_value;
		if(fromObj = $('selAlertbox'))
			changePosition(fromObj, $(place), add_top_position, add_left_position);
		if(obj = $('selAlertOkButton'))
			obj.focus();
		return false;
	}
function changePosition(fromObj, toObj, add_top_position, add_left_position){

	fromObj.style.zIndex = zIndexValue;
	var top = getAbsoluteOffsetTopConfirmation(toObj)+ add_top_position;

	var left = getAbsoluteOffsetLeftConfirmation(toObj)+ add_left_position;
	if(top<minimum_top)
		top = minimum_top;
	if(left<minimum_left)
		left = minimum_left;

	fromObj.style.top = top + 'px';
	fromObj.style.left = left + 'px';
	fromObj.style.display = 'block';
	if(obj = $('hideScreen')){
		var ss = getPageSizeWithScroll();					
		obj.style.width=ss[0]+"px";
		obj.style.height=ss[1]+"px";
		obj.style.display='block';
	}
}
function showHideScreen(divElm){
	var fromObj = $(divElm);
	fromObj.style.zIndex = zIndexValue;	
	fromObj.style.display = 'block';
	if(obj = $('hideScreen')){
		var ss = getPageSizeWithScroll();				
		obj.style.width=ss[0]+"px";
		obj.style.height=ss[1]+"px";
		obj.style.display='block';
		return false;
	}
}
function makeQueryAsFormFieldValues(form_name)
	{
		var query = '';
		var frm = eval('document.'+form_name);
		for(var i=0;i<frm.elements.length;i++){
				var e=frm.elements[i];
				if (e.type!='button' && e.type!='checkbox'){
						query += e.name+'='+e.value+'&';
					}
			}
		query =query.substring(0,query.length-1);
		return query;
	}

//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 place = arguments[0];
	var block = arguments[1];
	var form_name = arguments[2];
	var id_array = arguments[3];
	var value_array = arguments[4];
	var add_top_position = 0;
	var add_left_position = 0;
	var property_array = new Array();
	multiCheckValue ='';

	if(arguments.length==8)
		var add_left_position = arguments[7];
	if(arguments.length>=7)
		var add_top_position = arguments[6];
	if(arguments.length>=6)
		property_array = arguments[5];

	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, $(place), add_top_position, add_left_position);

	return false;
}
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;
}
//**************** confirmation box related functions End *******************/
function changeWidth(){		
	var width_value = document.formGetCode.image_width.value;
	if(parseInt(max_width_value)>=parseInt(width_value)){				
		var expression = 'width="([0-9]+)"';
		var subject = document.formGetCode.image_code.value;
		var replaced = 'width="'+width_value+'"';				
		document.formGetCode.image_code.value = RegularExpressionReplace(expression, subject, replaced);
	}
}

function chkValidTags(tags){
	var val;
	var i;	
	tags = Trim(tags);
	if(tags=='')
		return true;
	tags = tags.split(' ');
	for (i=0;i<tags.length;i++){
		val = Trim(tags[i]);
		if(val=='')
			continue;
		if((val.length<min_tag_size) || (val.length>max_tag_size))
			return true;
	}
	return false;
}

var getCheckBoxValue = function(){
	var form_name = arguments[0];
	var check_all_name = arguments[1];
	var frm = eval('document.'+form_name);
	var ids = '';
	for(var i=0;i<frm.elements.length;i++){
		var e=frm.elements[i];
		if ((e.name != check_all_name) && (e.type=='checkbox') && e.checked)
			ids += e.value+', ';		
	}
	if(ids){
		multiCheckValue =ids.substring(0,ids.length-1);				
		return true;
	}	
	return false;
}