function toggleTextOut(e,txtval) {
	if(e.value=="") e.value = txtval;
	

}
function toggleTextIn(e,txtval) {
	if(e.value==txtval) e.value="";
	else e.select();
}
$(document).ready(function(){
						   
		toggleSubFooter();		   				   
		showToolTip();
		showSuggestion();
		selectField();
		selectInput();
		$.preloadImages("../images/nav-top-txt-discover.gif", "../images/nav-top-txt-discover-mo.gif", "../images/nav-top-explore.gif","../images/nav-top-explore-mo.gif","../images/nav-top-see.gif","../images/nav-top-see-mo.gif", "../images/nav-top-read.gif", "../images/nav-top-read-mo.gif");
		
		// removing suggest duplication
		$("html").bind("click",function(event){
				if($('#suggest').is(':visible')){					
			$("#suggest").slideUp("fast");
			event.stopPropagation();
				}
				event.stopPropagation();
		});

		$("a[@rel=external]").attr('target', '_blank');  
		$("a[@rel=external nofollow]").attr('target', '_blank');  
			hide_show_features();
		 articleSetup();
		 
		$(".addcommentlink").click(function() {$("a[@name=formcomments]").ScrollTo(800); return false; })
	  
 });

function toggleSubFooter(){
	
	var now_height;
	//alert($('body').height());
	$("a.toggle-btn").click(function(){
									 
	if($('#sub-footer').is(':visible'))
	{
		$('#sub-footer').hide('fast');
		$('#footer').animate({height:52},'fast',function(){
		$('#container').height($('#container').height()-170);
		});
		
	}
	else{
		$('#sub-footer').show('fast');
		$('#footer').animate({height:220},'slow',function(){
		$('#container').height($('#container').height()+170);
			scrollTo(0,$('body').height()+370);
		});
		
	}
										 
  $("a.toggle-btn").toggleClass("minimize");
  $("a.toggle-btn").toggleClass("maximize");
 
   return false;

 });
	
}
var gmoli = null;
function showToolTip(){
	$("#nav-top li").hover(function(){
		if($(this).prev().length > 0 && !$(this).is('.current') ) { //&& $(this).prev('.current').length <= 0
			$(this).css('background-image', 'none')
			$(this).prev().css('background-image', 'none');
		}
		$("h2 , .title, #related-img" ).css("z-index", "-1");	 //solving z-index problem in ie6	
		$("#main-footer h2.title" ).css("z-index", "0");
		
		var ttid= $(this).attr('id');
			$("#tt-"+ttid).show();
		
		/*$(this).children(".tooltip").animate({
  opacity: 'show'
}, "slow", "easein");*/
			//setTimeout("hideToolTip()",20000);
		
	},function(){
		if($(this).prev().length > 0 && !$(this).is('.current') ) { //&& $(this).prev('.current').length <= 0
			$(this).css('background-image', 'url(/cm-site/themes/fli-v1-en/images/bg-nav-seperator.gif)')
			$(this).prev().css('background-image', 'url(/cm-site/themes/fli-v1-en/images/bg-nav-seperator.gif)');
		}
		//$("h2 a.title").css("z-index", "0");
		$("h2 , .title, #related-img").not('#footer h2 , .title').css("z-index", "0");
		//$(this).children(".tooltip").hide("fast");
		//setTimeout("hideToolTip()",0);
		var ttid= $(this).attr('id');
			$("#tt-"+ttid).hide("fast");
	})
	

	return false;
	
}

/*function hideToolTip(){
	$("#nav-top li").find(".tooltip").each(function() {
		if($(this).is(":visible")) {
			$(this).hide();
			
		}
	});
}
*/


AJAX_URL = '/cm-site/assets/ajax-handler.php?ajax_request=1';
function showSuggestion(){
	if($('#txtSearch').length) {
		var CURRENCY_LIST_URL = AJAX_URL + '&procedure=get_site_search';
		$('#txtSearch').autocomplete(CURRENCY_LIST_URL, {maxItemsToShow: 10, autoFill: true, onItemSelect: function(li) {
			window.location = li.extra[0];
		}, formatItem: function(row, i, num) {
			return(row[2]+row[0]);
		}});
		
	}
}
function selectField(){
	$("#contactform input, #contactform textarea, #contactform select, #newsletterform input, #newsletterform textarea, #newsletterform select").click(function()
		{
			$(this).addClass('selected');
			$(this).parent().parent().addClass('rowselected');
		}
	)
	
	$("#contactform input, #contactform textarea, #contactform select, #newsletterform input, #newsletterform textarea, #newsletterform select").blur(function()
		{
			$(this).removeClass('selected');
			$(this).parent().parent().removeClass('rowselected');
		}
	)
	
	
}

