// JavaScript Document
function swapimg(imgid,newsource)
{
	document.getElementById(imgid).src=newsource;
}

/* VALIDATION */
function validateRequest(){
		var filter =/^.+\@.+..{2,3}$/ ;
	email=document.servicerequest.email.value;
	if ( email == "" || !filter.test(email) )
         {
        
      alert("Please Enter a Valid Email");
      document.servicerequest.email.focus();
        }
	else
	document.servicerequest.submit();
}

function validateContact(){
		//check email
	var filter =/^.+\@.+..{2,3}$/ ;
	fullname=document.contact.FullName.value;
	
	message=document.contact.Message.value;
	
	email=document.contact.Email.value;
	
	
	//check fullname
	if(fullname==''){
		  alert("Please Enter your Full Name");
      document.contact.FullName.focus();
	}
	
	else
		if ( email == "" || !filter.test(email) )
         {
        
      alert("Please Enter a Valid Email");
      document.contact.Email.focus();
        }
	
	
	else
	//check Message
	if(message==''){
		  alert("Please Enter your Message");
      document.contact.Message.focus();
	}
	

		else
		document.contact.submit();	
	
	
}
 function validateLogIn(){
	un=document.login.username.value;
	pass=document.login.password.value;
	if(!un|| un=="username"){
		alert("Please enter your username");
		document.login.username.focus();
	}
	else
	if(!pass || un=="password"){
		alert("Please enter your password");
		document.login.password.focus();
	}
	
	else
		document.login.submit();
	}
	
function validateMailingList(){
		//check email
	var filter =/^.+\@.+..{2,3}$/ ;
	fullname=document.mailinglist.FullName.value;;
	address=document.mailinglist.Address.value;;
	country=document.mailinglist.Country.value;;
	phone=document.mailinglist.Phone.value;;
	
	email=document.mailinglist.Email.value;
	
	
	//check fullname
	if(fullname==''){
		  alert("Please Enter your Full Name");
      document.mailinglist.FullName.focus();
	}
	
	else
		if ( email == "" || !filter.test(email) )
         {
        
      alert("Please Enter a Valid Email");
      document.mailinglist.Email.focus();
        }
	
	else
	//check counntry
	if(country==''){
		  alert("Please Enter your Country");
      document.mailinglist.Country.focus();
	}
	else
	//check Address
	if(address==''){
		  alert("Please Enter your Address");
      document.mailinglist.Address.focus();
	}
	
	
	
	else
	//check phone
	if(phone==''){
		  alert("Please Enter your Phone");
      document.mailinglist.Phone.focus();
	}
	

		else
		document.mailinglist.submit();	
	
	
}
	/* END VALIDATION */
	
	
function deltext(objid,inputtext)
{
	if(document.getElementById(objid).value==inputtext)
		document.getElementById(objid).value="";
}
function puttext(objid,inputtext)
{
	if(document.getElementById(objid).value=="")
	document.getElementById(objid).value=inputtext;
}

/*for menu begin*/




