// JavaScript Document


 Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};



// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function Get_Cookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
	

function changeLanguage(lang) {
	if (Get_Cookie('lang') != lang) {
		Set_Cookie('islangchange', "yes");	
	}else {
		Set_Cookie('islangchange',"no");
		return ;
	}
	
	Set_Cookie('lang',lang);
	var patt1 = /\?lang=\w+/i;
	var suffix = "?lang=" + lang;
	var curloc =  new String();
	curloc = window.document.location.href;
	
	if (patt1.test(curloc) ==false) {
		curloc += suffix;
	}else {
		curloc = curloc.replace(patt1,suffix);
	}
	//alert(curloc);
	window.document.location = curloc;
}




function viewCompanyGallery(compId) {
	$("a[rel=company_photos" + compId + "]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});	
	$('#companyimg'+ compId + '-1').click();	
}	



function refreshViewAdsFancyBox(){
$(".viewads").fancybox({
				'width'				: '75%',
				'height'			: '100%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});	
}

$(document).ready(function() {
	$("#aniProcessing").fancybox({
					
			'autoScale'			: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'modal'				: true,
			'type'				: 'inline'
			
		});		   
							   
							   
							   
	$(".sendcv1").fancybox({
					'width'				: '50%',
					'height'			: '100%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});	
	
	$(".viewvideos").fancybox({
					'width'				: '75%',
					'height'			: '35%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});	
		
	$(".viewads").fancybox({
					'height'			: '100%',
					'autoScale'			: true,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});	
	$("#sharethispagelink").fancybox({
					'width'				: '45%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});						   
	
	$(".viewupgraderequest").fancybox({
					'width'				: '45%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});						   
							
	$(".viewsendmsgtocompany").fancybox({
					'width'				: '45%',
					'height'			: '80%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});						   
							   
	$(".viewprofile").fancybox({
					'width'				: '75%',
					'height'			: '100%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});
	$(".viewmaplocation").fancybox({
					'width'				: '85%',
					'height'			: '100%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});
	
	$("a[rel=company_photos]").fancybox({
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'titlePosition' 	: 'over',
					'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.lengt? ' &nbsp; ' + title : '') + '</span>';
					}
				});	
		
		$(".button").wrap('<div class="buttonR">');
		if (!$.browser.msie){
			//$('.buttonR').css("padding","9px 0px 5px 0px");
				
		}
	
		// Start: banner auto scroll down
		window.onscroll = function (e) { 
		  var vertical_position = 0; 
		  if (document.documentElement.clientHeight)//ie 
			vertical_position = document.documentElement.scrollTop; 
		  else if (pageYOffset)//usual 
			vertical_position = pageYOffset; 
		 
		  else if (document.body)//ie quirks 
			vertical_position = document.body.scrollTop; 
		
		  $('.elAutoSlideDown').each(function() {
			
			 var tadj = $(this).offset().top;
			 //set this one as attribute
			 if ( $(this).attr("defaulttop") == undefined) {
				$(this).attr("defaulttop",315);
			 }else{
				tadj= $(this).attr("defaulttop");
			 }
			 
			 var vpos =  vertical_position - tadj;
			 //if (vpos == (parseInt(tadj) * -1) ) vpos = 0;
			 if (vpos <= 0 ) vpos = 0;
			 $(this).css("top",vpos   + "px");
			// window.document.title = vpos;
			
		  });
		} 
		// End:	banner auto scroll down
	
	//auto complete
	var url = $('#__BASEURL__').val() + "ajax.receiver.html?searchby=1&module=search_auto_complete&part=";
	if ($('#txtSearchBox').length > 0) {
		setAutoComplete("txtSearchBox", "results", url);
		$('#txtSearchBox').focus();
		$('#txtSearchBox').attr("AutoComplete","off");
	}
	
	
	if ($("#slider").length > 0) {
		$("#slider").easySlider( {
		controlsShow: true,
		continuous:true,
		auto:true
		});
		startvScroll();
	}
	
	if ($(".marqueeCategoryContainer").length > 0) {
		$('.marqueeCategoryContainer').each(function() {
			//behavior="alternate"  direction="left"  scrollamount="2";
			$(this).replaceWith("<marquee class=\"marqueeCategory\" behavior=\"alternate\"  direction=\"left\"  scrollamount=\"2\">" + $(this).html() + "</marquee>" );
		});
	}
	


	function startvScroll() {
		if ($('#m1').length > 0) {
			new mq('m1');
			//new mq('m2');
			mqRotate(mqr); // must come last
		}
	}
	
	
	function next()  {
	 $("a","#nextBtn").click();
	}
	
	function previous()  {
	 $("a","#prevBtn").click();
	}	
	

	
    /* design dropdownbox */
    $('#selectSearchOption').selectbox();
	
	//$('#divHeaderWrapper2 .middle .lbox .box2 .boxSelectSearchOption').css("margin-top","3px !important;");
	if ($.browser.msie) {
		$('#divHeaderWrapper2 .middle .lbox .box2 .boxSelectSearchOption').css('cssText', 'margin-top: 3px !important');
		//$('.selectbox').css('cssText', 'padding-top: 12px !important');
		$('div.selectbox-wrapper').css('cssText', 'width: 129px !important');
		//$('div.selectbox-wrapper').css('cssText', 'margin-top: -15px !important');
		

	}
  
});			
		
		
		
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
function clearValue(field) 
{ 
if (field.defaultValue == field.value) 
	field.value = ""; 
	$(field).css("font-style","normal");
	$(field).css("color","#000000");
	
} 

function resetValue(field) 
{ 
if (field.value == "") 
	field.value = field.defaultValue ; 
	$(field).css("font-style","italic");
	$(field).css("color","#AAABA3");
	
}



function authPage() {
	var data =  {};
	  $('#aniProccessingHTML .text').html('Checking, please wait...');
	  $('#aniProcessing').click();
	data.pagepassword = $('#txtpagepassword').val();	
	data.action = "verify_page_password";	
	data.pageid =  $('#txtpageid').val();

	$.post($('#__BASEURL__').val() + "ajax.receiver.html",data,function(data){
		
	  	$.fancybox.close();
		//alert(data);
		var __RESPONSEDATA ; 
	
		try {
			__RESPONSEDATA = eval('(' + data + ')');
			
		}catch(err) {
			  
			__RESPONSEDATA = new Object();
			__RESPONSEDATA.RESPONSE_CODE = "__ERR";
			__RESPONSEDATA.RESPONSE_MESSAGE = err + data;
			
		}
		if ("__NO_ERR" == __RESPONSEDATA.RESPONSE_CODE){
			alert(__RESPONSEDATA.RESPONSE_MESSAGE);
			window.document.location = window.document.location.href;
		}else {
			alert(__RESPONSEDATA.RESPONSE_MESSAGE);
		}
			
		
	});
}