function selectInput(){
	$("#contact input, #contact textarea").click(function()
		{
			$(this).addClass('selectinput');
		}
	)
	
	$("#contact input, #contact textarea").blur(function()
		{
			$(this).removeClass('selectinput');
		}
	)
	
	
}
// form validation
function validateOnSubmit() {
	var emailFilter=/^.+@.+\..{2,3}$/;
	$(".validationresponse:visible").hide();

	if (document.formdata.txtName.value == "") {
		document.formdata.txtName.focus();
		addResponse("txtName",'Your first name required');
		return false;

	}
	
	if (document.formdata.txtLName.value == "") {
		document.formdata.txtLName.focus();
		addResponse("txtLName",'Your last name required');
		return false;

	}
	if (document.formdata.txtEmail.value == "") {
		document.formdata.txtEmail.focus();
		addResponse("txtEmail",'Email address required');
		return false;
	}
	if (!(emailFilter.test(document.formdata.txtEmail.value))) {
	   document.formdata.txtEmail.focus();
	   addResponse("txtEmail",'Enter valid email address');
		return false;
	}
	
	if (document.formdata.txtMessage.value == "") {
		document.formdata.txtMessage.focus();
		addResponse("txtMessage",'Your message required','textarea');
		return false;

	}
	return true;
  }

  function isAlphaNumeric(e)
  {

	var unicode=e.charCode? e.charCode : e.keyCode

		if (unicode!=8 && unicode!=13 && unicode!=9){
		str=String.fromCharCode(unicode);
		var re = /^[a-z A-Z]+$/;
		 // validation fails if the input doesn't match the regular expression
	 if(!re.test(str))
		  {
		  	 return false;
		   }
		}
	   return true;
  }

  function addResponse(name,msg) {
	
  	$("[@name="+name+"]").next(".validationresponse").html(msg);
  	$("[@name="+name+"]").next(".validationresponse").show('slow');
  	return false;

  }
  function addResponseCustom(id,msg) {
  	$("#"+id).html(msg);
  		$("#"+id).show('slow');
  	return false;

  }
 	jQuery.preloadImages = function()
	{
		for(var i = 0; i<arguments.length; i++)
			{
			jQuery("<img>").attr("src", arguments[i]);
			}
	}

/*Email to friend*/
function ValidateDatamail(form,url){
	var emailFilter=/^.+@.+\..{2,3}$/;
	var yourname = document.frmEmail.yourname;
	var youremail = document.frmEmail.youremail;
	var friendname = document.frmEmail.friendname;
	var friendemail = document.frmEmail.friendemail;
	
	if(friendname.value==""){
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please enter your friend's name </span> ");
		friendname.focus();
		return(false);
	}
	if(friendemail.value==""){
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please enter your friend's email id</span> ");
		friendemail.focus();
		return(false);
	}
	if (!(emailFilter.test(friendemail.value))){
		friendemail.focus();
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please enter a valid email</span> ");
		return(false);
	}
	if(yourname.value==""){
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please enter your name </span> ");
		yourname.focus();
		return(false);
	}
	if(youremail.value==""){
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please Enter your email id </span> ");
		youremail.focus();
		return(false);
	}
	if(!(emailFilter.test(youremail.value))){
		youremail.focus();
		$("#message").html("<span style=\"color:red\">*Mandatory fields empty. Please Enter your valid email id </span> ");
		return(false);
	}
	sentEmail(url);
	return(false);
}

function sentEmail(url) {
	$.post(url, { 
		yourname: $("input[@name=yourname]").val(), youremail:$("input[@name=youremail]").val() ,
		friendname: $("input[@name=friendname]").val(),
		yourremarks: $("textarea[@name=yourremarks]").val(), friendemail:  $("input[@name=friendemail]").val(),
		eurl:  $("input[@name=eurl]").val(), page_title:  $("input[@name=page_title]").val(), ajax:  "1"
	},
	function(data){
		document.getElementById("ajxares-mail").innerHTML=data; 
	} 
	);
}
/*Check submit*/
function  checkSubmit(e,obj) {
	if(e.charCode==0) return true;
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode==13)  {
		$(obj.form).trigger("onsubmit");
	}
}
/*For the Image Gallery (Portfolio)*/
function showImage(obj){
	var smallImg = $(obj).children('img').eq(0);
	var img = new Image();
	img.onload = function() {
		$('#indicator').hide();
		$("img#image-viewer").fadeOut('slow', function() {
		$('img#image-viewer').attr('src', obj.href).attr('alt', smallImg.attr('alt')).attr('title', smallImg.attr('title'));
		$("img#image-viewer").fadeIn('slow');
	});
	}
	$('#indicator').show();
	img.src = obj.href;
	
}

