

$(document).ready(function(){
	$(".open_change_province").colorbox({inline:true, href:"#open_change_province"});
	$(".open_invalid_items").colorbox({inline:true, href:"#open_invalid_items"});
	$(".open_reviews").colorbox({inline:true, href:"#open_reviews"});
 	$(".open_province").colorbox({inline:true, href:"#open_province"});
	$(".open_login").colorbox({inline:true, href:"#open_login"});
	$(".open_sizes").colorbox({inline:true, href:"#open_sizes"});
	$(".open_add").colorbox({inline:true, href:"#open_add"});
	$(".open_popup").colorbox({inline:true, href:"#open_popup"});
	$(".open_popup_messageError").colorbox({inline:true, href:"#open_popup_messageError"});
	$(".open_popup_login").colorbox({inline:true, href:"#open_popup_login"});
	$(".open_popup_discrepancies").colorbox({inline:true, href:"#open_popup_discrepancies"});
	$(".open_popup_Ticket").colorbox({inline:true, href:"#open_popup_Ticket"});
	$(".open_popup_Error").colorbox({inline:true, href:"#open_popup_Error"});
	$(".open_popup_password").colorbox({inline:true, href:"#open_popup_password"});
	$(".open_popup_password2").colorbox({inline:true, href:"#open_popup_password2"});
	$(".open_popup_msg").colorbox({inline:true, href:"#open_popup_msg"});
	$(".open_popup_list").colorbox({inline:true, href:"#open_popup_list"});
	$(".open_popup_list2").colorbox({inline:true, href:"#open_popup_list2"});
	$(".open_popup_reviews").colorbox({top:"0px",width:"820px",height:"250px",fixed:true,inline:true,href:"#open_popup_reviews"});
	$(".open_popup_msg_ajax").colorbox({inline:true, href:"#open_popup_msg_ajax"});
	$(".open_popup_alert_click_collect").colorbox({inline:true, href:"#open_popup_alert_click_collect"});
});

validateDateFormat = function(dateValue)	{
	var re = new RegExp("^([0-9]{1,2})[./]{1}([0-9]{1,2})[./]{1}([0-9]{1,4})$");
	var ar;
	var dd;
	var mm;
	var yyyy;
				
	if ((ar = re.exec(dateValue)) != null)	{
		dd = parseFloat(ar[1]);
		if (dd <= 0 || dd > 31)		{
			return false;
		}
		mm = parseFloat(ar[2]);
		if (mm <= 0 || mm > 12)		{
			return false;
		}
		yyyy = parseFloat(ar[3]);
		if (yyyy <= 2010)		{
			return false;
		}
	}else{
		return false;
	}	
	return true;
}


dateDiff = function(date1,date2,interval) {
    var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
    var arr1 = date1.split("/");
    var arr2 = date2.split("/");
    var date1 = new Date(arr1[2], arr1[1], arr1[0]);
	var date2 = new Date(arr2[2], arr2[1], arr2[0]);
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    switch (interval) {
        case "years": return date2.getFullYear() - date1.getFullYear();
        case "months": return (
            ( date2.getFullYear() * 12 + date2.getMonth() )
            -
            ( date1.getFullYear() * 12 + date1.getMonth() )
        );
        case "weeks"  : return Math.floor(timediff / week);
        case "days"   : return Math.floor(timediff / day); 
        case "hours"  : return Math.floor(timediff / hour); 
        case "minutes": return Math.floor(timediff / minute);
        case "seconds": return Math.floor(timediff / second);
        default: return undefined;
    }
}

