/* function for opening popup window */
var TimerRunning = false;
function openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-350)/2);
	var top			= parseInt((screen.height-300)/2)	
	var win_options = 'height='+ height +',width='+ width +',resizable=yes,' 
	+ 'scrollbars=yes,left=' + left + ',top=' + top;

	window.open(url,popup_name,win_options);
}

function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function removeLeadingAndTrailingChar (inputString, removeChar) 

{

	var returnString = inputString;

	if (removeChar.length)

	{

	  while(''+returnString.charAt(0)==removeChar)

		{

		  returnString=returnString.substring(1,returnString.length);

		}

		while(''+returnString.charAt(returnString.length-1)==removeChar)

	  {

	    returnString=returnString.substring(0,returnString.length-1);

	  }

	}

	return returnString;

}


function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }

}

function ShowForgotPasswordBox()
{
forgot = document.getElementById('forgotpass');

if(forgot.style.display == 'none')
	forgot.style.display = 'block';
else
	forgot.style.display = 'none';
		
}

function testimonial_showhide(id)
{
for(i=1;i<=document.getElementById('total_testimonial').value ;i++)
{
if(document.getElementById('link_'+i))
	{
		if(i == id)		
		{
			document.getElementById('full_'+i).style.display = '';
			document.getElementById('link_'+i).style.display = 'none';
			document.getElementById('short_'+i).style.display = 'none';			
		}	
		else		
		{
			document.getElementById('full_'+i).style.display = 'none';
			document.getElementById('link_'+i).style.display = '';
			document.getElementById('short_'+i).style.display = '';			
		}	
		
	}
}
}
// header all condition menu
/////////////////////////////////////////////////////////////////
// 	the following code block is for All condition right side menu
function load_menu_by_ajax()
{
		$.ajax({	
			beforeSend: function(){
				$("#ajax_menu").html("Loading....");
			},
			url: "/ajax_header_menu.php",
			success: function(data) {
				$("#ajax_top_menu").html(data);
				
				var timer ;
				$("#ajax_menu").mouseleave(function(){
					 TimerRunning=true;
					timer=	setTimeout ( "menu_slide_up()", 50);
				}); 
				$("#cat_menu").mouseleave(function(){
					TimerRunning=true;
					timer = setTimeout ( "menu_slide_up()", 50);
					$("#ajax_menu").stop(true,true);
				}); 
				$("#ajax_menu").mouseenter(function(){
					clearTimeout(timer);
					TimerRunning=false;
				});
				$("#cat_menu").mouseenter(function(){ 
					
					//var myleft =  $(".top-nav").offset().left;
					//$("#ajax_menu").css("left",myleft);	
					//$("#ajax_menu").offset({'left':myleft});
/*					if($('#cust-supp'))
					{
						$('#cust-supp').css('margin-top','-5px');
					}
*/					if(TimerRunning == true)
					{
						clearTimeout(timer);
						TimerRunning=false;
					}
					else
					{
						$('#dropmenuatag').addClass('dropmenuactive');
						$("#ajax_menu").slideDown("slow");
						$("#push_page_div").slideDown("fast");	
					}
				});
			
			}
	});
}
function menu_slide_up()
{
	TimerRunning = false;
	$("#push_page_div").slideUp("fast");	
	$("#ajax_menu").slideUp("fast");
	$('#dropmenuatag').removeClass('dropmenuactive');
	if($('#cust-supp'))
	{
		$('#cust-supp').css('margin-top','0px');
	}

}



// 	End of code block 
//////////////////////



function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function showflagpopup(id,lang)
{
	hideflagpopup();
	document.getElementById('dom_'+id).style.display=''
	var objlang  = document.getElementById('lang');
	if(objlang)
	{
			objlang.innerHTML = lang;
	}
	var objlink = document.getElementById('link_'+id);
	if(objlink)
	{
		objlink.className = 'rounded_linkolv';
	}
}

