//new ajac function in conjection with prototype.js
function ajaxNewChangeTown()
{
	var arg=ajaxNewChangeTown.arguments;
	var url = docRoot+'inc/ajax_feed.php';

	//var params = 'region=' + $F('region'); //you can use this line, if you know the id of the element
	// you can add as many arguments u want but the argument order must be same. by joshi
	var params = 'region=' + arg[0] + '&from=' + arg[1]+ '&next_div='+ arg[2];
	//alert( params);
	//arg[2] is the div name where the result to be populated
	var ajax = new Ajax.Updater({success: arg[2]},url,{method: 'get', parameters: params, onFailure: reportError});

}
//error reporting of prototype.js
function reportError(request) {
	$F('div_town') = "Error"; //displays the error in the give div id
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function destroycatfish()
{
	var catfish = document.getElementById('catfish');
	document.body.removeChild(catfish); /* clip catfish off the tree */
	document.getElementsByTagName('html')[0].style.padding= '0'; /* reset the padding at the bottom */
	return false;
}
function closeme()
{
	var closelink = document.getElementById('closeme');
	closelink.onclick = destroycatfish;

}

document.getElementsByClassName = function(class_name) {
    var docList = this.all || this.getElementsByTagName('*');
    var matchArray = new Array();

    /*Create a regular expression object for class*/
    var re1 = new RegExp("\\b"+class_name+"\\b");

    /*Create regular expression to handle dashes in class name*/
    var re2 = new RegExp("[\S]"+class_name+"|"+class_name+"[\S]");

    for (var i = 0; i < docList.length; i++) {
        if (re1.test(docList[i].className) && !re2.test(docList[i].className) ) {
            matchArray[matchArray.length] = docList[i].id;
        }
    }
    return matchArray;
}//eof annonymous function

function show(x)
{
	if(document.getElementById(x))
		document.getElementById(x).style.display="block";
}
function hide(x)
{
	if(document.getElementById(x))
		document.getElementById(x).style.display="none";
}

menu_table = new Array ('about_list_id','advertise_list_id','partners_list_id','hotels_list_id','maps_list_id','entertainment_list_id','schools_list_id','banks_list_id');
function show_hide(x)
{
/*
	if (menu_table[x] == null)
		menu_table[menu_table.length] = x;
	for(i=0; i<menu_table.length; i++)
		if(menu_table[i] != x)
			hide(menu_table[i]);
*/
	if(document.getElementById(x))
		if(document.getElementById(x).style.display != 'block')
			document.getElementById(x).style.display="block";
		else
			document.getElementById(x).style.display="none";
}
//function show_hide_id(x)
function show_hide_menu(x, obj)
{
	divArray = new Array("about_list_id","partners_list_id","account_list_id","cyprus_list_id");
	divArrayLen = divArray.length;
	for(i=0;i<divArrayLen;i++)
	{
		document.getElementById(divArray[i]).style.display="none";
	}
	if(document.getElementById(x).style.display == 'none')
	{
		document.getElementById(x).style.display="block";
		obj.style.background='url('+docRoot+'inc/images/more-small-blue.gif) top right no-repeat';
	}
	else
	{
		document.getElementById(x).style.display="none";
		obj.style.background='url('+docRoot+'inc/images/arrow-right.jpg) right no-repeat';
	}
}

// moved open_popup to frame js
function open_popup_scrollable(filename, h, w,extra)
{
	if(!w) w = 498;
	if(!h) h = 450;
	if(!extra)
		extra = ",resizable=no,scrollbars=no,status=yes";
	
	flyout = window.open(filename,"flyout", "height="+h+",width="+w+extra);
	if(flyout)
		flyout.focus();
}

var fontSize=11;
function setFont()
{
	var CookieFontSize=getCookieValue("cook_font_size");
	if(CookieFontSize)
	{
		fontSize = CookieFontSize;
		obj2 = document.getElementById("preview");
		if(obj2)
			obj2.style.fontSize = fontSize+"px";
	}
}

function FontLarger()
{
	fontSize++;
	obj2 = document.getElementById("preview");
	if(obj2)
	{
		obj2.style.fontSize = fontSize+"px";
		writeCookie ('cook_font_size', fontSize);
	}
}
function FontSmaller()
{
	fontSize--;
	obj2 = document.getElementById("preview");
	if(obj2)
	{
		obj2.style.fontSize = fontSize+"px";
		writeCookie ('cook_font_size', fontSize);
	}
}

function addToFavorite()
{ 
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
	{ 
		window.sidebar.addPanel (prj_website_title, docRoot,""); 
	} 
	if (document.all) window.external.AddFavorite(docRoot,prj_website_title);
}

function show_trim_str(iStr, showlength){
	if(iStr.length > 0){
		output = ""; 
		output = iStr.substr(0,showlength); 
		if( iStr.length > showlength){ 
			output = output + "...";
		}
		return output;
	}else{
		return "";
	}
}
function currencyFormat(fld, milSep,  e) {
	decSep = "";
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep))
			break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		
	aux += key;
	len = aux.length;

	if (len == 0) fld.value = '';
	if (len > 0) {
		aux2 = '';
		for (j = 0, i = len-1; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
	}
	return false;
}

function load_opener_href(path, focus_on_parent)
{
	try {
		if(window.opener.location.href)
			if (typeof path == "undefined") 
				window.opener.location.href = window.opener.location;
			else
				window.opener.location.href = path;
		if (typeof focus_on_parent != "undefined") 
		{
			window.opener.focus();
		}
	}
	catch(oException) {
		if (typeof path == "undefined") 
		{
			//window.location.href = docRoot;
		}
		else
		{
			window.location.href = path;
		}
	}
}

function writeCookie (CookieName, CookieValue) {
	offset = 30;//30 days 
	writeCookieDetail (CookieName, CookieValue, "Persistent", offset) 
}

function writeCookieDetail (CookieName, CookieValue, CookieType, offset) {
	var expireDate = new Date ();
	//offset = offset / 1;
	
	if(CookieType == "Session")
	{
		document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		return true;
	}
	else
	{
		expireDate.setDate(expireDate.getDate()+offset);
		document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
	}
}

function getCookieValue (cookieName) {
	var exp = new RegExp (escape(cookieName) + "=([^;]+)");
	if (exp.test (document.cookie + ";")) {
		exp.exec (document.cookie + ";");
		return unescape(RegExp.$1);
	}
	else return false;
}

function deleteCookie (cookieName) {

	if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
		return true;     
}

//to disable all other selections in advanced search, if project 'Any' is selected 
function disable_rest(){
	var obj=document.search.elements['project[]'];
	var len=obj.length;
	var tot_mail=10;
	var count=0;

	for(i=0;i<len;i++){
		
		if(obj[i].selected && obj[i].value=="Any")
		{
			for(j=1;j<len;j++){
				obj[j].selected=false;
			}
			//alert("You cannot select Any and some other Project name in same search")
			break;		
		}
	}
}