function setVid(flvname)
		{
			SH('Image','none');
			SH('Images','none');
			SH('Videos','block');
     		var html = '';
			
			
			
			
			html += '<object width="424" height="460">';
			html += '<param name="movie" value="videos/player_video.swf?f=flv/'+flvname+'.flv"></param>';
  			html += '<param name="allowFullScreen" value="true"></param>';
  			html += '<param name="allowscriptaccess" value="always"></param>';
  			html += '<embed wmode="transparent" src="videos/player_video.swf?f=flv/'+flvname+'.flv" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="424" height="460"></embed>';
			html += '</object>';
			

			
      		document.getElementById('Videos').innerHTML = html;

		}
		
		function setImage(imagename)
		{
			SH('Videos','none');
			SH('Images','block');
			SH('Image','none');
     		var html = '';
           	html += '<img src="'+imagename+'" width="424" height="460" />';
			
      		document.getElementById('Images').innerHTML = html;

		}


		var content = '';

		function InnerClose(){
  			content = document.getElementById('Videos').innerHTML; 
  			document.getElementById('Videos').innerHTML = content;
			
  		}
  
  		function InnerShow(){
       		content = obj.innerHTML;
       		obj.innerHTML = '';
       		obj.innerHTML = content;  
  		}
		
		function hide_video(){
		SH('Videos', 'none');
		SH('Images', 'block');
		}
		
		var lastactive = null;
		
		function setImgURL(img, path){
			img.src=path;
		}
		
		function seton(img)
			{ img.src = img.src.replace(/\.gif/, "_over.gif"); }
		
		function setoff(img)
			{ img.src = img.src.replace(/\_over.gif/, ".gif"); }
			
		function setactive(img)
			{ 	
				img.src = img.src.replace(/\_over.gif/, "_clicked.gif");
				lastactive = img;				
			}			
			
		function setactive_off(img)
		{ 
			img = lastactive;
		
			if (img != null)
			{
			if(img.src.indexOf("over") > 0)
			{
			img.src = img.src.replace(/\_over.gif/, ".gif"); 
			} else if(img.src.indexOf("clicked") > 0)
			{
			img.src = img.src.replace(/\_clicked.gif/, ".gif"); 
			}
			} 
		}


		
		function SH(id, block) 
		{	 
    	obj = document.getElementsByTagName("div"); 
    	obj[id].style.display = block;
		}		

		function navon(img)
			{ 
			if(img.longdesc != "on")
				{img.src = img.src.replace(/\.gif/, "_over.gif");}
			}
		
		function navoff(img)
			{ 
			if(img.longdesc != "on")
				{img.src = img.src.replace(/\_over.gif/, ".gif"); }
			}

		function navActive(img)
			{ 
			var tag	= document.getElementById('navrow').getElementsByTagName('img');
			for (var i=0; i	< tag.length; i++) {
				tag[i].src = tag[i].src.replace(/\_over.gif/, ".gif"); 
				tag[i].longdesc = "off";
			}
			img.src = img.src.replace(/\.gif/, "_over.gif"); 
			img.longdesc = "on";
			}
			
			
			
			
				function alerterr(msg)
	{
	
		$('errorLyr').hide();
		
		html  = '<table bgcolor="#7f6332" cellpadding="0" cellspacing="0" border="0" width="320" height="320">\n';
		html += '<tr>\n';
		html += '<td width="15"></td>\n';
		html += '<td width="290" height="35" valign="bottom" align="center"><img src="images/pleasenote.gif" width="199" height="24" alt=""></td>\n';
		html += '<td width="15"></td>\n';
		html += '</tr>\n';
		html += '<tr>\n';
		html += '<td width="320" height="20" colspan="3"></td>\n';
		html += '</tr>\n';
		html += '<tr>\n';
		html += '<td width="15" height="100"></td>\n';
		html += '<td width="290" height="100" valign="top" align="center" style="color:#000;font-family:Arial;font-size:11px;">'+msg+'</td>\n';
		html += '<td width="15" height="100"></td>\n';
		html += '</tr>\n';
		html += '<tr>\n';
		html += '<td width="15" height="30"></td>\n';
		html += '<td width="290" height="30" align="center" align="right" valign="top"><a href="javascript://" onclick="$(\'errorLyr\').hide();"><img src="images/error_close.gif" width="67" height="20" alt="" border="0"></a></td>\n';
		html += '<td width="15" height="30"></td>\n';
		html += '</tr>\n';
		html += '</table>\n';		
	
			$('errorLyr').update(html);
			$('errorLyr').show();

	}		
		
	function centerlayer(layerName,w,h)
	{

		obj = getObject(layerName);
	
		if (parseInt(navigator.appVersion)>3)
		{
	
			if (navigator.appName=="Netscape")
			{
				winW = window.innerWidth;
				winH = window.innerHeight;
			}
	
			if (navigator.appName.indexOf("Microsoft")!=-1)
			{
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			}
		}

		if (w>0)
		{
			LeftPosition=(winW)?(winW-w)/2:100;
			LeftPosition = parseInt(LeftPosition);
		//	alert(LeftPosition);
			obj.left = LeftPosition+"px";
		}
	
		if (h>0)
		{
			TopPosition=(winH)?(winH-h)/2:100;
			TopPosition = parseInt(TopPosition);
		//	alert(TopPosition);
			obj.top = TopPosition+"px";
		}
		
	}

	
	//Browser Sniffing
	var ns4=document.layers?1:0
	var ie=document.all?1:0
	var ns6=document.getElementById&&!document.all?1:0
	var mac=navigator.userAgent.indexOf('Mac')>0?1:0;
	var obj = null;	
	
	//Hide and show layers
	if (ie||ns6)
	{
		var fShow = "visible";
		var fHide = "hidden";
	}
	else
	{
		var fShow = "show";
		var fHide = "hide";
	}	

	function getObject(layerName)
	{
		if (ie)
		{	
			obj = eval("document.all['"+layerName+"'].style");
		}
		else if (ns6)
		{
			obj = eval("document.getElementById('"+layerName+"').style");		
		}
	
		else
		{
			obj = eval("document.layers['"+layerName+"']");
		}
	
		//	alert(layerName+' '+obj);	
		return obj;		
	}

	function centerwin(obj,h,w)
	{	
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

		obj.moveTo(LeftPosition,TopPosition);	
	}

	function setwin(obj,h,w)
	{	
		obj.resizeTo(w,h);
		centerwin(obj,h,w);
		obj.focus();	
	}
	
	function Validemail(val) 
	{
		var RE1 = /^[A-Za-z0-9_-]+[.A-Za-z0-9_-]*@{1,1}[A-Za-z0-9_-]+[.]{1,1}\w{2,4}/;
		return RE1.test(val);
	}	
	
	function TestNumerics(val) 
	{
		var RE1 = /[\d]+/;
		return RE1.test(val);
	}
	
	function TestAlphaNumerics(val)
	{
		var RE1 = /[A-Za-z ]/;
		return RE1.test(val);
	}
	
	function Testfield(val)
	{
		var RE1 = /@/;
		return RE1.test(val);
	}
	
	

	function reset_all()
	{
		$('.exc_hide').each ( function() { $(this).hide() } );
		$('.messageblock_bottom').each ( function() { $(this).hide() } );
		$('.messageblock_bottom_longer').each ( function() { $(this).hide() } );
		$('.messageblock_bottom_faq').each ( function() { $(this).hide() } );
		$('.messageblock').each ( function() { $(this).text('') } );
		$('.invalid').each ( function() { $(this).text('') } );
		$('.fieldinvalid').each ( function() { $(this).text('') } );
		$('.messageblock_faq').each ( function() { $(this).text('') } );
		$('.messageblock_top').each ( function() { $(this).text('') } );
		$('.exclimation').each ( function() { $(this).show() } );
		$('.messageblock_myacc').each ( function() { $(this).text('') } );
		$('.messageblock_bottom_myacc').each ( function() { $(this).hide() } );
	}


	function alert_inline(element_id, msg)		{
		$('#' + element_id + '_msg').text(msg);
		$('#' + element_id + '_alert').show();
		$('#' + element_id + '_star').hide();
		$('#' + 'main_msg').show();	
		$('.position_absolute,.position_absolute_card').hide();
	}

	function generalAnchor(target){		
        var offset = $("#"+target).offset().top;
        if (offset != null)
        $('html,body').animate({ scrollTop: offset }, 'slow');		
	}
	
	

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
