//var config_site_path = 'http://localhost/acsense/';

$(document).ready(function()
{
	$(document).mousedown(function()
	{
		if($('#search_input').val() == '')
		{
			$('#search_input').val( $('#search_button').attr('title') );
			$('#search_input').css('color','#cccccc');
		}
	});
	
	$('#search_input').focus(function()
	{
		$('#search_input').val('');
		$('#search_input').css('color','#000');
	});
	
	$('#customer #img1, #customer #img2, #customer #img3, #customer #img4, #customer #img5').mouseover(function()
	{
		var img = config_site_path+'uploads/customer/' + $(this).attr('alt')+'.png';
		$(this).attr('src', img);
	});
	
	$('#customer #img1, #customer #img2, #customer #img3, #customer #img4, #customer #img5').mouseout(function()
	{
		var img = config_site_path+'uploads/customer/' + $(this).attr('alt')+'_gr.png';
		$(this).attr('src', img);
	});
	
	
	$(".carousel").carousel({loop: true, effect: "zoom"});

	$(".carousel ul li#0 .carousel-image img").css("width","900px");
	
	$(".carousel ul li#0 .carousel-text-container").hide();
	

	$(".carousel img").fadeIn(2000);

	$(".carousel ul li#0 .carousel-text-container").css('opacity', 0.8);

	if($(".carousel ul li#0 .carousel-image img").width() > 750)
	{
		$(".carousel ul li#0 .carousel-image img").animate( { width:"770px"}, 4000 );
		$(".carousel ul li#0 .carousel-text-container").animate({right:"10px"}, 3000).fadeIn(100);			
	}
	else
	{
		$(".carousel ul li#0 .carousel-text-container").animate({right:"10px"},1000).fadeIn(100);		
	}
	

});


// Checks email valid or not.
function EmailCheck(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	
	// check if '@' is at the first position or at last position or absent in given email 
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   alert("Invalid E-mail ID");
	   return false;
	}
	
	// check if '.' is at the first position or at last position or absent in given email
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	
	// check if '@' is used more than one times in given email
	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid E-mail ID");
		return false;
	 }
	
	
	 // check for the position of '.'
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 {
		alert("Invalid E-mail ID");
		return false;
	 }
	
	 // check if '.' is present after two characters from location of '@'
	 if (str.indexOf(dot,(lat+2))==-1)
	 {
		alert("Invalid E-mail ID");
		return false;
	 }
	
	
	 // check for blank spaces in given email
	 if (str.indexOf(" ")!=-1)
	 {
		alert("Invalid E-mail ID");
		return false;
	 }
	
	 return true;					
}

function GetPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

  function GetPageScroll() {
	  var xScroll, yScroll;
	  if (self.pageYOffset) {
		  yScroll = self.pageYOffset;
		  xScroll = self.pageXOffset;
	  } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		  yScroll = document.documentElement.scrollTop;
		  xScroll = document.documentElement.scrollLeft;
	  } else if (document.body) {// all other Explorers
		  yScroll = document.body.scrollTop;
		  xScroll = document.body.scrollLeft;	
	  }
	  arrayPageScroll = new Array(xScroll,yScroll);
	  return arrayPageScroll;
  };
  
 var filetypes = new Array();
filetypes[0] = '.doc';
filetypes[1] = '.docx';
filetypes[2] = '.pdf';

Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++)
	{
		if (this[i] === value || this[i] === "."+value)
		{
			return true;
		}
	}
	return false;
};

function checkFile(what)
{
	var ext = what.substring(what.length-4,what.length);
	if(!filetypes.inArray(ext))
	{
		alert('Invalid file type');
		return false;
	}
	
	return true;
} 
