// $Id: common.js,v 1.8 2010/02/23 12:59:08 bipinpatel Exp $ 
function confirmDel(msgDel){
	if(confirm(msgDel)) {
		return true;
	}
	return false;

}
//For open pop up window
function openpopup (popurl) {
 	var winpops = window.open(popurl,"","width=770,height=450,menubar=0,toolbar=0,scrollbars =1");
	winpops.focus();
}
function depositJS(deposit_type){
	if(deposit_type.value == "Y")
		$('#deposits').css('display','block');
	else
		$('#deposits').css('display','none');
}

function productAvaJS(prd_availabe){
	if(prd_availabe.value == 2)
		$('#product_ava').css('display','block');
	else
		$('#product_ava').css('display','none');
}

function blockError(){return true;}
	window.onerror = blockError;

function imageSmall(imgPath,seqname)
{
	$('#imgSmall'+seqname).attr('src',imgPath);
	return false;
}

function imageLarge(imgName){
	$('#imgLarge').attr('src',imgName);
	return false;
}

jQuery.fn.contactInfo=function(e)
{				
	if(e.value == 'N')
		$('#contact_inf').css('display', 'block');			
	else
		$('#contact_inf').css('display', 'none');
	
}

jQuery.fn.loadCategory=function(id,level, setVal, setLevel)
{		
		levelVal=$('#catLevel').val();
		if(setLevel == 'false')
		{
			for(i=level+1;i<=levelVal+1;i++)
			{
				if('#category_level_'+i)
					$('#category_level_'+i).remove();
			}
			$('#catLevel').val((parseInt(level)-1));
		}
		if(id > 0)
		{			
			$.ajax({
				'url': '/seller/selectCategory/id/'+id+'/level/'+level+'/setVal/'+setVal+'/setLevel/'+setLevel,
				'success': function(html)
				{
				   	if(setLevel == 'false')
				   	{				   		
				   		$('#category_level_1').append(html);
				   		$('#catLevel').val(level);
				   		$('#catLevelhid').val(level);
				   	}
				   	else
				   	{
				   		nextLevel=level+1;
				   		$('#category_level_'+nextLevel).html(html);				   		
				   	}
				}
			});
		}
}

//To remove blank space from both side of string
function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
// zoom icon display while mouseover on image
function zoomIcon(id, totalImage, bigAvailable, altTag)
{
	src = '/images/zoom_modal_icon.png';
	alt = altTag;
	for(i=0;i<totalImage;i++)
	{
		$('#zoom_'+i).html('');
	}
	$('#imgLarge').attr('style','cursor:default');
	if(bigAvailable)
	{
		$('#zoom_'+id).html('<img id="zoomImageId" style="cursor:pointer;" class="img png" src="'+ src +'" width="24" height="24" alt="'+alt+'" />');
		$('#imgLarge').attr('style','cursor:pointer');
	}
}
function dispatchClickEvent(id){
	var fireOnThis = document.getElementById(id);
	if( document.createEvent ) {
		var evObj = document.createEvent('MouseEvents');
    	evObj.initMouseEvent( 'click', true, true, window, 0, 12, 345, 7, 220, false, false, true, false, 0, null );
    	fireOnThis.dispatchEvent(evObj);
	}
	else if( document.createEventObject ){
		var evObj = document.createEventObject();
  		evObj.detail = 0;
  		evObj.screenX = 12;
  		evObj.screenY = 345;
  		evObj.clientX = 7;
  		evObj.clientY = 220;
  		evObj.ctrlKey = false;
  		evObj.altKey = false;
  		evObj.shiftKey = true;
  		evObj.metaKey = false;
  		evObj.button = 0;
  		evObj.relatedTarget = null;
  		fireOnThis.fireEvent('onclick',evObj);
 	}
}
function setTimeZoneOffset()
{
	var now = new Date();
	var later = new Date();
	// Set time for how long the cookie should be saved
	later.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	// Set cookie for the time zone offset in minutes
	setCookie("time_zone_offset", now.getTimezoneOffset(), later, "/");
	// Create two new dates
	var d1 = new Date();
	var d2 = new Date();
	// Date one is set to January 1st of this year
	// Guaranteed not to be in DST for northern hemisphere,
	// and guaranteed to be in DST for southern hemisphere
	// (If DST exists on client PC)
	d1.setDate(1);
	d1.setMonth(1);
	// Date two is set to July 1st of this year
	// Guaranteed to be in DST for northern hemisphere,
	// and guaranteed not to be in DST for southern hemisphere
	// (If DST exists on client PC)
	d2.setDate(1);
	d2.setMonth(7);
	// If time zone offsets match, no DST exists for this time zone
	if(parseInt(d1.getTimezoneOffset())==parseInt(d2.getTimezoneOffset()))
	{
		setCookie("time_zone_dst", "0", later, "/");
	}
	// DST exists for this time zone - check if it is currently active
	else
	{
	  	// Find out if we are on northern or southern hemisphere
	  	// Hemisphere is positive for northern, and negative for southern
	  	var hemisphere = parseInt(d1.getTimezoneOffset())-parseInt(d2.getTimezoneOffset());
	  	// Current date is still before or after DST, not containing DST
	  	if((hemisphere>0 && parseInt(d1.getTimezoneOffset())==parseInt(now.getTimezoneOffset())) ||
	    	(hemisphere<0 && parseInt(d2.getTimezoneOffset())==parseInt(now.getTimezoneOffset())))
	  	{
	    	setCookie("time_zone_dst", "0", later, "/");
	  	}
	  	// DST is active right now with the current date
	  	else {
	    	setCookie("time_zone_dst", "1", later, "/");
	  	}
	}
}