$(document).ready(
	   
		function() {
				
				//banners//
		   var $links= $('#slideshow a');
			if ( $links.length > 1 ){
			setInterval( "slideSwitch()", 4000 );
			}//animate if more than 1
	
			//drop down menu
			$('#nav ul').hide();
			/*$('#nav > li >ul >li:odd').each(function(){
												$(this).find('a:first').addClass('odd');
												   });*/
			if(typeof on != 'undefined')
				$('#nav #'+on+' a:first').addClass('hover');
			else
				on='home';
			$('#nav li[@id]').hover(
								
							  function() {
								  $('td.brdrbtm').css('z-index','-999');
								  
								   $(this).find('ul:first').show();
								    $(this).find('a:first').addClass('hover');
								
							  },
							  
							function() {
								//alert($(this).attr('id'));
								 $('td.brdrbtm').css('z-index','0');
								   $(this).find('ul:first').hide();
								    $(this).find('a:first').removeClass('hover');
								  $('#nav #'+on+' a:first').addClass('hover');
							  }
												
							
							).click(function() {
								   $(this).find('ul:first').toggle('fast');
								   $(this).find('a:first').toggleClass('hover');
								 // return false;
							  });
			
			
			
			//SITE MAP
			$('#rollup ul').hide();
			$('#rollup h3.clickable').click(function() {$(this).toggleClass('rolledup').next().slideToggle(300);;})
			
							.hover(
									function(){
										
											$(this).addClass('hover');},
									function(){
										$(this).removeClass('hover');});
			
			//SEARCH RESULTS
			var $results=$('#results .result');
			
			//add pages if more than one
			if($results.length>1){
				var npages=$results.length;
			$('#results .result:gt(0)').hide();
			var pages='';
			var pages='<div class="pages"><span class="page" href="#" rel="first" title="first">&lt;&lt;</span>';
			//pages+='<span class="page" href="#" rel="prev" title="previous">prev</span>';
			$('#results .result').each(function(index){
										 
										  pages+=' <span title="'+(index+1)+'" class="page" href="#">'+(index+1)+'</span>';
										  });
			//pages+='<span class="page" href="#" rel="next" title="next">next</span>';
			pages+='<span class="page" href="#" rel="last" title="last">&gt;&gt;</span></div>';
			$('#results').append(pages);
			$('#results').prepend(pages);
			
			//$('.pages a:nth(1)').addClass('highligh');
			$('.pages ').each(function(index){$(this).find('span:nth(1)').addClass('highlight');});
			var curi=1;
			$('.pages').each(function(index){
									  $(this).find('span.page').each(function(index){
										  $(this).click(function(){
															  
															  var type=$(this).attr('rel');
															  var i;
															  switch(type){
																case 'first':
																	i=0;break;
																case 'last':
																	i=($('#results .result').length)-1;break;
																case 'prev':
																		i=(cur>1)?(curi-1):1; break;
																case 'next':
																	i=curi+1; alert(''+(curi+1)); break;
																default:
																	i=index-1;
																
															  }
															  $('#results .result').hide();
															 $('.pages span').removeClass('highlight');
															 
								 $('.pages ').each(function(index){$(this).find('span:nth('+(i+1)+')').addClass('highlight');});
															// $(this).addClass('highlight');
															 curi=i;
															  $('#results .result:eq('+i+')').show();
															  })
											 
											 });});
			}//end if
			
	//ie 6 fix menu height
	// Split the string into part [0] and part [1]
	temp=navigator.appVersion.split('MSIE');

	// Parse the string for the "6" in 6.0
	ieVer=parseInt(temp[1]);
	if(ieVer==6){
	height=getTDHeight();
	$('.posabs').css('height',height);
			}
		}
		);

/*for menu end*/

//for banners
function slideSwitch() {
	
	
       var $active = $('#slideshow a.active');
	//alert($active.attr('title'));
    if ( $active.length == 0 ) $active = $('#slideshow a:last');
	
	
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow a:first');
		
	//var i= $next.html();
	//alert(i);
	
	 //$active.removeClass('active');
 	$active.addClass('last-active');
	
   $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 3000, function() {
            $active.removeClass('active last-active');
        });
}


/***********************only for IE6 **********/
function getPixelsFromTop(obj){
	objFromTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		objParent = obj.offsetParent;
		objFromTop += objParent.offsetTop;
		obj = objParent;
	}
	return objFromTop;
}


function getTDHeight(){
	
	contentTopDiv = document.getElementById("content_top")
	
	contentBotDiv = document.getElementById("content_bottom")
	
	contentTop = getPixelsFromTop(contentTopDiv);
	
	contentBottom = getPixelsFromTop(contentBotDiv);
	
	contentHeight = contentBottom - contentTop;
	//alert(contentHeight);
	return (contentHeight-9);
}

