
Number.prototype.Format=function(number_of_dicimal_places,thousands_separator){
	var num=this;
	if(number_of_dicimal_places>0){
		var mul=Math.pow(10,number_of_dicimal_places);
		num=parseFloat(parseInt(num*mul))/mul;
	} else {
		num=parseInt(num);
	}
	if(thousands_separator){
		var num1=num.toString().replace(/\.[0-9]+/,'').split("").reverse();
		var modula='';
		if(number_of_dicimal_places>0){
			modula=num.toString();
			if(modula.indexOf('.')!=-1){
				modula='.'+modula.toString().replace(/([0-9]+\.)/,'');
			} else {
				modula='';
			}
		} else {
			modula='';
		}
		var num2=new Array();
		var i=0;
		var a=0;
		for(a=0;a<num1.length;a++){
			if(a%3==0 && a>0){
				num2[i++]=thousands_separator;
			}
			num2[i++]=num1[a];
		}
		var testClass = new RegExp("(^"+thousands_separator+")");
		return num2.reverse().join("").replace(testClass,'')+modula;
	} else {
		return num;
	}
}



var gtrfailes=0;

var errorColor = "#E3F2D5";
var posx=0,posy=0;
var med_posx,med_posy;
document.scTop=function (){
	if(document.documentElement){//IE 6+ strict mode
		return document.documentElement.scrollTop;
	}
	else if(document.body){//Other IE
		return document.body.scrollTop;
	}
}

C_addEvent = function(obj, type, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false);
    }
    else if (obj.attachEvent) {
//    	if(UI.debug==1){
//    		UI.debug=0;
//    	}
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
        obj.attachEvent("on"+type, obj[type+fn]);
    }
}
C_addEvent(document,'mousemove',function(e){
	var ev=(!e)?window.event:e;//IE:Moz
	if (ev.pageX){//Moz
		posx=ev.pageX; //+window.pageXOffset;
		posy=ev.pageY; //+window.pageYOffset;
	}
	else if(ev.clientX){//IE
		if(document.documentElement){//IE 6+ strict mode
			posx = ev.clientX + document.documentElement.scrollLeft;
			posy = ev.clientY + document.documentElement.scrollTop;
		}
		else if(document.body){//Other IE
			posx = ev.clientX + document.body.scrollLeft;
			posy = ev.clientY + document.body.scrollTop;
		}
	}
	//else{return false}//old browsers

	med_posx = this.posx=posx;
	med_posy = this.posy=posy;
	if(document.dragging == 1) { //
		if(!this.draggedObject.style.left){
			this.draggedObject.style.left=this.draggedObject.offsetLeft+'px';
		}
		if(!this.draggedObject.style.top){
			this.draggedObject.style.top=this.draggedObject.offsetTop+'px';
		}
		if(!this.draggedObject.style.position!='absolute'){
			this.draggedObject.style.position='absolute';
		}
		this.deltax=this.posx-this.lastx
		this.deltay=this.posy-this.lasty
		this.draggedObject.style.left=(parseInt(this.draggedObject.style.left.replace('px',''))+this.deltax)+'px';
		this.draggedObject.style.top=(parseInt(this.draggedObject.style.top.replace('px',''))+this.deltay)+'px';
		this.lastx=this.posx;
		this.lasty=this.posy;
	}  else {
		this.lastx=this.posx;
	  	this.lasty=this.posy;
	}
});


var overlib_savecolor='';
function overlib(str,event,bgcolor){
	UI.OL.S({Text:str});
	return;
}

function nd(){
	$('overDiv').style.display='none';
	if(overlib_savecolor!=''){
		$('overDiv').style.backgroundColor=overlib_savecolor;
		overlib_savecolor='';
	}
}
var tt_cloud={
	show:function(str,obj){
		$('cloud_content').innerHTML=str;
		$('cloud').style.display='';
		var x = posx-15;
		var x = obj.offsetLeft-obj.offsetWidth/2-4
		var y = obj.offsetTop-$('cloud').offsetHeight;
		//posy-$('cloud').offsetHeight-10;

		//alert($('cloud').offsetHeight);
				$('cloud').style.left=x+'px';
		$('cloud').style.top=y+'px';
		
	},
	hide:function(){
		$('cloud').style.display='none';
	}
}

var currency = {
	get_rate:function(currency_id,onsuccess){
		new Ajax.Request('/shared_ajax_services.php?actions=get_currency_rate&id='+currency_id,{
			method:'get',
			onSuccess: function(transport){
				onsuccess(transport.responseText);
			}
		}
		)
	},
	transform:function(objPrice,source_currency_id,target_currency_id,onsuccess){
		var old_price_value=$(objPrice).innerHTML;
		new Ajax.Request('/shared_ajax_services.php?actions=transform_price&s_id='+source_currency_id+'&t_id='+target_currency_id+'&price='+old_price_value,{
			method:'get',
			onSuccess: function(transport){
				var results=0;
				eval(transport.responseText);
				onsuccess(results);
			}
		}
		)
	}
}