function AllowOnly(e,type,allow_space)
{
	if (allow_space==null) allow_space=false; else allow_space=true;
	if(e.charCode==0) return true;
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode==13) return true;
	if(allow_space && unicode==32)
	return true;
	switch(type)
	{
		case 'NUM_ONLY':
		if(unicode < 48 || unicode > 57) return false; else return true;
		case 'MOBILE_NUM_ONLY':
		if(unicode < 39 || unicode > 57 ) return false; else return true;
		case 'ALPHA_ONLY':
		if(unicode <65 || unicode >90)
		if(!(unicode >= 97 && unicode <=122))
		return false;
		else
		return true;
		case 'ALPHA_NUM_ONLY':
		if(unicode >= 65 && unicode <= 90)
		return true;
		if(unicode >= 97 && unicode <= 120)
		return true;
		if(unicode >= 48 && unicode <= 57)
		return true;
		else
		return false;

	}
}
//showing and hiding features 

function hide_show_features() {
	
	$("#chm_features").find("li").each(function(i){
		
		var feature_id;
		$(this).click(function(){
				
			feature_id = $(this).attr("id");
			if($(".feature_shown").attr("id")!=feature_id+"-data")
			{
				
			//$(".feature_shown").hide('slow').removeClass("feature_shown");
			$(".feature_shown").hide().removeClass("feature_shown");
			//$("#"+feature_id+"-data").addClass("feature_shown").slideDown('slow');
			$("#"+feature_id+"-data").addClass("feature_shown").show();
			
				}	
			return false;
	});
	});

}
// increases the font and adjusts the article layout
function increaseFont(){
	// get the current value from the cookie
	var cv1 = readCookie("ihtuserdata");
	cookieValues = parseCookie(cv1);
	var currentFontSize = parseInt(cookieValues[0]);
	var newFontSize = currentFontSize + 1;
	if (newFontSize > 17){
		newFontSize = 17;
	}
	// save new value in the cookie
	var cv = "fontSize:" + newFontSize;
	createCookie("ihtuserdata",cv,7);

	// re-draw article
	obj = document.getElementById("content");
	obj.style.fontSize = newFontSize + "px";
}

// increases the font and adjusts the article layout
function decreaseFont(){
	// get the current value from the cookie
	var cv1 = readCookie("ihtuserdata");
	cookieValues = parseCookie(cv1);
	var currentFontSize = parseInt(cookieValues[0]);
	var newFontSize = currentFontSize - 1;
	if (newFontSize < 10){
		newFontSize = 10;
	}
	// save new value in the cookie
	var cv = "fontSize:" + newFontSize;
	createCookie("ihtuserdata",cv,7);
	// re-draw article
	obj = document.getElementById("content");
	obj.style.fontSize = newFontSize + "px";
}

function articleSetup(){
	// get the fontSize value from the cookie
	var cv1 = readCookie("ihtuserdata");
	cookieValues = parseCookie(cv1);
	var fontSize = cookieValues[0];
	var parentDiv = document.getElementById("content");
	if(parentDiv) {
	parentDiv.style.fontSize = fontSize + "px";
	}
}

function initArticle(){
	if (document.getElementById("content") != null){
		articleSetup();
	}
}


// scroll

jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};

jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

// creates a cookie with the given parameters
function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

// locates and reads the value of a cookie with a specified name
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// deletes a cookie with a specified name
function eraseCookie(name){
	createCookie(name,"",-1);
}
function parseCookie(cookievalues){
	if (cookieValues.length > 0){
		var cookieValuesArray = new Array(3);
		var CookiesArray = cookievalues.split("&");
		for (var i = 0; i < CookiesArray.length; i++){
			var v = CookiesArray[i].split(":");
			cookieValuesArray[i] = v[1];
		}
		return cookieValuesArray;
	} else {
		return null;
	}
}

var cookieValues = new Array(3);
var cv = readCookie("ihtuserdata");
if (cv){
	cookieValues = parseCookie(cv);

} else {
	createCookie("ihtuserdata","fontSize:13",7);
	cv = readCookie("ihtuserdata");
	if (cv){
		// the cookie was created, parse the values
		cookieValues = parseCookie(cv);
	} else {
			cookieValues[0] = "13"; // font size
	}
}