function hideflagpopup()
{
	for(i=1;i<=100;i++)	
	{
		var obj = document.getElementById('dom_'+i);	
		if(obj)
		{
			obj.style.display = 'none';
		}
		
		var objlink = document.getElementById('link_'+i);
		if(objlink)
		{
			objlink.className = 'rounded_linkgrn';
		}
	}
}
// Mini Login Popup Jaascript
function ShowForgotPasswordBox(id)
{
	
if(id)	
forgot = document.getElementById(id);
else
forgot = document.getElementById('forgotpass');

if(forgot.style.display == 'none')
	forgot.style.display = 'block';
else
	forgot.style.display = 'none';
		
}
var box_flg = false;
$(document).ready(function() {
						   
	$("div#signin_menu").hide();
	
	$(".signin").click(function(e) {
		e.preventDefault();
		var offset = $(this).offset();
		var eleheight=	$(this).height();
		$('div#signin_menu').removeAttr("style");
		$('div#signin_menu').css( { "right": 200 + "px", "top":(offset.top+eleheight+5) + "px" } );
		if(box_flg == true)
		{ 	
		 $("div#signin_menu").html('').slideDown(10);
		 box_flg = false;
		 return false;
					
		}
		else{
			 $.ajax({url:'/ajax_mini_login.php',
					success: function(data){
					$('div#signin_menu').html(data).slideDown('fast');
					box_flg = true;
				   }
			 });
		 }
	});
	
	$(".signin2").click(function(e) {
		e.preventDefault();
		var offset = $(this).offset();
		var eleheight=	$(this).height();
		$('div#signin_menu').removeAttr("style");
		$('div#signin_menu').css( { "left": 10 + "px", "top":(offset.top+eleheight+5) + "px" } );
		if(box_flg == true)
		{ 	
		 $("div#signin_menu").html('').slideDown(10);
		 box_flg = false;
		 return false;
					
		}
		else{
			 $.ajax({url:'/ajax_mini_login.php',
					success: function(data){
					var diff=$('div#signin_menu').offset().top+$('html').offset().top;
					$('div#signin_menu').html(data).slideDown('fast');
					box_flg = true;
					if(diff>500)
					{
						$('html, body').animate({ 
						  scrollTop: $('div#signin_menu').offset().top-200
						}, 3000);
					}

				   }
			 });
		 }
	});
	$("div#signin_menu").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {			
		if($(e.target).parent("a.signin").length==0) {
			$(".signin").removeClass("menu-open");
			$("div#signin_menu").hide();
			if(box_flg == true)
			{ 	
			 $("div#signin_menu").html('').slideDown(10);
			 box_flg = false;
			 return false;
			}
		}
		if($(e.target).parent("a.signin2").length==0) {
			$(".signin2").removeClass("menu-open");
			$("div#signin_menu").hide();
			if(box_flg == true)
			{ 	
			 $("div#signin_menu").html('').slideDown(10);
			 box_flg = false;
			 return false;
						
			}
		}
	});	
	
	//Hide all toggle container
	$("ul[class='left_toggle_container']").hide();
	
 	var isanimationcomplete = true;
	//Show container on mouseover of parent and set parent_toggle_flag to ture
	 $("li[class='left_toggle_parent']").mouseenter(function(){ 
			var selected_index=$(this).index();											  
			if(isanimationcomplete == true)
			{	$("li[class='left_toggle_parent']").stop(true,true);
				$("ul[class='left_toggle_container']").stop(true,true);
				$("ul[class='left_toggle_container']").each(function(index){
					if($(this).is(":visible"))
					{
							if(index!=selected_index)
							{
								$(this).slideUp("slow");
							}
					}
				});
				isanimationcomplete = false;
				$(this).find('.left_toggle_container').slideDown("slow",function(){
					isanimationcomplete = true;															 
				});
			}
	 });	
});
//////////////////////


// Below is the code for Custom Google Search


function preloadImages()
{
  if(document.images)
  {

    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }  
}

$(document).ready(function() {
	$('#q').blur(function()
	{
		if($('#q').val() == "")
		{
			$('#q').css("background",'#FFFFFF url(https:\x2F\x2Fwww.google.com\x2Fcse\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_site_search_watermark.gif) left no-repeat') ;
		}
	});
	
	$('#q').focus(function()
	{
		$('#q').css("background",'#FFFFFF') ;
	});
	
	if($('#q').val() == "")
	{
		$('#q').css("background",'#FFFFFF url(https:\x2F\x2Fwww.google.com\x2Fcse\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_site_search_watermark.gif) left no-repeat') ;
	}
});