function set_currency_ajax(after_request_actions, currency_id,UpdateSessionCurrency, stop) {
  if(stop == 2)
  {
  	ajax = new Ajax.Request('/shared_ajax_services.php?NODC=00c85a33aacf776a5d502cc6ca804b9f&session_currency='+UpdateSessionCurrency+'&actions=set_default_currency&currency_id='+currency_id,{
			method:'get',
			onSuccess: function(transport){
				if(after_request_actions){
				eval(after_request_actions);
				}
			}
		}
		);
  }
  if(stop == 1)
  {
    eval(after_request_actions);
  }
  if(stop == 0)
  {
     after_request_actions = after_request_actions.replace(/\\'/g,'\'');
     after_request_actions = after_request_actions.replace(/\\"/g,'"');
     after_request_actions = after_request_actions.replace(/\\\\/g,'\\');
     after_request_actions = after_request_actions.replace(/\\0/g,'\0');

	if(confirm('Would you like the selected currency to become your default currency on all MedWOW pages?'))
	{
		ajax = new Ajax.Request('/shared_ajax_services.php?NODC=00c85a33aacf776a5d502cc6ca804b9f&session_currency='+UpdateSessionCurrency+'&actions=set_default_currency&currency_id='+currency_id,{
			method:'get',
			onSuccess: function(transport){
				if(after_request_actions){
				eval(after_request_actions);
				}
			}
		}
		)
	}
	else {
		if(after_request_actions){
		eval(after_request_actions);
		}
	}
  }
}

function set_language_ajax(language_id, language_origine_id) {
  var message= "";
  if(language_origine_id == 1)
  {
	    ajax = new Ajax.Request('/shared_ajax_services.php?NODC=6b868dd2f3065d31454c39cb8756cf71&actions=set_default_language&language_id='+language_id,{
		method:'get',
		onSuccess: function(transport){}
		}
		)
  }
  else
  {
	    ajax = new Ajax.Request('/shared_ajax_services.php?NODC=6b868dd2f3065d31454c39cb8756cf71&actions=set_default_language&language_id='+language_id,{
		method:'get',
		onSuccess: function(transport){}
		}
		)
  }
}

		function checkSearch() {
				if($F('head_search_word').length < 2 || $('head_search_word').value == 'Quick Search') {
					quick_search_error()
					return false;
				}
				$('search_form_div').hide();
				if($('searchin_animate')) { $('searchin_animate').show(); }
				var x=0;
				var xlang=1;
				var link;
				var arr=new Array();
				if(xlang>1){
					arr[x++]='xlang='+xlang;
				}
				//arr[x++]='ViewType=1';
				if($('ViewType').value==1)
				{
					//arr[x++]='ViewType=1';
					link='used-medical-equipments';
				}
				else
				{
					link='wanted-medical-equipments';
					//arr[x++]='ViewType=2';
				}
				arr[x++]='ItemType=1';
				arr[x++]='searchstring='+$F('head_search_word');
				arr[x++]='first_shot=1';
				$('quick_search_animation_div').toggle();
				$('quick_search_div').toggle();
				location.href ='/'+link+'?' +arr.join("&");
		}
		function quick_search_error(){
			alert ('Please enter a search keyword, or click "Advanced Search"');
		}
	function change_lang(lang_url) {
			var lngUrl=lang_url.split(",");
			location.href=lngUrl[1];
	}
	function checkEnter(e,todo){
		if(e && e.which){
			e = e
			characterCode = e.which
		} else{
			e = event
			characterCode = e.keyCode
		}

		if(characterCode == 13){
			if(todo){
				eval(todo)
			}
		}
	}

	function popup_select_currency()
	{
		document.getElementById('change_currency').style.display='block';
		document.getElementById('change_currency').value=document.getElementById('popup_select_currencies').value;
		document.getElementById('change_currency').name=document.getElementById('popup_select_currencies').options[document.getElementById('popup_select_currencies').selectedIndex].text;
		document.getElementById('change_currency').maxlength=false;
		document.getElementById('change_currency').focus();
		close_popup();
	}
	var selected_popup;
	function open_popup(menu_context,p_top,p_left)
	{
		window.scrollTo(0,0);
		if(!menu_context) menu_context='menu_context';
		$('hider').style.zIndex=$(menu_context).style.zIndex-1
		if(!p_top) p_top='30%';
		if(!p_left) p_left='40%';
		$('hider').style.height=document.body.scrollHeight +'px';
		selected_popup=$(menu_context);
		document.getElementById(menu_context).style.top = p_top;
		document.getElementById(menu_context).style.left = p_left;
		document.getElementById(menu_context).style.display = "block";
		document.getElementById(menu_context).style.visibility = "visible";
		$('hider').show();
		$('hider').onclick=function(){
			close_popup(menu_context);
		};

	}

	function close_popup(menu_context)
	{
		if(!menu_context){
			menu_context="menu_context";
		}
		$('hider').hide();
		document.getElementById(menu_context).style.display = "none";
		document.getElementById(menu_context).style.visibility = "hidden";
	}
	function increase_popup_height(){
	}


function change_captcha_image(objCaptcha){
	var s = objCaptcha.src;
	s = s + "&q";
	objCaptcha.src = s;
}

function _addToFavorites(item_number,on_success,on_failure){
	new Ajax.Request('/shared_ajax_services.php?NODC=ea0e469651ee810bb84a0cbb15eacaa2&actions=addToFavorites&sale_number='+item_number,{
		method:'get',
		onSuccess: function(transport){
			on_success();
			/*
			var x=transport.responseText[0];
			switch(x){
				case 1:
					on_success();
					break;
				case 2:
					alert('error');
					break;
			}
			*/
		}
	}
	);
}
var normal_price_test_object={
	sale_number:null,
	device:null,
	model:null
};
function _is_normal_price(objTest,price,currency_id,on_success,on_failure){
	new Ajax.Request('/shared_ajax_services.php?NODC=7af239635acb8a6625da083654a634fb&actions=is_normal_price&sale_number='+objTest.sale_number+'&device='+objTest.device+'&model='+objTest.model+'&price='+price+'&currency_id='+currency_id,{
		method:'get',
		onSuccess: function(transport){
			if(transport.responseText==-1 && on_failure){
				on_failure(transport.responseText);
			} else {
				on_success(transport.responseText);
			}
		}
	}
	);
}
/*
	Implemented By Amir Saleh <amirs@medwow.com>
	JS functions used by CFormInputsJavaScriptValidator in jsvalidator.class.php
*/

var errorWindow='';
var validationErrors=new Array();
var firstError=false;
function fnGetObjectValueByName(objName,flagtest) {

	objects=document.getElementsByName(objName);
	if(objects.length < 1) {
		return null;
	}
	obj = objects[0];
	type = obj.tagName.toLowerCase();
	if(type == "input") {
		type=obj.type.toLowerCase();
	}
	if(flagtest) {
		alert(type);
	}
	switch(type) {
		case 'select':
		case 'text':
		case 'hidden':
		case 'password':
		case 'file':
			return obj.value;
			break;
		case 'radio':
			for(a=0;a<objects.length;a++){
				if(objects[a].checked==true){
					return objects[a].value;
					break;
				}
			}
			return null;
			break;
		case 'checkbox':
			var ret=0;
			for(a=0;a<objects.length;a++){
				if(objects[a].checked==true){
					ret++;
				}
			}
			return ret;
			break;
		}
}

function fnGetObjectHandleByName(objName){
	objects=document.getElementsByName(objName);
	if(objects.length<1) return null;
	return objects[0];
}


function fnCheckVal(objName,condition,values,errMessage,colorObject){
//	alert(values);
	var ret=false;
	var errorAdd='';
	var errorBefore=''
	var errorColor='#ffffff';
	switch(condition){
		case 'isCreditCardNumber':
			objNames=objName.split(",");
			if(isValidCreditCardNumber($F(objNames[0]),$F(objNames[1]))){
				ret=true;
			} else {
				ret=false;
			}
		case '!=':
			if(fnGetObjectValueByName(objName)!=values){
				ret=true;
			} else {
				ret=false;
			}
			break;
		case "isMail":
			var mailfilter=/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
			if(mailfilter.test(fnGetObjectValueByName(objName))){
				ret=true;
			} else {
				ret=false;
			}
			break;
		case '>=':
			if(parseFloat(fnGetObjectValueByName(objName))>=values){
				ret=true;
			} else {
				errorAdd=" Must be greater than "+values;
				ret=false;
			}
			break;
		case '>':
			//alert(fnGetObjectValueByName(objName));
			if(parseFloat(fnGetObjectValueByName(objName)) > values){
				ret=true;
			} else {
				errorAdd=" Must be greater than "+values;
				ret=false;
			}
			break;
		case '==':
			if(fnGetObjectValueByName(objName)==values){
				ret=true;
			} else {
//				errorAdd=" Must be greater than "+values;
				ret=false;
			}
			break;
		case 'length':
			if(document.getElementById(objName).value.trim().length<values){
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'fixed_length':
			if(document.getElementById(objName).value.trim().length==values){
				ret=true;
			} else {
				ret=false;
			}
			break;
		case 'lengthBE':
			if(document.getElementById(objName).value.length<values){
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'notEmpty':
			if(document.getElementById(objName).value.trim().length<1){
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'BETWEEN':
			var limit=values.split(",");
			var val=parseInt($F(objName));
			if(val<parseInt(limit[0]) || val>parseInt(limit[1])){
				errorAdd=" should be between: "+limit[0]+"-"+limit[1];
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'COUNTCHECKED':
			if(fnGetObjectValueByName(objName)<values){
				errorBefore="You should check at least "+values+" ";
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'isChecked':
			if(!$(objName).checked){
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'isMatch':
			if(!$(objName).value.match(values)){
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'COUNTSELECTED':
			if(fnGetObjectValueByName(objName)<values){
				errorBefore="You should select at least "+values+" ";
				ret=false;
			} else {
				ret=true;
			}
			break;
		case 'REGEX':
			var regExp = new RegExp(values, 'i');
			if(regExp.test(fnGetObjectValueByName(objName).trim())){
				ret = true;
			} else {
				ret = false;
			}
			break;
		case 'EMPTY_OR_CUSTOM_REGEX':
			if(!fnGetObjectValueByName(objName).trim().length){
				ret = true;
			} else {
				var regExp = new RegExp(values, 'i');
				if(regExp.test(fnGetObjectValueByName(objName).trim())){
					ret = true;
				} else {
					ret = false;
				}
			}
			break;
		case 'isUrl':
			var filter = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/i;
			var value = $(objName).value;
			if(!value.startsWith('http://') && !value.startsWith('https://')) {
				value = 'http://' + value;
			}
			if(filter.test(value)) {
				ret=true;
			} else {
				ret=false;
			}
			break;
	}
	if(ret){
		if(colorObject){
			if(colorObject.indexOf(",")==-1){
				if($('colorObject')){
					$(colorObject).style.backgroundColor="#ffffff";
				}
				if($(colorObject+'_error')){
					$(colorObject+'_error').style.display='none';
				}
			} else {
				colorObjects=colorObject.split(",");
//				document.getElementById(colorObjects[1]).style.backgroundColor="#ffffff";
				if($(colorObjects[0]+'_error')){
					$(colorObjects[0]+'_error').style.display='none';
				}
			}
		}
		return true;
	} else {
		if(!firstError) firstError=fnGetObjectHandleByName(colorObject.split(",")[0]);
		if(!firstError) firstError=fnGetObjectHandleByName(colorObject.split(",")[1]);
		if(errMessage.indexOf('TEXTOF')==-1){
			errorWindow+=errorBefore+errMessage+errorAdd+'\n';
		} else {
			errorWindow+=document.getElementById(errMessage.replace('TEXTOF','')).innerText+'\n';
		}

		if(colorObject){
			if(colorObject.indexOf(",")==-1){
				if($(colorObject)) {
//					$(colorObject).style.backgroundColor=errorColor;
				}
				if($(colorObject+'_error')){
					$(colorObject+'_error').style.display='';
					$(colorObject+'_error').parentNode.style.display='';
					$(colorObject+'_error').parentNode.parentNode.style.display='';
				}

			} else {
				colorObjects=colorObject.split(",");
//				document.getElementById(colorObjects[1]).style.backgroundColor=errorColor;
				if($(colorObjects[0]+'_error')){
					$(colorObjects[0]+'_error').style.display='';
					$(colorObjects[0]+'_error').parentNode.style.display='';
					$(colorObjects[0]+'_error').parentNode.parentNode.style.display='';
				}
			}

		}
		return false;
	}

}

function fnCheckVal2(objName,condition,values){
	switch(condition){
		case '>':
			if(fnGetObjectValueByName(objName)>values){
				return true;
			}
			break;
		case '>=':
			if(fnGetObjectValueByName(objName)>=values){
				return true;
			}
			break;
		case '&=':
			if(fnGetObjectValueByName(objName)&values){
				return true;
			}
			break;
		case '=':
			if(fnGetObjectValueByName(objName)==values){
				return true;
			}
			break;
		case '!=':
			if(fnGetObjectValueByName(objName)!=values){
				return true;
			}
			break;
		case 'length':
			if(fnGetObjectValueByName(objName).length<values){
				return true;
			}
			break;
		case 'lengthBE':
			if(fnGetObjectValueByName(objName).length>=values){
				return true;
			}
			break;
		case 'notEmpty':
			if(fnGetObjectValueByName(objName)){
				if(fnGetObjectValueByName(objName).length>0){
					return true;
				}
			}
			break;
		case 'COUNTCHECKED':
			if(fnGetObjectValueByName(objName)<values){
				return false;
			} else {
				return true;
			}
			break;
		default:
			alert('This Condition is not supported');

	}
	return false;
}

function fnValidateReturnColor(object,arrValues,errorMessage,caller){
	if(arrValues.indexOf(document.getElementById(object).value) == -1) {
		document.getElementById(object).style.backgroundColor='#ffffff';
//		if($(object+'_error')){
//			$(object+'_error').style.display='none';
//		}
		return true;
	} else {
		return false;
	}

}


function fnIsEqual(object,svalue){
	if(document.getElementById(object).value == svalue) {
		return true;
	} else {
		return false;
	}

}

function getElementsByClassName(className, tag, elm){
//	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var testClass = new RegExp("([ ]*"+className+"[ ]*)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}


function checkMailExists(val,functionAfterEvent){
	new Ajax.Request('shared_ajax_services.php?actions=is_mail_exist&email='+val,{
	method:'get',
	onSuccess: function(transport){
		if(transport.responseText=="1"){
			em_check=true;
		} else {
			em_check=false;
		}
		if(functionAfterEvent){
			fnDelayedEvents(functionAfterEvent,em_check)
		}
	}
	}
	)
}

function VerifyPassword(val,functionAfterEvent){
	new Ajax.Request('shared_ajax_services.php?actions=verify_user_password&reg_password='+val,{
	method:'get',
	onSuccess: function(transport){
		if(transport.responseText=="1"){
			em_check=true;
		} else {
			em_check=false;
		}
		if(functionAfterEvent){
			fnDelayedEvents(functionAfterEvent,em_check)
		}
	}
	}
	)
}


function isMail(val){
	var mailfilter=/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
	if(mailfilter.test(val)){
		return true;
	} else {
		return false;
	}
}

function isValidCreditCardNumber(cardNumber, cardType)
{
  var isValid = false;
  var ccCheckRegExp = /[^\d ]/;
  isValid = !ccCheckRegExp.test(cardNumber);

  if (isValid)
  {
    var cardNumbersOnly = cardNumber.replace(/ /g,"");
    var cardNumberLength = cardNumbersOnly.length;
    var lengthIsValid = false;
    var prefixIsValid = false;
    var prefixRegExp;

    switch(cardType)
    {
      case "mastercard":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^5[1-5]/;
        break;

      case "visa":
        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
        prefixRegExp = /^4/;
        break;

      case "amex":
        lengthIsValid = (cardNumberLength == 15);
        prefixRegExp = /^3(4|7)/;
        break;

      default:
        prefixRegExp = /^$/;
        alert("Card type not found");
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
  }

  if (isValid)
  {
    var numberProduct;
    var numberProductDigitIndex;
    var checkSumTotal = 0;

    for (digitCounter = cardNumberLength - 1;
      digitCounter >= 0;
      digitCounter--)
    {
      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
      digitCounter--;
      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
      for (var productDigitCounter = 0;
        productDigitCounter < numberProduct.length;
        productDigitCounter++)
      {
        checkSumTotal +=
          parseInt(numberProduct.charAt(productDigitCounter));
      }
    }

    isValid = (checkSumTotal % 10 == 0);
  }

  return isValid;
}

function switchDisplay(objId){
	if($(objId).style.display==''){
		$(objId).style.display='none';
	} else {
		$(objId).style.display='';
	}
}


/*

KEYBOARD VALIDATOR
ADDEDD BY Amir Saleh
*/
var keybYN = new keybEdit('yn','Valid values are \'Y\' or \'N\'.');
var keybNumeric = new keybEdit('01234567890','Numeric input only.');
var keybMNumeric = new keybEdit('01234567890.','Numeric input only.');
var keybAlpha = new keybEdit('abcdefghijklmnopqurstuvwxyz ','Alpha input only.');
var keybAlphaNumeric = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.');
var keybDecimal = new keybEdit('01234567890.','Decimal input only.');
var keybDate =  new keybEdit('01234567890/','Date input only');;
var keybYNNM = new keybEdit('yn');
var keybNumericNM = new keybEdit('01234567890');
var keybAlphaNM = new keybEdit('abcdefghijklmnopqurstuvwxy');
var keybAlphaNumericNM = new keybEdit('abcdefghijklmnopqurstuvwxy01234567890');
var keybDecimalNM = new keybEdit('01234567890.');
var keybDateNM = new keybEdit('01234567890/');;

function keybEdit(strValid, strMsg) {
	//	Variables
	var reWork = new RegExp('[a-z]','gi');		//	Regular expression\

	//	Properties
	if(reWork.test(strValid))
		this.valid = strValid.toLowerCase() + strValid.toUpperCase();
	else
		this.valid = strValid;

	if((strMsg == null) || (typeof(strMsg) == 'undefined'))
		this.message = '';
	else
		this.message = strMsg;

	//	Methods
	this.getValid = keybEditGetValid;
	this.getMessage = keybEditGetMessage;

	function keybEditGetValid() {

		return this.valid.toString();
	}

	function keybEditGetMessage() {

		return this.message;
	}
}

function editKeyBoard(objForm, objKeyb,evt) {
	var ie=false;
	if(!evt) {
		ie=1;
		evt=window.event;
	}
	strWork = objKeyb.getValid();
	strMsg = '';							// Error message
	blnValidChar = false;					// Valid character flag
	var keycode=(evt.keyCode)?evt.keyCode:evt.charCode;
	// Part 1: Validate input
	if(!blnValidChar)
		for(i=0;i < strWork.length;i++)
			if(keycode == strWork.charCodeAt(i)) {
				blnValidChar = true;

				break;
			}

	// Part 2: Build error message
	if(!blnValidChar) {
//		if(objKeyb.getMessage().toString().length != 0)
//			alert('Error: ' + objKeyb.getMessage());
		if(evt.keyCode) {
			evt.returnValue = false;		// Clear invalid character
		} else {
			if(keycode!=8) evt.preventDefault()
		}

		objForm.focus();						// Set focus
	}
}

function stripHTML(oldString, object)
{
	if(object.value.indexOf("<")!=-1 || object.value.indexOf(">")!=-1){
		object.value=object.value.replace(/</gi,"");
		object.value=object.value.replace(/>/gi,"");
	}
/*	var newString = "";
   	var inTag = false;
   	for(var i = 0; i < oldString.length; i++)
   	{
   		if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>')
        {
        	if(oldString.charAt(i+1)=="<"){}
			else
			{
				inTag = false;
				i++;
			}
        }
		if(!inTag) newString += oldString.charAt(i);
   }
   if(oldString != newString)
   {
   		object.value = newString;
   }
   */
}



//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor="lightyellow"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/;

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}


var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function is_ie6_or_older(){
	var agt=navigator.userAgent.toLowerCase();
	return ((agt.indexOf("msie 5.")!=-1) || (agt.indexOf("msie 6.")!=-1) || (agt.indexOf("msie 4.")!=-1));
}

function is_ff(){
	return (navigator.userAgent.indexOf('Firefox')!=-1);
}
function is_ie7(){
	return (navigator.userAgent.indexOf('MSIE 7.')!=-1);
}

function is_ie(){
	return (navigator.userAgent.indexOf('MSIE')!=-1);
}
function is_opera(){
	return (navigator.userAgent.indexOf('Opera')!=-1);
}
function is_safari(){
	return (navigator.userAgent.indexOf('Safari')!=-1);
}
function is_chrome(){
	return (navigator.userAgent.indexOf('Chrome')!=-1);
}

function fnSetOpacity(Obj,opacity){
	if(typeof(Obj)=='string'){
		Obj=$(Obj);
	}
	if(is_ie()){
		Obj.style.filter="alpha(opacity="+(opacity*100)+")";
	}
	if(is_ff()){
		Obj.style.MozOpacity=opacity;
	}
	if(is_opera() || is_safari() || is_chrome()){
		Obj.style.opacity=opacity;
	}
}

Ajax.Request.prototype.abort = function() {
    // prevent and state change callbacks from being issued
    this.transport.onreadystatechange = Prototype.emptyFunction;
    // abort the XHR
    this.transport.abort();
    // update the request counter
    Ajax.activeRequestCount--;
};

function fnSetAutoComplete(objId,objAutoCompleteDivId,AJAXDataSource,strOnItemClick){
	if(objAutoCompleteDivId==''){
		objAutoCompleteDivId = 'dv' + (new Date().getTime());
		var div_ac = document.createElement("DIV");
		div_ac.id = objAutoCompleteDivId;
		div_ac.style.position = 'absolute';
		div_ac.style.width = $(objId).offsetWidth + 'px';
		div_ac.style.overflow = 'hidden';
		div_ac.style.top = $(objId).offsetTop+$(objId).offsetHeight + 'px';
		$(objId).parentNode.insertBefore(div_ac,$(objId));
	}

	if(!document.ACLCLASSCREATED) {
		document.ACLCLASSCREATED=1;
		if(is_ie()){
			var ss1 = document.createElement('style');
			var def = '.ACL_selected {padding:3px;height:18px;line-height:18px;overflow-y:hidden;background-color:#59A910;cursor:pointer;color: #fff}';
			def += '.ACL_unselected{padding:3px;line-height:18px;height:18px;overflow-y:hidden;background-color: #fff;cursor:pointer;color: #666}';
			ss1.setAttribute("type", "text/css");
			ss1.styleSheet.cssText = def;
			var hh1 = document.getElementsByTagName('head')[0];
			hh1.appendChild(ss1);
		} else {
			var asheet = document.createElement('style');
			asheet.innerText="";
			asheet.innerHTML='.ACL_selected {padding:3px;height:18px;line-height:18px;overflow-y:hidden;background-color:#59A910;cursor:pointer;color: #fff}';
			asheet.innerHTML+="\n";
			asheet.innerHTML+='.ACL_unselected{padding:3px;line-height:18px;height:18px;overflow-y:hidden;background-color: #fff;cursor:pointer;color: #666}';
			document.body.appendChild(asheet);
		}

	}
	if(!document.getElementById(objId)){
		return;
	}
	/**
	Created By Amir Saleh
	**/
	$(objId).Cache=new Array();
	$(objId).interrupt=null;
	$(objId).ACL_Starter_Timer=null;
	$(objId).ACL_Ajax=null;
	$(objId).ACL_Time=null;
	$(objId).ACL_CurrentPlace=0;
	$(objId).ACL_NumberOfResults=0;
	$(objId).ACL_hold=0;
	$(objId).ACL_textObject=null;
	$(objId).ACL_lastListedPart='';
	$(objId).ACL_Blur=function(){
		$(objId).ACL_Time=setTimeout("$('"+objId+"').ACL_TimeOut();",200);
	}
	$(objId).ACL_TimeOut=function(){$(objAutoCompleteDivId).hide();clearTimeout($(objId).ACL_Time);}
	$(objId).ACL_getListingsStarter=function(part,obj,event){
		$(objId).ACL_textObject=obj;
		if($(objId).ACL_Starter_Timer!=null){
			clearTimeout($(objId).ACL_Starter_Timer);
		}
		if(!event) {ie=1;event=window.event;}
		var keycode=((event.keyCode)?event.keyCode:event.charCode);
		if(!is_opera()){
			if($(objId).updownArrow(keycode)){
				return;
			}
		}
		if(keycode==13 || keycode==27){
			$(objAutoCompleteDivId).hide();
			return;
		}
		if($(objId).ACL_lastListedPart==part) return;
		$(objId).ACL_lastListedPart=part;
		if(part==''){
			if($(objId).ACL_Ajax){
				$(objId).ACL_Ajax.abort();
			}
			$(objId).interrupt=1;
			$(objAutoCompleteDivId).hide();
			$(objId).ACL_NumberOfResults=0;
			$(objId).ACL_hold=0;
			return;
		}
		//if($(objId).ACL_hold==1) return;

		$(objId).interrupt=1;
		if($(objId).ACL_Ajax){
			$(objId).ACL_Ajax.abort();
		}
		setTimeout("$('"+objId+"').ACL_getListings('"+part+"','"+obj+"','"+event+"');",100);

	}
	$(objId).ACL_getListings = function(part,obj,event){
		$(objId).interrupt=null;
		$(objId).ACL_hold=1;
		if(!$(objId).Cache[part]){
			$(objId).ACL_Ajax = new Ajax.Request(AJAXDataSource,{
				parameters: 'p='+part,
				contentType:  'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				method:'post',
				onSuccess: function(transport){
					var x=eval(transport.responseText);
					$(objId).Cache[part]=(x==null)?-1:x;
					$(objId).BuildResultsView($(objId).Cache[part]);
				}
			}
			)
		}
		else {
			//alert($(objId).Cache[part]);
			$(objId).BuildResultsView($(objId).Cache[part]);
		}
	};
	$(objId).BuildResultsView = function(x){
		if(x==-1){
			$(objAutoCompleteDivId).hide();
			$(objId).ACL_NumberOfResults=0;
			$(objId).ACL_hold=0;
			return;
		}
		$(objId).ACL_CurrentPlace=0;
		$(objId).ACL_NumberOfResults=x.length;
		var ht='<div style="height:0px;" id="ACL_Title" class=""></div>';
		for(a=0;a<x.length;a++){
			if($(objId).interrupt!=null){
				$(objId).interrupt=null;
				$(objAutoCompleteDivId).update('');
				$(objAutoCompleteDivId).hide();
				break;
				return;
			}
			ht=ht + '<div style="display:block;" id="'+objId+'ACL_Item'+a+'" class="ACL_unselected" onclick="$(\''+$(objId).ACL_textObject.id+'\').value=\''+x[a]+'\';$(\''+objAutoCompleteDivId+'\').hide();'+strOnItemClick+'" onmouseover="$(\''+objId+'\').autoComplete_onMouseOverItem('+(a+1)+')">' + x[a] +'</div>';
		}
		ht+='<div style="margin-bottom:3px;float:right;margin-right:10px;" id="ACL_Title" class=""><a onclick="$(\''+objAutoCompleteDivId+'\').hide();" style="text-decoration:underline;cursor:pointer">close</a></div>';
		$(objAutoCompleteDivId).update(ht);
		$(objAutoCompleteDivId).show();
		$(objId).ACL_hold=0;
	};
	$(objId).autoComplete_onMouseOverItem = function(i) {
		for(a=0;a<$(objAutoCompleteDivId).childNodes.length;a++){
			if($(objAutoCompleteDivId).childNodes[a].id!='ACL_Title') $(objAutoCompleteDivId).childNodes[a].className='ACL_unselected'
		}
		$(objAutoCompleteDivId).childNodes[i].className='ACL_selected';
	}
	$(objId).updownArrow = function(keyCode) {
		if((keyCode == 40 || keyCode == 38) && $(objId).ACL_NumberOfResults>0){

			if(keyCode == 38){ // keyUp
				if($(objId).ACL_CurrentPlace == 1){
					$(objId).ACL_CurrentPlace = $(objId).ACL_NumberOfResults;
				}else{
					$(objId).ACL_CurrentPlace--;
				}
			} else { // keyDown
				if($(objId).ACL_CurrentPlace == $(objId).ACL_NumberOfResults){
					$(objId).ACL_CurrentPlace = 1;
				}else {
					$(objId).ACL_CurrentPlace++;
				}
			}
			$(objId).autoComplete_onMouseOverItem($(objId).ACL_CurrentPlace)
			$(objId).value=$(objId+'ACL_Item'+($(objId).ACL_CurrentPlace-1)).innerHTML;
			return true;
		} else {
			// reset
			$(objId).ACL_CurrentPlace = -1;
			return false;
		}
	}
	var _onkeyup=$(objId).onkeyup;
	$(objId).onkeyup=function(event){
		if(_onkeyup){
			//_onkeyup();
		}
		this.ACL_getListingsStarter(this.value,this,event);
	}
	$(objId).onblur=function(){
		$(objId).ACL_Blur();
	};
	if(is_opera()){
		_onkeypress=$(objId).onkeypress;
		$(objId).onkeypress=function(event){
			if(!event) {
				ie=1;
				event=window.event;
			}
			var keycode=((event.keyCode)?event.keyCode:event.charCode);
			if($(objId).updownArrow(keycode)){
				return;
			}
			if(_onkeypress){
				_onkeypress();
			}
		}


	}

}


function fnSetItemSlider(arrParams){
	if (!$(arrParams.rotationObject)) {
		return;
	}
	/** Created By Amir Saleh
		Sample Params Array
		var arrParams =	{
						"rotationObject":"more_results",
						"btnNextElement":"mr_up_arrow",
						"btnBackElement":"mr_down_arrow",
						"btnNextClassName":"mr_up_ar",
						"btnNextDisabledClassName":"mr_up_disabled",
						"btnBackClassName":"mr_down_ar",
						"btnBackDisabledClassName":"mr_down_disabled",
						"MaxResults":75,
						"MaxStep":24,
						"StepLength":699
						};

	**/
	$(arrParams.rotationObject).current_step=0;
	$(arrParams.rotationObject).max_results=arrParams.MaxResults;
	$(arrParams.rotationObject).max_step=arrParams.MaxStep;
	$(arrParams.rotationObject).scrolling=0;
	$(arrParams.rotationObject).scrollingy=0;
	$(arrParams.rotationObject).mr_intervalID;
	$(arrParams.rotationObject).scrollingspeed=20;
	$(arrParams.rotationObject).step_length=arrParams.StepLength;
	$(arrParams.rotationObject).m_opacity=1;
	$(arrParams.rotationObject).opacity_speed=0.1;
	$(arrParams.rotationObject).scrolling=false;
	$(arrParams.rotationObject).btnNextClassName=arrParams.btnNextClassName?arrParams.btnNextClassName:'mr_up_ar';
	$(arrParams.rotationObject).btnNextDisabledClassName=arrParams.btnNextDisabledClassName?arrParams.btnNextDisabledClassName:'mr_up_disabled';
	$(arrParams.rotationObject).btnBackClassName=arrParams.btnBackClassName?arrParams.btnBackClassName:'mr_down_ar';
	$(arrParams.rotationObject).btnBackDisabledClassName=arrParams.btnBackDisabledClassName?arrParams.btnBackDisabledClassName:'mr_down_disabled';

	if($(arrParams.rotationObject).max_step<1){
			$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextDisabledClassName;
			$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackDisabledClassName;
	} else {
			$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextDisabledClassName;
			$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackClassName;
	}
	$(arrParams.btnNextElement).onclick=function(){if(!$(arrParams.rotationObject).scrolling) $(arrParams.rotationObject).mr_go(1);};
	$(arrParams.btnBackElement).onclick=function(){if(!$(arrParams.rotationObject).scrolling) $(arrParams.rotationObject).mr_go(-1);};
	$(arrParams.rotationObject).fade_scroller = function (dir){
		$(arrParams.rotationObject).use_step=$(arrParams.rotationObject).current_step+(-1*dir);
		if($(arrParams.rotationObject).current_step<0){
			$(arrParams.rotationObject).step=-1*$(arrParams.rotationObject).current_step;
		} else {
			$(arrParams.rotationObject).step=$(arrParams.rotationObject).current_step;
		}
		$(arrParams.rotationObject).step=$(arrParams.rotationObject).step*3+1;
		$(arrParams.rotationObject).step2=$(arrParams.rotationObject).step+2;
		if($(arrParams.rotationObject).step2>$(arrParams.rotationObject).max_results){
			$(arrParams.rotationObject).step2=$(arrParams.rotationObject).max_results;
		}
//		$('paging_for_items').innerHTML= step + ' - '+ step2;
			if($(arrParams.rotationObject).max_step>1 && document.getElementById('paging_for_items')) {
				$('paging_for_items').innerHTML= $(arrParams.rotationObject).step + ' - '+ $(arrParams.rotationObject).step2;
			}
		clearInterval($(arrParams.rotationObject).mr_intervalID);
		newOffset=(($(arrParams.rotationObject).use_step*$(arrParams.rotationObject).step_length)+dir*$(arrParams.rotationObject).step_length)+'px';
		if (PageInfo.boolRTL) {
			$(arrParams.rotationObject).style.right=newOffset;
		} else {
			$(arrParams.rotationObject).style.left=newOffset;
		}
		$(arrParams.rotationObject).scrollingy=0;
		if($(arrParams.rotationObject).current_step<0){
			$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextClassName;
		} else {
			$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextDisabledClassName;
		}
		if($(arrParams.rotationObject).current_step<=(-$(arrParams.rotationObject).max_step)){
			$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackDisabledClassName;
		} else {
			$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackClassName;
		}

	}

	$(arrParams.rotationObject).fnFadeOut=function (dir){
		$(arrParams.rotationObject).m_opacity=$(arrParams.rotationObject).m_opacity-$(arrParams.rotationObject).opacity_speed;
		if($(arrParams.rotationObject).m_opacity<0){
			$(arrParams.rotationObject).m_opacity=0;
			fnSetOpacity(arrParams.rotationObject,$(arrParams.rotationObject).m_opacity)
			$(arrParams.rotationObject).fade_scroller(dir);
			clearInterval($(arrParams.rotationObject).mr_intervalID);
			$(arrParams.rotationObject).mr_intervalID=setInterval("$('"+arrParams.rotationObject+"').fnFadeIn("+dir+")",50);
		} else {
			fnSetOpacity(arrParams.rotationObject,$(arrParams.rotationObject).m_opacity)
		}
	}
	$(arrParams.rotationObject).fnFadeIn = function (dir){
		$(arrParams.rotationObject).m_opacity+=$(arrParams.rotationObject).opacity_speed;
		if($(arrParams.rotationObject).m_opacity>1){
			$(arrParams.rotationObject).m_opacity=1;
			fnSetOpacity(arrParams.rotationObject,$(arrParams.rotationObject).m_opacity)
			$(arrParams.rotationObject).scrolling=0;
			clearInterval($(arrParams.rotationObject).mr_intervalID);
		} else {
			fnSetOpacity(arrParams.rotationObject,$(arrParams.rotationObject).m_opacity)
		}
	}

	$(arrParams.rotationObject).mr_go=function(dir){
		if($(arrParams.rotationObject).max_step<1){
			return 1;
		}
		if($(arrParams.rotationObject).scrolling) return;
		if($(arrParams.rotationObject).current_step==0 && dir==1) {
			return;
		}
		if($(arrParams.rotationObject).current_step==(-$(arrParams.rotationObject).max_step) && dir==-1) {
			return;
		}
		$(arrParams.rotationObject).scrolling=1;
		$(arrParams.rotationObject).current_step=$(arrParams.rotationObject).current_step+dir;
		if(is_ff()){
			$(arrParams.rotationObject).mr_intervalID=setInterval("$('"+arrParams.rotationObject+"').fnFadeOut("+dir+")",50);
		} else {
			$(arrParams.rotationObject).mr_intervalID=setInterval("$('"+arrParams.rotationObject+"').mr_scrolltop("+dir+")",10);
		}
	}

	$(arrParams.rotationObject).mr_scrolltop= function (dir){
		$(arrParams.rotationObject).use_step=$(arrParams.rotationObject).current_step+(-1*dir);
		$(arrParams.rotationObject).scrollingy+=$(arrParams.rotationObject).scrollingspeed;
		if($(arrParams.rotationObject).scrollingy>$(arrParams.rotationObject).step_length-$(arrParams.rotationObject).scrollingspeed){
			if($(arrParams.rotationObject).current_step<0){
				$(arrParams.rotationObject).step=-1*$(arrParams.rotationObject).current_step;
			} else {
				$(arrParams.rotationObject).step=$(arrParams.rotationObject).current_step;
			}
			$(arrParams.rotationObject).step=$(arrParams.rotationObject).step*3+1;
			$(arrParams.rotationObject).step2=$(arrParams.rotationObject).step+2;
			if($(arrParams.rotationObject).step2>$(arrParams.rotationObject).max_results){
				$(arrParams.rotationObject).step2=$(arrParams.rotationObject).max_results;
			}
			if($(arrParams.rotationObject).max_step>1 && document.getElementById('paging_for_items')) {
				$('paging_for_items').innerHTML= $(arrParams.rotationObject).step + ' - '+ $(arrParams.rotationObject).step2;
			}
			clearInterval($(arrParams.rotationObject).mr_intervalID);
			newOffset=(($(arrParams.rotationObject).use_step*$(arrParams.rotationObject).step_length)+dir*$(arrParams.rotationObject).step_length)+'px';
			if (PageInfo.boolRTL) {
				$(arrParams.rotationObject).style.right=newOffset;
			} else {
				$(arrParams.rotationObject).style.left=newOffset;
			}
			$(arrParams.rotationObject).scrollingy=0;
			$(arrParams.rotationObject).scrolling=0;
			if($(arrParams.rotationObject).current_step<0){
				$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextClassName;
			} else {
				$(arrParams.btnNextElement).className=$(arrParams.rotationObject).btnNextDisabledClassName;
			}
			if($(arrParams.rotationObject).current_step<=(-$(arrParams.rotationObject).max_step)){
				$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackDisabledClassName;
			} else {
				$(arrParams.btnBackElement).className=$(arrParams.rotationObject).btnBackClassName;
			}

		} else {
			newOffset=(($(arrParams.rotationObject).use_step*$(arrParams.rotationObject).step_length)+dir*$(arrParams.rotationObject).scrollingy)+'px';
			if (PageInfo.boolRTL) {
				$(arrParams.rotationObject).style.right=newOffset;
			} else {
				$(arrParams.rotationObject).style.left=newOffset;
			}
		}
	}
}

function absLeft(obj){
	if(obj.parentNode==document.body){
		return obj.offsetLeft
	} else {
		alert(1);
		return obj.offsetLeft + absLeft(obj.parentNode);
	}
}

var _OpenedSubMenu=null;
var debug=0;
function _addSubMenu(objTarget,objMenu,setleft,setTop,TargetMouseOverClass,TargetMouseOutClass){
	$(objTarget).mouseOutTimer=null;
	if(TargetMouseOutClass){
		$(objTarget).className=TargetMouseOutClass;
	}
	if(setleft){
		switch(setleft){
			case 'afterobject':
				$(objMenu).style.left=$(objMenu).offsetLeft+$(objTarget).offsetWidth+'px';
				break;
			default:
				$(objMenu).style.left=$(objMenu).offsetLeft+setleft+'px';
		}

	}
	$(objMenu).hide();
	$(objTarget).onmouseover=function(){
		if(_OpenedSubMenu){
			_OpenedSubMenu.style.display='none';
		}
		if($(objTarget).mouseOutTimer){
			clearInterval($(objTarget).mouseOutTimer);
			$(objTarget).mouseOutTimer=null;
		}
		_OpenedSubMenu=$(objMenu);
		$(objMenu).show();
		if(TargetMouseOverClass){
			$(objTarget).className=TargetMouseOverClass;
		}
	}
	$(objMenu).onmouseover=$(objTarget).onmouseover;
	$(objTarget).hideMenu=function(){
		if(TargetMouseOutClass){
			$(objTarget).className=TargetMouseOutClass;
		}
		if($(objTarget).mouseOutTimer){
			clearInterval($(objTarget).mouseOutTimer);
			$(objTarget).mouseOutTimer=null;
		}
		$(objMenu).hide();
	}
	$(objTarget).onmouseout=function(){
		$(objTarget).mouseOutTimer=setInterval("$('"+objTarget+"').hideMenu()",50);
	}
	$(objMenu).onmouseout=$(objTarget).onmouseout;
}




var viewportwidth;
var viewportheight;

document.ViewPort = function () {
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	} else if (
		typeof document.documentElement != 'undefined' && 
		typeof document.documentElement.clientWidth != 'undefined' &&
		document.documentElement.clientWidth != 0
		) {
			viewportwidth = document.documentElement.clientWidth,
			viewportheight = document.documentElement.clientHeight
	} else {
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
}
document.ViewPort();
//var _dWrite=document.write;
//document.write=function(content){
//	if(document.WriteCursor){
//		document.WriteCursor.innerHTML=document.WriteCursor.innerHTML+content;
//	} else {
//		_dWrite(content);
//	}
//}
var Common={
	
	findPos:function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	},
	SystemDebugger:0,
	Texts:{

	},
	Viewer:'',
	GetViewer:function(){
		if(this.Viewer==''){
			this.Viewer=popupObj.Clone();
		}
		return this.Viewer;
	},
	Clone:function(object){
		var new_object={};
		for (a in object){new_object[a]=object[a];}
		return new_object;
	},
	Extend:function(obj){
		obj.update=function(content){
			obj.innerHTML=content;
		}
		obj.show=function(){
			obj.style.display='';
		}
		obj.hide=function(){
			obj.style.display='none';
		}
	},
	InsertScriptFile:function(ParentElement,ScriptSrc,sleep){
		document.WriteCursor=ParentElement;
		var Script= document.createElement('script');
		Script.type= 'text/javascript';
		Script.src= ScriptSrc;
		ParentElement.appendChild(Script);
		if(sleep) {
			this.Sleep(sleep);
		}
	},
  	Sleep:function(naptime){
		naptime = naptime * 1000;
		var sleeping = true;
		var now = new Date();
		var alarm;
		var startingMSeconds = now.getTime();
		while(sleeping){
			alarm = new Date();
			alarmMSeconds = alarm.getTime();
			if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
		}
    },
	HideElements:function(objParams){
		if(objParams.Multiple){
			for(var a=objParams.Multiple.FirstIndex;a<=objParams.Multiple.LastIndex;a++){
				$(objParams.Multiple.Prefix+a).hide();
			}
		}
	},
 	ie6d:function(){
		return (navigator.appName=='Microsoft Internet Explorer' && (navigator.appVersion.indexOf('MSIE [7-9]')==-1));
	},
	HttpGet:function(arrParams,onSuccess,strTargetScript){
		if(!strTargetScript){
			strTargetScript="/ajax.interface.php";
		}
		new Ajax.Request (strTargetScript,
		{
			method: "post",
			parameters: arrParams.join("&"),
			onSuccess: function (res) {
				onSuccess(res.responseText);
			}
		}
		);
	},
	Browser:{
		is_ff:function(){
			return (navigator.userAgent.indexOf('Firefox')!=-1);
		},

		is_ie:function(){
			return (navigator.userAgent.indexOf('MSIE')!=-1);
		},
		is_opera:function(){
			return (navigator.userAgent.indexOf('Opera')!=-1);
		},
		ie6d:function(){
			if(navigator.appName=='Microsoft Internet Explorer'){
				var x=navigator.appVersion.match(/MSIE ([0-9]+)\./);
				if(x[1] && x[1]<7){
					return 1;
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		},
		ie7d:function(){
			if(navigator.appName=='Microsoft Internet Explorer'){
				var x=navigator.appVersion.match(/MSIE ([0-9]+)\./);
				if(x[1] && x[1]<8){
					return 1;
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		},
		is_safari:function(){
			return (navigator.userAgent.indexOf('Safari')!=-1);
		},
		is_chrome:function(){
			return (navigator.userAgent.indexOf('Chrome')!=-1);
		}
		
	},
	fastLogin: {
		handleResults:function(results) {
			switch(results.actions) {
				case 'showIframe':
					$(document.FastLoginPopup.Hider).show();
					$(document.FastLoginPopup.Container).show();
					break;
				case 'login_success':
					$('top_links_right').innerHTML = Base64.decode(results.login_div);
					if(document.onLoginSuccess) {
						document.onLoginSuccess();
					}
					document.FastLoginPopup.close();
					break;
			}
		},
		login:function (onSuccess) {
			if(typeof(popup_v2)=='undefined') {
				var popup_v2 = false;
			}
			var url  = (location.hostname.indexOf("medwow.com")!=-1? 'https://':'http://') + location.hostname + '/tag/fronthandler/member?actions=fast_login';
			document.FastLoginPopup = popup_v2?popup_v2:Common.GetViewer();
			document.FastLoginPopup = Common.Browser.ie6d()?Common.GetViewer():document.FastLoginPopup;
			document.onLoginSuccess = onSuccess;
			document.FastLoginPopup.open('&nbsp;','<iframe id="flog" style="border: 0px;" frameborder="0" src="'+url+'" width="690" height="430"> </iframe>')
			if(!document.FastLoginPopup.Hider) {
				document.FastLoginPopup.Hider = document.UIHider;
			}
			$(document.FastLoginPopup.Hider).hide();
			$(document.FastLoginPopup.Container).hide();
		}
		
	},
	redirectIfLoggedIn:function (url) {
		url = Base64.encode(url);
		//var targ  = (location.hostname.indexOf("medwow.com")!=-1? 'https://':'http://') + location.hostname + '/tag/fronthandler/member?actions=fast_login&url='+url;
		var targ  = (location.hostname.indexOf("medwow.com")!=-1? 'https://':'http://') + location.hostname + '/members.php?actions=login_form&surl='+url;
		location.href = targ;
	},
	OpenLink:function(link){
		window.open(link, "_blank");
	}
}
Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}



var HTMLGenerator = {
	CreateOptionsFromArray:function(arrData,strValueIndex,strTextIndex,AddOptionToExpand,NoSelectOption){
		if(NoSelectOption){
			 var ret='';
		} else {
			var ret='<option value="0">Select</option>';
		}
		if(!strValueIndex || strValueIndex==''){
			strValueIndex="value";
		}
		if(!strTextIndex || strTextIndex==''){
			strTextIndex="text";
		}
		for(var a=0;a<arrData.length;a++){
			if(arrData[a]['isGroupStart']){
				ret+='<optgroup label="'+arrData[a][strTextIndex]+'">';
			} else if(arrData[a]['isGroupEnd']) {
				ret+='</optgroup>';
			} else {
				ret+='<option value="'+arrData[a][strValueIndex]+'">'+arrData[a][strTextIndex]+'</option>';
			}
		}
		if(AddOptionToExpand){
			ret+='<option value="more">More</option>';
		}
		return ret;
	},
	UpdateSelectElement:function(objParams){
		if(!objParams.arrParams){
			objParams.arrParams=new Array();
			objParams.arrParams[0]="noparams=1";
		}
		Common.HttpGet(objParams.arrParams,function(res){
			var arrData=new Array();
			var c=0;
			eval(res);
			if(res.finallist){
				objParams.Element.update(res.finallist);
			} else {
				if(res.data.length){
					if(res.data.length==1){
						arrData[c++]={
							id:0,
							name:res.data[0]
						}
					}
				} else {
					for( var a in res.data){
						arrData[c++]={
							id:a,
							name:res.data[a]
						};
					}
				}
				objParams.Element.update(HTMLGenerator.CreateOptionsFromArray(arrData,'id','name',0,1));
			}
			if(objParams.callback!=''){
				eval(objParams.callback +'('+Object.toJSON(res.data)+','+Object.toJSON(res)+')');
			}
			objParams.Element.fireEvent('onchange');
		},objParams.resource);
	}

}
document.Menus=[];
if(typeof(UI)=='undefined'){
	var UI = {};
}
Object.extend(UI,{
	Blink2Colors:function (object_id,color1,color2,time,returns){
		obj = $(object_id);
		obj.color1 = color1;
		obj.color2 = color2;
		obj.style.color = color1;
		if(returns && returns>0){
			obj.returns = returns*2+1;
		} else {
			obj.returns = 0;
		}
		obj.blink = function(){

			this.style.color = (this.returns%2)? this.color2:this.color1;
			this.returns--;
			if(this.returns==1){
				clearInterval(obj.IntervalId);
			}

		}
		obj.IntervalId = setInterval("$('"+object_id+"').blink()",time);
	},

	MakeSameHeight:function(ob1,ob2){
		if(ob1.offsetHeight > ob2.offsetHeight){
			ob2.style.height=(ob1.offsetHeight) +'px';
		} else {
			ob1.style.height=(ob2.offsetHeight) +'px';
		}
	},
	debug:1,
	UpdateCaptchImage:function (objCaptcha){
		var s = objCaptcha.src;
		s = s + "&q";
		objCaptcha.src = s;
	},
    addEvent : function(obj, type, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(type, fn, false);
        }
        else if (obj.attachEvent) {
        	if(UI.debug==1){
        		UI.debug=0;
        	}
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
            obj.attachEvent("on"+type, obj[type+fn]);
        }
    },
    getElementsByClassName : function(className, tag, elm) {
        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                returnElements.push(current);
            }
        }
        return returnElements;
    },
	MakeSameHeightByClassName:function(className,fixedWidth){
		var elements=$$('.'+className);
		var max_height=0;
		if(elements.length){
			for(var a=0;a<elements.length;a++){
				if(fixedWidth){
					elements[a].style.width=fixedWidth+'px';
				}
				if(elements[a].offsetHeight>max_height){
					max_height=elements[a].offsetHeight;
				}
			}
			for(var a=0;a<elements.length;a++){
				elements[a].style.height=max_height+'px';
			}
		}
		return max_height;
	},

    BuildRoundedCornerObjects:function(){
        var as = this.getElementsByClassName('roundedcorners(.*)');
        for (var i=0; i<as.length; i++) {
        	rbc=as[i].className.split("_");
        	gfpath=PageInfo.GFXPath + 'ver2/borders/'+rbc[1]+'/';
			as[i].innerHTML='<div style="padding:0px;background: url('+gfpath+'dot.png) 100% 0 repeat-x"><div style="padding:0px;background: url('+gfpath+'dot.png) 0 100% repeat-x"><div style="padding:0px;background: url('+gfpath+'dot.png) 0 0 repeat-y"><div style="background: url('+gfpath+'dot.png) 100% 0 repeat-y"><div style="background: url('+gfpath+'bl.png) 0 100% no-repeat"><div style="background: url('+gfpath+'br.png) 100% 100% no-repeat"><div style="background: url('+gfpath+'tl.png) 0 0 no-repeat"><div style="background: url('+gfpath+'tr.png) 100% 0 no-repeat; padding:10px;">'+as[i].innerHTML+'</div></div></div></div></div></div></div></div>';
			if(Common.Browser.ie6d()){
				as[i].innerHTML+='<div style="clear:both;"></div>';
			}
		}
    },
    BuildTopMenuElements:function(){
    	return;
		var el=UI.getElementsByClassName('header_menu_selected')
		for(var a=0;a<el.length;a++){
			if(Common.Browser.ie7d() && PageInfo.boolRTL){
				el[a].style.backgroundColor='#59A910';
			} else {
				el[a].style.backgroundColor='#ffffff';
				el[a].innerHTML='<div class="dl"></div><div class="dc">'+el[a].innerHTML+'</div><div class="dr"></div>';
			}
		}
    },
	OL:{
		Initialized:0,
		Init:function(){
			var overDiv=document.createElement("DIV");
			document.createElement("DIV");
			overDiv.innerHTML="&nbsp;";
			document.body.appendChild(overDiv);
			overDiv.id="overDiv";
			$('overDiv').style.display='none';
			$('overDiv').style.backgroundColor="#ffffcc";
			$('overDiv').style.zIndex=100;
			this.Initialized=1;
		},
		S:function(objParams){
			if(!this.Initialized){
				this.Init();
			}
			if(objParams.Decode64){
				objParams.Text=Base64.decode(objParams.Text);
			}
			if(!this.OverLIBInitialized){
				this.OverLIBInitialized=1
			}
			if(objParams.Text==''){
				return;
			}
			var xs = viewportwidth;
			$('overDiv').style.display='';
			$('overDiv').innerHTML=objParams.Text;
			var x = med_posx+10;
			var y = med_posy+20;
			if(PageInfo.boolRTL){
				//if (navigator.userAgent.toLowerCase().indexOf('chrome',0) == -1) {
					$('overDiv').style.left=(x-250)+'px';
				/*}
				else {
					$('overDiv').style.left=x+'px';
				}*/
				$('overDiv').style.top=y+'px';
			} else {
				if($('overDiv').offsetWidth + x>viewportwidth) {
					$('overDiv').style.left = 'auto';
					$('overDiv').style.right=x+'px';
				} else {
					$('overDiv').style.left=x+'px';
				}
				$('overDiv').style.top=y+'px';
			}
		},
		H:function(){
			$('overDiv').style.display='none';
		}
	},
	OpenedSubMenu:'',
	AddSubMenu:function(objParams){
		var objTarget	=	objParams.Parent
		var objMenu		=	objParams.subMenu
		if(objParams.MenuGroup){
			objTarget.MenuGroup=objParams.MenuGroup;
		}
		if(objParams.TargetParentMouseOutClass){
			objTarget.parentNode.className=objParams.TargetParentMouseOutClass;
		}
		objMenu.Twin=objTarget;
		objMenu.style.zIndex=10;
		if(objParams.MenuRebuildFunction){
			eval(objParams.MenuRebuildFunction);
		}
		if(objParams.AddHoverDiv){
			objTarget.HoverDiv=document.createElement("DIV");
			objTarget.HoverDiv.style.position='absolute';
			objTarget.HoverDiv.style.display='none';
			objTarget.HoverDiv.style.height=objTarget.offsetHeight+'px';
			objTarget.HoverDiv.style.width=objTarget.offsetWidth+'px';
			objTarget.HoverDiv.style.left=objMenu.offsetLeft+20+'px';
			objTarget.HoverDiv.style.top=objMenu.offsetTop+'px';
			objTarget.HoverDiv.style.zIndex=1;
			objTarget.HoverDiv.innerHTML=objTarget.innerHTML;
			objTarget.HoverDiv.className=objParams.HoverDivClass;
			document.body.appendChild(objTarget.HoverDiv);

		}
		if(objParams.TargetMouseOutClass){
			objTarget.className=objParams.TargetMouseOutClass;
		}
		if(!objMenu.hide){
			objMenu.hide=function(){this.style.display='none';}
			objMenu.show=function(){this.style.display='';}
			objTarget.hide=function(){this.style.display='none';}
			objTarget.show=function(){this.style.display='';}
		}
		objTarget.mouseOutTimer=null;
		if(objParams.setLeft){
			switch(objParams.setLeft){
				case 'afterobject':
					objMenu.style.left=objMenu.offsetLeft+objTarget.offsetWidth+'px';
//					objMenu.style.position='relative';
//					objMenu.style.position='relative';
					break;
				case 'afterobjectMinusMenuWidth':
					objMenu.style.left=objMenu.offsetLeft+(279 - objTarget.offsetWidth) - objMenu.offsetWidth +'px';
					break;
				case 'beforeobject':
					objMenu.style.right=objTarget.offsetLeft;
					//objMenu.style.left=objTarget.offsetLeft-objMenu.offsetWidth+'px';
					break;
				case 'afterobject':
					objMenu.style.left=objTarget.offsetLeft+objMenu.offsetWidth+'px';
					break;
				default:
					objMenu.style.left=objMenu.offsetLeft+objParams.setLeft+'px';
			}
		}
		objMenu.hide();
		objTarget.onmouseover=function(){
			if(objParams.MenuGroup){
				if(document.Menus[objParams.MenuGroup] && document.Menus[objParams.MenuGroup]!=objTarget){
					document.Menus[objParams.MenuGroup].hideMenu();
				}
			}
			document.Menus[objParams.MenuGroup]=objTarget;

			if(UI.OpenedSubMenu){
				UI.OpenedSubMenu.style.display='none';
			}
			if(objTarget.mouseOutTimer){
				clearInterval(objTarget.mouseOutTimer);
				objTarget.mouseOutTimer=null;
			}
			UI.OpenedSubMenu=objMenu;
			objMenu.show();
			if(objParams.TargetMouseOverClass){
				objTarget.className=objParams.TargetMouseOverClass;
			}
			if(objParams.TargetParentMouseOverClass){
				objTarget.parentNode.className=objParams.TargetParentMouseOverClass;
			}
			if(objParams.ParentOnShow){
				objParams.ParentOnShow();
			}
			if(objParams.TargetParentMouseOutClass){
				objTarget.parentNode.onmouseover=objTarget.onmouseover;
			}
		}
		objMenu.onmouseover=objTarget.onmouseover;
		objTarget.hideMenu=function(){
			if(objTarget.HoverDiv){
				objTarget.HoverDiv.style.display='none';
			}
			if(objParams.TargetMouseOutClass){
				objTarget.className=objParams.TargetMouseOutClass;
			}
			if(objParams.TargetParentMouseOutClass){
				objTarget.parentNode.className=objParams.TargetParentMouseOutClass;
			}
			if(objParams.ParentOnHide){
				objParams.ParentOnHide();
			}
			if(objTarget.mouseOutTimer){
				clearInterval($(objTarget).mouseOutTimer);
				objTarget.mouseOutTimer=null;
			}
			if(objParams.TargetParentMouseOutClass){
				objTarget.parentNode.onmouseover=function(){};
			}
			objMenu.hide();
		}
		objTarget.onmouseout=function(){
			objTarget.mouseOutTimer=setInterval("$('"+objTarget.id+"').hideMenu()",300);
		}
		objMenu.onmouseout=objTarget.onmouseout;
	},
	AddSubMenus:function(objParams){
		if(objParams.AutoMenuList){
			var MenuList=new Array();
			for(var a=objParams.AutoMenuList.FirstIndex-1;a<objParams.AutoMenuList.LastIndex-1;a++){
				MenuList[a]=[$(objParams.AutoMenuList.ParentPrefix+(a+1))];
			}
		} else {
			var MenuList=objParams.MenuList;
		}
		objParams.MenuList='';
		for(var a=0;a<MenuList.length;a++){
//			if(!MenuList[a][0]){
//				continue;
//			}
			objParams.Parent=MenuList[a][0];
			if(objParams.TargetParentMouseOutClass){
				var p=objParams.Parent.parentNode.parentNode;
			} else {
				var p=objParams.Parent.parentNode;
			}
			if(objParams.AutoCreateSubMenu){
				objParams.subMenu=document.createElement("DIV");
				objParams.subMenu.id="sm"+MenuList[a][0].id;
				if(objParams.useSubMenuParent){
					objParams.subMenuParent=document.createElement("DIV");
					objParams.subMenuParent.appendChild(objParams.subMenu);
				} else {
					objParams.subMenuParent=objParams.subMenu;
				}
				if(objParams.SubMenuStyle){
					objParams.SubMenuStyle(objParams.subMenu);
				}
				if(objParams.TargetParentMouseOutClass){
					p.insertBefore(objParams.subMenuParent,objParams.Parent.parentNode);
				} else {

					//p.insertBefore(objParams.subMenuParent,objParams.Parent.nextSibling);
					p.insertBefore(objParams.subMenu,objParams.Parent);
				}
				if(objParams.ElementsStylingFunction){
					objParams.ElementsStylingFunction(p,objParams.Parent,objParams.subMenuParent,objParams.subMenu);
				}
			} else {
				objParams.subMenu=MenuList[a][1];
			}

			this.AddSubMenu(objParams);
		}
	},
	Hider:{
		Init:function() {
			if(!document.UIHider) {
				document.UIHider=document.createElement("DIV");
				document.UIHider.style.display='none';
				document.UIHider.style.position='fixed';
				document.UIHider.style.top='0';
				document.UIHider.style.left='0';
				document.UIHider.style.width='100%';
				document.UIHider.style.height=document.body.scrollHeight+'px';
				document.UIHider.style.backgroundColor='#000000';
				document.UIHider.style.filter='Alpha(Opacity=60)';
				document.UIHider.style.MozOpacity=0.6;
				document.UIHider.style.opacity=0.6;
				document.body.appendChild(document.UIHider);
			}
		},
		Show:function(zIndex) {
			this.Init();
			if(!zIndex) {
				zIndex = 1000;
			}
			document.UIHider.style.zIndex=zIndex
			document.UIHider.style.display='';
		},
		Hide:function(zIndex) {
			this.Init();
			document.UIHider.style.display='none';
		},
		Set:function () {
			this.Init();
			return document.UIHider;
		}
	},
	LoadingNote:{
		Init:function () {
			if(!document.LoadingNote) {
				document.LoadingNote=document.createElement("DIV");
				document.LoadingNote.style.display='none';
				document.LoadingNote.style.color = "#ffffff";
				document.LoadingNote.style.zIndex='1500';
				document.LoadingNote.style.position='fixed';
				document.LoadingNote.style.top=viewportheight/2+'px';
				document.LoadingNote.style.left=(viewportwidth-128)/2+'px';
				document.body.appendChild(document.LoadingNote);
				document.LoadingNote.Position = this.Position;
				UI.addEvent(window,'resize', function() { UI.LoadingNote.Position();} );
				
			}
		},
		Position:function() {
			this.Init();
			document.LoadingNote.style.top=viewportheight/2+'px';
			document.LoadingNote.style.left=(viewportwidth-128)/2+'px';
		},
		Show:function(text) {
			this.Init();
			UI.Hider.Show(document.LoadingNote.style.zIndex - 1)
			document.LoadingNote.style.display='';
			document.LoadingNote.innerHTML = text+'<img src="/gfx/processing.gif" width="128px" height="15px" align="middle" />';
		},
		Hide:function(zIndex) {
			this.Init();
			document.UIHider.style.display='none';
		}
	}
});
function insertAfter(parent, node, referenceNode) {
  parent.insertBefore(node, referenceNode.nextSibling);
}

JSLoader={
	Cache:[],
	Load:function(ObjectId){
		if(typeof(ObjectId) == 'object'){
			this._object = ObjectId;
			ObjectId = this._object.id;
			var params = Base64.encode(Object.toJSON(this._object));
		} else {
			var params = "";
		}
		if(JSLoader.Cache[ObjectId]){
			eval(JSLoader.Cache[ObjectId]);
		} else {
			new Ajax.Request ("/ajax.interface.php",
			{
				method: "post",
				parameters: 'thread=ObjectLoader&ObjectId='+ObjectId+'&params='+params,
				onSuccess: function (res) {
					JSLoader.Cache[ObjectId]=res.responseText;
					eval(JSLoader.Cache[ObjectId]);
				}
			}
			);
		}
	}
}
if(typeof popupObj == 'undefined') {
	var popupObj = {
		MasterObject:1,
		discard_hider: 0,
		Container : '',
		Title : '',
		Content : '',
		Hider :	'',
		setLeft:function (x){
			this.Container.style.left=x;
		},
		Init:function(){
			if(this.MasterObject==0){
				if(!document.UIHider){
					document.UIHider=document.createElement("DIV");
					document.UIHider.style.display='none';
					document.UIHider.style.position='fixed';
					document.UIHider.style.top='0';
					document.UIHider.style.left='0';
					document.UIHider.style.width='100%';
					document.UIHider.style.height='100%';
					document.UIHider.style.backgroundColor='#000000';
					document.UIHider.style.backgroundColor='#000000';
					document.UIHider.style.filter='Alpha(Opacity=60)';
					document.UIHider.style.MozOpacity=0.6;
					document.UIHider.style.opacity=0.6;
					document.body.appendChild(document.UIHider);
					this.Hider = this.hider=document.UIHider;
					Common.Extend(this.hider)
				}
				this.hider=document.UIHider;
				this.Container=document.createElement("DIV");
				this.Container.style.display='none';
				this.Container.style.position='absolute';
				this.Container.style.width='auto';
				this.Container.style.zIndex=5000;
				this.Container.style.backgroundColor='#eeeeee';
				this.Container.style.borderColor='#000000';
				this.Container.style.borderStyle='solid';
				this.Container.style.borderWidth='1px';
				//Create The Title Object
				this.Container.TitleContainer=document.createElement("DIV");
				this.Container.TitleContainer.style.padding='10px';
				this.Container.TitleContainer.style.backgroundColor='#3EA7E9';
				this.Container.TitleContainer.parent=this.Container;
				this.Container.TitleContainer.onmousedown=function(){
					document.draggedObject=this.parent;
					document.dragging = 1;
				}
				this.Container.TitleContainer.onmouseup=function(){
					document.dragging = 0;
				}
	
				this.Container.CloseBtn=document.createElement("DIV");
				this.Container.CloseBtn.style.display='inline';
				this.Container.CloseBtn.CloseImage=document.createElement("IMG");
				this.Container.CloseBtn.CloseImage.style.cursor='pointer';
				this.Container.CloseBtn.CloseImage.src=PageInfo.GFXPath + 'ico_close.gif';
				this.Container.CloseBtn.CloseImage.Parent=this;
				this.Container.CloseBtn.CloseImage.onclick=function(){
					this.Parent.Close();
				}
				this.Container.CloseBtn.appendChild(this.Container.CloseBtn.CloseImage);
	
				this.Container.Title=document.createElement("DIV");
				this.Container.Title.style.display='inline';
				this.Container.Title.style.fontSize='14px';
				this.Container.Title.style.fontWeight='bold';
				this.Container.Title.style.color='#ffffff';
				this.Container.Title.style.padding='10px';
				this.Container.Title.style.textAlign=PageInfo.boolRTL?'right':'left';
				this.Container.Title.align=PageInfo.boolRTL?'right':'left';
				this.Container.TitleContainer.style.textAlign=PageInfo.boolRTL?'right':'left';
				this.Container.TitleContainer.appendChild(this.Container.CloseBtn);
				this.Container.TitleContainer.appendChild(this.Container.Title);
				this.Container.appendChild(this.Container.TitleContainer);
				//Create The Body Object
				this.Container.Content=document.createElement("DIV");
				//this.Container.Content.style.backgroundColor='#00ff00';
				this.Container.Content.style.padding='10px';
				this.Container.Content.style.width='auto';
				this.Container.Content.style.textAlign=PageInfo.boolRTL?'right':'left';;
				this.Container.appendChild(this.Container.Content);
				Common.Extend(this.Container.TitleContainer);
				Common.Extend(this.Container.Content);
				Common.Extend(this.Container.Title);
				Common.Extend(this.Container);
				//document.getElementById('page').insertBefore(this.Container)
				document.body.appendChild(this.Container);
			}
		},
		UpdateContent: function (content){
			$(this.content).update(content);
		},
		GetContent:function(){
			return $(this.content).innerHTML;
		},
		Reopen:function(title,content){
			this.Open(title,content);
		},
		HideCloseBtn:function(){
			this.Container.CloseBtn.style.display='none';
		},
		open: function (title,content,no_close, content_id){
			this.Open(title,content,no_close, content_id);
		},
		Open : function (title,content,no_close, content_id){
			if(no_close){
				this.Container.CloseBtn.style.display='none';
			}
			if(title) this.Container.Title.update(title);
			if(title==''){
				document.UIHider.currentPopup=this;
				document.UIHider.onclick=function(){document.UIHider.currentPopup.Close();document.UIHider.onclick=function(){};};
				this.Container.TitleContainer.style.display='none';
			} else {
				this.Container.TitleContainer.style.display='';
			}
			if(content) this.Container.Content.update(content);
			if($(content_id)) {
				this.Container.Content.update($(content_id).innerHTML);
			}
			this._title= this.Container.Title.innerHTML;
			this._content= this.Container.Content.innerHTML;
	
			if(!this.discard_hider){
				this.hider.style.zIndex=this.Container.style.zIndex-1
				this.hider.height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight;
				this.hider.style.height=document.body.offsetHeight>this.hider.height?document.body.offsetHeight:this.hider.height + 'px';
				this.hider.show();
			}
			this.Container.show();
			var q=this.Container.Content.offsetWidth;
			if(q<300){
				this.Container.style.width	= '320px';
			}
			var m=this.Container.offsetWidth;
			var h=this.Container.offsetHeight;
			var h2=document.body.scrollTop+(window.screen.height-h)/2;
			this.Container.style.top=(h2<0?0:h2)+'px';
			this.Container.style.left=((document.body.scrollWidth-m)/2)+'px';
			//this.Container.TitleContainer.style.width=this.Container.Content.offsetWidth;
			/**/
		},
		resetwidth :function (w){
			this.Container.style.width = w+'px';
		},
		setTop :function (w){
			this.Container.style.top = w+'px';
		},
		close: function (){
			this.Close();
		},
		Close : function (){
			this.Container.Title.update('');
			this.Container.Content.update('');
			this.hider.hide();
			this.Container.hide();
			this.Container.style.width='auto';
			if(this.onClose) {
				this.onClose();
			}
		},
		SetTitleBackground:function (TitleColor){
			this.Container.TitleContainer.style.backgroundColor=TitleColor;
		},
		Clone:function(TitleColor){
			var new_popup = Common.Clone(this);
			new_popup.Clone='';
			new_popup.MasterObject=0;
			new_popup.Init();
			new_popup.Init='';
			if(TitleColor){
				if( TitleColor.indexOf('#')==-1){
					TitleColor='#'+Math.ceil(Math.random()*128).toString(16)+Math.ceil(Math.random()*128).toString(16)+Math.ceil(Math.random()*128).toString(16);
					new_popup.Container.TitleContainer.style.backgroundColor=TitleColor;
				} else {
					new_popup.Container.TitleContainer.style.backgroundColor=TitleColor;
				}
			}
			return new_popup;
		}
	}
}
var Browse={
	Cache:[],MenuConfig:null,
	RebuildMenusData:function(strMenusDataConfig,UniqueParam){
		//alert(strMenusDataConfig);
		this.GetBrowseData('BuildMenuData',"[\""+strMenusDataConfig+"\","+$F('ItemType')+","+$F('ViewType2')+",\""+UniqueParam+"\"]",function(res){
			for(var a=0;a<res.length;a++){
				$(res[a].id).update(res[a].data);
				Browse.BuildRatedDevicesMenu($(res[a].id));
			}
			//Browse.LoadDevicesDescriptions();
		},1);
	},
	GetBrowseData:function(action,params,onsuccess,nocache){
		if(Browse.Cache[action+params]){
			onsuccess(Browse.Cache[action+params]);
		} else {
			var Request='thread=browse&action='+action+'&JsonParams='+params;
			//alert(Request);
			new Ajax.Request ("/ajax.interface.php",
			{
				method: "post",
				parameters: Request,
				onSuccess: function (res) {
					var x=eval(res.responseText);
					if(!nocache){
						Browse.Cache[action+params]=x
					}
					onsuccess(x);
				}
			}
			);
		}
	},
	BuildRatedDevicesMenu:function(obj){
		var st='';
		obj.innerHTML='<div class="rd"><img onclick="this.parentNode.parentNode.Twin.hideMenu()" /><br clear="all" />'+obj.innerHTML+'</div>';
	}
};

var QuickSearch= {
	ErrorMessage:'Please enter a search keyword, or click "Advanced Search"',
	DefaultText:'Quick Search',
	checkSearch_new:function () {
		var add = "";
		if($F('head_search_word').length < 2 || $('head_search_word').value == Common.Texts.QuickSearch) {
			alert (this.ErrorMessage);
			return false;
		}
		$('search_form_div').hide();
		if($('searchin_animate')) {
			$('searchin_animate').show();
		}
		$('quick_search_animation_div').toggle();
		$('quick_search_div').toggle();
		if($('QSType').value=="leads") {
			add = "&type=BUYING";
		}
		var q =  encodeURIComponent($F('head_search_word'));
		location.href = '/tag/fronthandler/browse?actions='+$('QSType').value + add+'&searchstring=' + q;
	},
	checkSearch:function () {
			if($F('head_search_word').length < 2 || $('head_search_word').value == Common.Texts.QuickSearch) {
				alert (this.ErrorMessage);
				return false;
			}
			$('search_form_div').hide();
			if($('searchin_animate')) { $('searchin_animate').show(); }
			var x=0;
			var link;
			var arr=new Array();
			if($('ViewType').value==1) {
				link='used-medical-equipments';
			} else {
				link='wanted-medical-equipments';
			}
			arr[x++]='searchstring='+$F('head_search_word');
			//arr[x++]='first_shot=1';
			$('quick_search_animation_div').toggle();
			$('quick_search_div').toggle();
			location.href ='/'+link+'?' +arr.join("&");
	}
	
};



var Members={
	Thread:'Members',
	Login:function(){
		alert(1);
	},
	isLoggedIn:function(onSuccess,onFailure){
		var arrParams=new Array();
		arrParams[0]="thread="+this.Thread;
		arrParams[1]="actions=isLoggedIn";
		Common.HttpGet(arrParams,function(res){
			if(res=='1'){
				if(onSuccess){
					onSuccess();
				}
			} else {
				if(onFailure){
					onFailure();
				}
			}
		});
	}
}


UI.addEvent(window,'resize', function() { document.ViewPort();} );


var Locations={
	Cache:[],
	getRegions:function(Params){
		var arrParams=new Array();
		arrParams[0]="thread=Location";
		arrParams[1]="actions=getRegions";
		arrParams[2]="Params="+Object.toJSON(Params);
		var req=Base64.encode(Object.toJSON(Params));
		if(Locations.Cache[req]){
			Params.onSuccess(Locations.Cache[req]);
		} else {
			Common.HttpGet(arrParams,function(res){
				Locations.Cache[req]=res;
				Params.onSuccess(res);
			});
		}
	}
}
Object.extend(Locations,{
	getRegionsCompaniesDirectory:function(intCountryId){
		this.getRegions({
			firstvalue: '',
			firstname: 'Select',
			CountryId:intCountryId,
			ObjectName:'region_id',
			onSuccess:function(res){
				eval(res);
				if(results.Count>0){
					$('div_region_id').update(results.SelectObject);
					$('div_region_title').update("&nbsp;&nbsp;&nbsp;"+results.RegionsTitle);
					$('div_region_name').show();
				} else {
					$('div_region_id').update("");
					$('div_region_title').update("");
					$('div_region_name').hide();
				}
			}
		});
	}
});

/*var CompaniesDirectory = {
	Viewer: popup,
	Filters:[],
	GetDetailsPage: function(intPageNumber){
		this.GetDetails(this.MessageId,intPageNumber);
	},
	AddFilter: function(strFilterName,strValue){
		this.Filters[this.Filters.length]='"'+strFilterName+'":'+'"'+strValue+'"';
	},
	BuildFiltersObject: function(){
		this.Filters=[],
		this.AddFilter('directory',$F('directory'));
		return '{'+this.Filters.join(",")+'}';
	},
	getServiceArea: function(id) {
		this.Viewer.open("Service Area","Loading");
		new Ajax.Updater($(this.Viewer.content),'?actions=getServiceArea&id='+id);
		this.Viewer.resetwidth(300);
		this.Viewer.Reopen();
		//this.Viewer.setTop(document.body.scrollTop);
	}
}*/

var firstError=0;
var CompaniesDirectory = {
	
	Viewer: Common.GetViewer(),
	
	popup: function(title, data, width) {
		if(!width) {
			width = 300;
		}
		this.Viewer.Open(title, Base64.decode(data));
		this.Viewer.resetwidth(width);
		this.Viewer.Reopen();
	},
	
	
	getServiceArea: function(data) {
		this.Viewer.Open("Service Area", Base64.decode(data));
		this.Viewer.resetwidth(300);
		this.Viewer.Reopen();
	},
	
	ExtraValidationFunction:function(){return true;},
	Validate:function(){
		firstError=0
		var v = true;
		if($('country_type2').checked) {
			v = (arrLocationCounter['regions[]'] > 0 || arrLocationCounter['countries[]'] > 0 || arrLocationCounter['continents[]'] > 0);
			if(!v) {
				$('countries_error').show();
			} else {
				$('countries_error').hide();
			}
		}
		
v=fnCheckVal('firstname','length','1','First Name','firstname') && v;

v=fnCheckVal('lastname','length','1','Last Name','lastname') && v;

v=fnCheckVal('company_name','length','1','Company','company_name') && v;

v=fnCheckVal('country_id','length','1','Country','country_id') && v;

v=fnCheckVal('company_website','isUrl','','Website','company_website') && v;

v=fnCheckVal('email','isMail','','Email','email') && v;

v=fnCheckVal('country_code_telephone','length','1','Telephone','telephone') && v;

v=fnCheckVal('telephone','length','1','Telephone','telephone') && v;

if(fnCheckVal2('is_benefits','=','2'))
{
	v = fnCheckVal('benefits','length','1','Telephone','benefits') && v;
}		v = this.ExtraValidationFunction() && v;
		if(!v) {
			if(firstError){				
				if(firstError.style.display=='none'){
					firstError.style.display='';
					firstError.focus();
					firstError.style.display='none';
				} else {
					firstError.focus();
				}				
			}	
		}
		return v;
	},
	
	Validate2 : function() {
		// if(document.companies_directory_form.link_to_url.value) { document.getElementById('error_link_to_url').style.display = 'none'; document.companies_directory_form.submit(); } else { document.getElementById('error_link_to_url').style.display = 'block'; } 
		var v=true;
		
v=fnCheckVal('link_to_url','isUrl','','Link','link_to_url') && v;
		
		
		if(v) { 
			$('companies_directory_form').submit(); 
		}
		return v;
	},
	
	certificationUploadPictures: function() {
		this.addElement = function(element) {
			element.onchange = function(){
				if(element.type == 'file') {
					document.getElementById('div_certification_pictures').style.display='block';
					document.getElementById('validate_images').value='1';
				}
			};
		};
	},
	deleteImage: function(image_id,temp_id){
		var url = 'companies_directory_ajax_handler.php?NODC=f0a04cfcb9a4b4d745bf22038308fb95&action=deleteImage&image_id='+image_id+'&temp_id='+temp_id;
		new Ajax.Request(url, {
				method: 'get',
				onSuccess: function(transport){
					document.getElementById(image_id + "_v").innerHTML='';
					document.getElementById(image_id + "_d").innerHTML='';
					
				},
				onComplete: function() {
					// show the file input element
					$('file').show();
				}
			}
		);		
	},
	displayObjectIf: function(objectHandeled,values){
		if(objectHandeled){
			if(objectHandeled=document.getElementById(objectHandeled)){
				if(values) {
					objectHandeled.style.display='';
				} else {
					objectHandeled.style.display='none';
				}
			}
		}
	}
	

}
