// JavaScript Document
var options = { 
        //target:        '#output2',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:	showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };

// ************ not using trim_this() function as it is not functioning properly  *************************
function trim_this(s)
{
	//calculate the length of the supplied string
	l = s.length;
	
	//now get the starting point of the string ------ remove the blank spaces from the start of the string
	start_point = 0;
	for(i=0;i<l;i++)
	{
		//alert("character at position "+i+"="+s.charAt(i));
		if(s.charAt(i) == "" || s.charAt(i) == " " || s.charAt(i) == null)
			start_point++;
		else
			break;
	}
	
	//now get the end point of the supplied string ------ remove the blank spaces from the end of the string
	end_point = l-1;
	for(i=l-1;i>0;i--)
	{
		//alert("character at position "+i+"="+s.charAt(i));
		if(s.charAt(i) == "" || s.charAt(i) == " " || s.charAt(i) == null)
		{
			end_point--;
			alert('i was here');
		}
		else
			break;
	}
	
	//debug
	alert("end_point recorded="+end_point);
	
	//now return the trimmed sub-string
	trimmed_string = s.substring(start_point,end_point);
	
	return trimmed_string;
}

function delete_all()
{

	 	ok = confirm("Doing this will delete all the images related to the newsletters sent in the past!!! \nIt is highly recommended that you do not perform this action as it will delete all images from newsletters image option gallery!");
		if(ok == true)
		{
			return true;
		}
		else
			return false;

}

function delete_uploads()
{

	 	ok = confirm("Doing this will delete all the uploaded content!!! \nIt is highly recommended that you do not perform this action, instead please use delete one method");
		if(ok == true)
		{
			return true;
		}
		else
			return false;

}

function delete_uns(l,g)
{
	string = 'list='+l+'&g='+g;
	//alert(string);
	$.post('../include/newsletter_processing.php',string,function(data){
		$('#news_dc').html(data);
	});
}

function change_e_content(e)
{
	a = e.value;
	//alert(a);
	if(a == 'text')
	{
		$('.fancy').hide();
		$('.simple').show();
	}
	if(a == 'html')
	{
		$('.fancy').show();
		$('.simple').hide();
	}
	
}

function send_cred()
{
	flag = "";
	e_message = "Please correct following fields:";
	
	//sub
	a = $('#sub').val();
	//alert('sub='+a);
	if(a == '' || a == null)
	{
		flag = 'error';
		e_message += "\n -> Please enter the subject";
	}

	//message description
	var content = $('iframe').contents().find("body").html();
	a = content;
	
	
	if(a == '' || a == null || a == '<br>')
	{
		flag = 'error';
		e_message += "\n -> Please put some content in your message";
	}
	//alert(flag);
	if(flag == 'error')
	{
		alert(e_message);
		return false;
	}
	else
	{
		var content = $('iframe').contents().find("body").html();
		$('#id_description').val(content);
		//alert(content);
		string = $('#news').serialize();
		//alert(string);
		$.post('../include/send_cred.php',string,function(data){
			alert(data);
			location.reload();
		});
		return true;
	}
}

function news_validate(e)
{
	//alert(e);
	flag = "";
	e_message = "Please correct following fields:";
	//interest
	a = $('input:checked').length;
	//alert(a);
	if(a == 0)
	{
		flag = 'error';
		e_message += "\n -> Please select the subscriber group";
	}
	//alert(e_message);
	//sub
	a = $('#sub').val();
	//alert('sub='+a);
	if(a == '' || a == null)
	{
		flag = 'error';
		e_message += "\n -> Please select the newsletter subject";
	}
	
	//message
	//alert('message='+a);
	interest = $('.e_content').val();
	if(interest == 'text')
	{
		a = $('.plain_content').val();
	}
	else
	{
		var content = $('iframe').contents().find("body").html();
		a = content;
		//alert(a);
	}
	
	if(a == '' || a == null || a == '<br>')
	{
		flag = 'error';
		e_message += "\n -> Please put some content in your newsletter";
	}
	//alert(flag);
	if(flag == 'error')
	{
		alert(e_message);
		return false;
	}
	else
	{
		if(e == 'test')
		{
			stm();
		}
		else
		{
			bm();
		}
		return true;
	}
}


function stm()
{

		c_type = $('.e_content').val();
		if(c_type == 'text')
		{
			string = $('form').serialize();
		}
		else
		{
			var content = $('iframe').contents().find("body").html();
			$('#id_description').val(content);
			//alert(content);
			string = $('form').serialize();
		}
		string = string + '&test=set';
		//alert(string);
		alert('sending test message... \n it will take few seconds ....');
		$.post('../include/newsletter_processing.php',string,function(data){
			alert(data);
		});

}

function bm()
{

		var content = $('iframe').contents().find("body").html();
		$('#id_description').val(content);
		//alert(content);
		string = $('form').serialize();
		$('#news_dc').html('<span class=\'size12\'>sending emails...  please wait ...</span>');
		$.post('../include/newsletter_processing.php',string,function(data){
			//alert(data);
			$('#news_dc').html(data);
		});
}

function check_proceed(t)
{
	if(t == 'online')
	{
		send_data = "proceed=set";
		$.post('include/cart_processing.php',send_data,function(data){
			seperate = data.split(',');
			if(seperate[1] != null || seperate[1] != "")
				lowerLimit = seperate[1];
			store = parseInt(seperate[0],10);
			//alert(store);
			if(store == 0)
			{
				alert("Sorry! can't proceed!!!\n \nCurrent shopping cart cost is less than the required minimum order placement for online shopping, which is:\n"+lowerLimit+" excluding shipping cost!");
			}
			else
			{
				location.href = "shopping_secure_s2.php";
			}	
	   });
	}
	if(t == 'wh')
	{
		send_data = "proceed=set";
		$.post('../include/wh_cart_processing.php',send_data,function(data){
			store = parseInt(data,10);
			//alert("data="+data+" and store="+store);
			if(store == 0)
			{
				alert("Sorry! can't proceed!!!\n \nCurrent shopping cart has no items in it!");
			}
			else
			{
				location.href = "wh_secure_cart.php";
			}	
	   });
	}
	if(t == 'dis')
	{
		send_data = "proceed=set";
		$.post('../include/dis_cart_processing.php',send_data,function(data){
			store = parseInt(data,10);
			//alert(store);
			if(store == 0)
			{
				alert("Sorry! can't proceed!!!\n \nCurrent shopping cart has no items in it!");
			}
			else
			{
				location.href = "dis_secure_cart.php";
			}	
	   });
	}
	if(t == 'hos')
	{
		send_data = "proceed=set";
		$.post('../include/hos_cart_processing.php',send_data,function(data){
			store = parseInt(data,10);
			//alert(store);
			if(store == 0)
			{
				alert("Sorry! can't proceed!!!\n \nCurrent shopping cart has no items in it!");
			}
			else
			{
				location.href = "hos_secure_cart.php";
			}	
	   });
	}
}

function toggle_sform()
{
	if($.browser.mozilla)
	{
		if($('#sform_container').is(':visible'))
		{
			$('#sform_container').hide();
			$('#sform_control').html(' [+]');
		}
		else
		{
			$('#sform_container').slideDown();
			$('#sform_control').html(' [-]');
		}
	}
	else
	{
		$('#sform_container').slideToggle(1000,function(){
			if($('#sform_container').is(':visible'))
			{
				$('#sform_control').html(' [-]');
			}
			else
			{
				$('#sform_control').html(' [+]');
			}
		});
	}
}


function set_shipping_cost(a)
{
	send_data = "shipping="+a.value;
	//alert(send_data);
	$.post('include/cart_processing.php',send_data,function(data){
		d = data.split('-');
		//alert(d[0].length);
		if(d[0] == "invalid")
		{
			$('#proceed').hide();
			check = confirm('If you change the state information, you will have to re-submit the new shipping address! \nDo you want to change the shipping address?\nPress OK to re-enter the shipping address and submit it!\nPress Cancel to leave it as it is!');
			if(check)
			{
				us_data = "unset="+1;
				$.post('include/cart_processing.php',us_data,function(ret){
					//location.reload();
				});
			}
			else
			{
				$('#proceed').show();
			}
		}
		else
		{
			if(data != "$0.00")
			{
				e = data.split('-');
				//alert(data);
				$('#shipping_cell').html(e[0]);
				$('#finaltotal_cell').html(e[1]);
			}
		}
	});
	
}

function change_quantity(a,id)
{
	send_data = 'id='+id+"&q="+a.value;
	//alert(send_data);
	$.post('include/cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	
}

function wh_change_quantity(a,id)
{
	send_data = 'id='+id+"&q="+a.value;
	//alert(send_data);
	$.post('../include/wh_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	
}

function dis_change_quantity(a,id)
{
	send_data = 'id='+id+"&q="+a.value;
	//alert(send_data);
	$.post('../include/dis_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	
}

function hos_change_quantity(a,id)
{
	send_data = 'id='+id+"&q="+a.value;
	//alert(send_data);
	$.post('../include/hos_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	
}

function remove_this_item(id)
{
	decision = confirm("Do you really want to remove this item from the cart");
	send_data = 'remove='+id;
	//alert(send_data);
	if(decision == true)
	{
		$.post('include/cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	}
}

function wh_remove_this_item(id)
{
	decision = confirm("Do you really want to remove this item from the cart");
	send_data = 'remove='+id;
	//alert(send_data);
	if(decision == true)
	{
		$.post('../include/wh_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	}
}

function dis_remove_this_item(id)
{
	decision = confirm("Do you really want to remove this item from the cart");
	send_data = 'remove='+id;
	//alert(send_data);
	if(decision == true)
	{
		$.post('../include/dis_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	}
}

function hos_remove_this_item(id)
{
	decision = confirm("Do you really want to remove this item from the cart");
	send_data = 'remove='+id;
	//alert(send_data);
	if(decision == true)
	{
		$.post('../include/hos_cart_processing.php',send_data,
		   function(data){
			   	//history.go(-1);
				location.reload();
		   });
	}
}

function ask_quantity(id,e,which)
{
	noofids = id.split('~');
	//alert(e.width);
	send_data = "";
	if(noofids.length == 1)
	{
		//prepare data to be send to get_quan_boxes php file to determine the number of select boxes to display 
		send_data += "id1="+noofids[0]+"&ask=1&which="+which+"&";
		send_data += "p_length="+1;
		
		//create bubble to load the select boxes from php file
		quan_bubble = 'quan_bubble';  //'bubble_'+noofids[0]
		//alert(quan_bubble);
		$('<div id = '+quan_bubble+'></div>')
		.load('include/get_quan_boxes.php?'+send_data)
		.appendTo('body')
		.hide()
		.delay(200)
		.addClass('shipCalBubble');
		
		bubble(e,quan_bubble,0,40,12); /* calling procedure "bubble(this,'shipCalBubble',vertical offset value,horizontal offset value,z-index value,'toggle');" */

		
		// show the white background behind the bubble
		$('#top_board')
		.show()
		.css({'z-index':'11','opacity':'0'})
		.animate({'opacity': '0.10'},300);
		
		
		//alert(send_data);
		//ajax request
		/*$.post('include/cart_processing.php',send_data,
		   function(data){
			   	//alert(data);
				if($.browser.webkit)
					$('body').animate({scrollTop:0},1000,'swing',function(){alert("item added to the cart!!!");$('#live_cart_bar').html(data);});
				else
					$('html').animate({scrollTop:0},1000,'swing',function(){alert("item added to the cart!!!");$('#live_cart_bar').html(data);});	   	
		   });*/
	}
	else
	{
		for(i=0;i<noofids.length-1;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+(noofids.length-1)+"&";
		
		//now add the checkbox values to be sent to the popup window
		if(document.getElementById(noofids[0]).checked == true)
			check1 = noofids[0];
		else
			check1 = "null";
			
		if(document.getElementById(noofids[1]).checked == true)
			check2 = noofids[1];
		else
			check2 = "null";
		
		send_data += "check1="+check1+"&check2="+check2+"&ask=1&which="+which;
		//alert("check1 ="+check1+" check2 ="+check2);
		if(check1 != "null" || check2 != "null")
		{
			//create bubble to load the select boxes from php file
			quan_bubble = 'quan_bubble';  //'bubble_'+noofids[0]
			//alert(quan_bubble);
			$('<div id = '+quan_bubble+'></div>')
			.load('include/get_quan_boxes.php?'+send_data)
			.appendTo('body')
			.hide()
			.delay(200)
			.addClass('shipCalBubble');
			
			bubble(e,quan_bubble,0,40,12); /* calling procedure "bubble(this,'shipCalBubble',vertical offset value,horizontal offset value,z-index value,'toggle');" */
	
			
			// show the white background behind the bubble
			$('#top_board')
			.show()
			.css({'z-index':'11','opacity':'0'})
			.animate({'opacity': '0.05'},300);
			
			//ajax request
			/*$.post('include/cart_processing.php',send_data,
			function(data){
				//alert(data);
				$('#live_cart_bar').html(data);
				alert("item added to the cart!!!");
		   });*/
		}
		else
			alert("Please select atleast one package size to be added to the cart!!!");
	}
}

function add_to_cart(id,e)
{
	noofids = id.split('~');
	//alert(e.width);
	send_data = "";
	if(noofids.length == 1)
	{
		send_data += "id1="+noofids[0]+"&";
		send_data += "p_length="+1;
		//alert(send_data);
		//ajax request
		$.post('include/cart_processing.php',send_data,
		   function(data){
			   	//alert(data);
				if($.browser.webkit)
					$('body').animate({scrollTop:0},1000,'swing',function(){alert("item added to the cart!!!");$('#live_cart_bar').html(data);});
				else
					$('html').animate({scrollTop:0},1000,'swing',function(){alert("item added to the cart!!!");$('#live_cart_bar').html(data);});	   	
		   });
	}
	else
	{
		for(i=0;i<noofids.length-1;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+(noofids.length-1)+"&";
		
		//now add the checkbox values to be sent to the popup window
		if(document.getElementById(noofids[0]).checked == true)
			check1 = noofids[0];
		else
			check1 = "null";
			
		if(document.getElementById(noofids[1]).checked == true)
			check2 = noofids[1];
		else
			check2 = "null";
		
		send_data += "check1="+check1+"&check2="+check2;
		//alert("check1 ="+check1+" check2 ="+check2);
		if(check1 != "null" || check2 != "null")
		{
			//ajax request
			$.post('include/cart_processing.php',send_data,
		   	function(data){
			   	//alert(data);
			   	$('#live_cart_bar').html(data);
				alert("item added to the cart!!!");
		   });
		}
		else
			alert("Please select atleast one package size to be added to the cart!!!");
	}
}

function add_to_cart_pop(id)
{
	noofids = id.split('~');
	//alert(id);
	send_data = "";
	if(noofids.length == 1)
	{
		for(i=0;i<noofids.length;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+1;
		//ajax request
		$.post('include/cart_processing.php',send_data,
		   function(data){
			   	//alert(data);
			   	$('#live_cart_bar').html(data);
				alert("item added to the cart!!!");
		   });
	}
	else
	{
		for(i=0;i<noofids.length-1;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+(noofids.length-1)+"&";
		
		//now add the checkbox values to be sent to the popup window
		if(document.getElementById(noofids[0]+'-pop').checked == true)
			check1 = noofids[0];
		else
			check1 = "null";
			
		if(document.getElementById(noofids[1]+'-pop').checked == true)
			check2 = noofids[1];
		else
			check2 = "null";
		
		send_data += "check1="+check1+"&check2="+check2;
		//alert("check1 ="+check1+" check2 ="+check2);
		if(check1 != "null" || check2 != "null")
		{
			//ajax request
			$.post('include/cart_processing.php',send_data,
		   	function(data){
			   	//alert(data);
			   	$('#live_cart_bar').html(data);
				alert("item added to the cart!!!");
		   });
		}
	}
}

function wh_add_to_cart(id,q)
{
	send_data = "id="+id+"&quan="+q;
	//alert(send_data);
	//ajax request
	$.post('../include/wh_cart_processing.php',send_data,
	   function(data){
			//alert(data);
			$('#live_cart_bar').html(data);
			alert("item added to the cart!!!");
	   });
}

function dis_add_to_cart(id,q)
{
	send_data = "id="+id+"&quan="+q;
	//alert(send_data);
	//ajax request
	$.post('../include/dis_cart_processing.php',send_data,
	   function(data){
			//alert(data);
			$('#live_cart_bar').html(data);
			alert("item added to the cart!!!");
	   });
}

function hos_add_to_cart(id,q)
{
	send_data = "id="+id+"&quan="+q;
	//alert(send_data);
	//ajax request
	$.post('../include/hos_cart_processing.php',send_data,
	   function(data){
			//alert(data);
			$('#live_cart_bar').html(data);
			alert("item added to the cart!!!");
	   });
}

function popup(page)
{
	current_popup = window.open(page,"NESTAR TESTIMONIALS - Few words from our satisfied customers",'location=no,menubar=no,status=no,titlebar=no,scrollbars=yes,width=1024,height=500,resizable=no');
	screenWidth = screen.width;
	screenHeight = screen.height;
	if(screenWidth > 1024)
	{
		xPoint = (screenWidth - 1024)/2;
		yPoint = (screenHeight - 500)/2;
	}
	else
	{
		xPoint = 0;
		yPoint = 0;
	}
	current_popup.moveTo(xPoint,yPoint);
	current_popup.focus();
	return false;
}

function popup_list(page,t,w,h)
{
	current_popup = window.open(page,t,'location=0,menubar=0,status=0,titlebar=0,scrollbars=1,width='+w+',height='+h+',resizable=0');
	screenWidth = screen.width;
	screenHeight = screen.height;
	if(screenWidth > w)
	{
		xPoint = (screenWidth - w)/2;
		yPoint = (screenHeight - h)/2;
	}
	else
	{
		xPoint = 0;
		yPoint = 0;
	}
	current_popup.moveTo(xPoint,yPoint);
	current_popup.focus();
	return false;
}

function test_message()
{
	name = document.signup_form.customer_name.value;
	email = document.signup_form.customer_emailid.value;
	if(name == "enter your name" || email == "enter your email address" || name == "" || email == "")
	{
		alert("Please enter both the credentials!");
		return false;
	}
	else
	{
		//alert ('i am here');
		i_e = document.getElementById('customer_emailid');
		//alert(i_e.value);
		result = validate_email(i_e);
		//alert(result);
		if(result)
		{
			//put the ajax jquery script here
			$.post('include/general_subscription.php',{c_name:name, c_eid:email},function(data){alert(data);});
			return true;
		}
		else
		{
			i_e.focus();
			return false;
		}
	}
}

function more_info_product_ajax(id)
{
	noofids = id.split('~');
	//alert(id);
	send_data = "";
	if(noofids.length == 1)
	{
		for(i=0;i<noofids.length;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+1;
	}
	else
	{
		for(i=0;i<noofids.length-1;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+(noofids.length-1)+"&";
		
		//now add the checkbox values to be sent to the popup window
		if(document.getElementById(noofids[0]).checked == true)
			check1 = noofids[0];
		else
			check1 = "";
			
		if(document.getElementById(noofids[1]).checked == true)
			check2 = noofids[1];
		else
			check2 = "";
		
		send_data += "check1="+check1+"&check2="+check2;
		//alert("check1 ="+check1+" check2 ="+check2);
	}
	
	//alert(send_data);  //debug
		//ajax request
	$.post('include/product_popup_generator.php',send_data,
		   function(data){
			   $('#pop_this').html(data);
		   });

	
	screenWidth = $(document).width();
	screenHeight = $(document).height();
	xPoint = (screenWidth - 510)/2;
	yPoint = (screenHeight - 530)/2;
	if(screenHeight > 840)
	{
		yPoint = 100;
	}
	//debug
	//alert ("Screen width = "+screenWidth+"\n Screen Height = "+screenHeight+"\n xPoint = "+xPoint+"\n yPoint = "+yPoint);
	
	// hide scrollbars!
	//$('body').css('overflow-y', 'hidden');
	$("#black_board")
	.show()
	.css({'z-index':'2','opacity':'0'})
	.animate({'opacity': '0.6'}, 'slow');
	
	//alert(yPoint);
	$(".product_popup_window").css({left:xPoint,top:yPoint});
	popup_element = document.getElementById('pop_this');
	//popup_element.style.display = "";
	$("<img name='loading' class='abs_in_middle' src='images/loading.gif' width='54' height='70' border='0' alt='loading...' />").appendTo("#pop_this");
	$("#pop_this").show();
	
	//blackout = document.getElementById('blackout');
	return;
	
}

function more_info_product_admin(id)
{
	noofids = id.split('~');
	send_data = "";
	if(noofids.length == 1)
	{
		for(i=0;i<noofids.length;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+1;
	}
	else
	{
		for(i=0;i<noofids.length-1;i++)
		{
			send_data += "id"+(i+1)+"="+noofids[i]+"&";
		}
		send_data += "p_length="+(noofids.length-1);
	}
	
	//alert(send_data);  //debug
	//ajax request
	$.post('../include/product_popup_generator_admin.php',send_data,
		   function(data){
			   $('#pop_this').html(data);
		   });

	
	screenWidth = $(document).width();
	screenHeight = $(document).height();
	xPoint = (screenWidth - 510)/2;
	yPoint = (screenHeight - 530)/2;
	if(screenHeight > 840)
	{
		yPoint = 100;
	}
	//debug
	//alert ("Screen width = "+screenWidth+"\n Screen Height = "+screenHeight+"\n xPoint = "+xPoint+"\n yPoint = "+yPoint);
	
	// hide scrollbars!
	//$('body').css('overflow-y', 'hidden');
	$(".blackout")
	.show()
	.css({'z-index':'2','opacity':'0'})
	.animate({'opacity': '0.6'}, 'slow');
	
	//alert(yPoint);
	$(".product_popup_window").css({left:xPoint,top:yPoint});
	popup_element = document.getElementById('pop_this');
	//popup_element.style.display = "";
	$("<img name='loading' class='abs_in_middle' src='../images/loading.gif' width='54' height='70' border='0' alt='loading...' />").appendTo("#pop_this");
	$("#pop_this").show();
	//blackout = document.getElementById('blackout');
	return;
	
}

function more_info_product(id)
{
	screenWidth = $(document).width();
	screenHeight = $(document).height();
	xPoint = (screenWidth - 510)/2;
	yPoint = (screenHeight - 530)/2;
	if(screenHeight > 840)
	{
		yPoint = 100;
	}
	//debug
	//alert ("Screen width = "+screenWidth+"\n Screen Height = "+screenHeight+"\n xPoint = "+xPoint+"\n yPoint = "+yPoint);
	
	// hide scrollbars!
	//$('body').css('overflow-y', 'hidden');
	$(".blackout")
	.show()
	.css({'z-index':'2','opacity':'0'})
	.animate({'opacity': '0.6'}, 'slow');
	
	//alert(yPoint);
	$(".product_popup_window").css({left:xPoint,top:yPoint});
	popup_element = document.getElementById(id);
	popup_element.style.display = "";
	//blackout = document.getElementById('blackout');
	return;
	
}

function edit_product(id)
{
	screenWidth = $(document).width();
	xPoint = (screenWidth - 750)/2;
	yPoint = 15;
	//debug
	//alert ("Screen width = "+screenWidth+"\n Screen Height = "+screenHeight+"\n xPoint = "+xPoint+"\n yPoint = "+yPoint);
	
	// hide scrollbars!
	//$('body').css('overflow-y', 'hidden');
	$("#black_board")
	.show()
	.css({'z-index':'2','opacity':'0'})
	.animate({'opacity': '0.60'}, 'slow');
	
	//alert(yPoint);
	$(".product_edit").css({left:xPoint,top:yPoint});
	popup_element = document.getElementById(id);
	popup_element.style.display = "";
	return;
	
}

function close_me()
{
	popup_element = document.getElementById('pop_this');
	popup_element.style.display = "none";
	message_window = document.getElementById('black_board');
	message_window.style.display = "none";
	$("#pop_this").html("");
	$(".blackout").hide();
	return;
}

function submit_edit_form(a)
{
	alert(a);
}
 
// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)
{
	alert(responseText);
	//location.reload();
	$("#browse_form").submit();
}

// function to handle delete product request

function delete_product(id,t)  // here is t is payer type
{
	//alert(id);
	if(confirm("Do you really want to delete product with \nPRODUCT_ID: "+id+"\n *** This action will remove the product from the database permanently"))
	{
		

		switch(t)
		{
			case 'online':
				location.href = "browse_product.php?delete='set'&id='"+id+"'";
				break;
			case 'wh':
				location.href = "wh_browse_product.php?delete='set'&id='"+id+"'";
				break;
			case 'dis':
				location.href = "dis_browse_product.php?delete='set'&id='"+id+"'";
				break;
			case 'hos':
				location.href = "hos_browse_product.php?delete='set'&id='"+id+"'";
				break;
			default:
		}
		return true;
	}
	else
	{
		return false;
	}	
}

function validate_empty(a,chain)
{
	e = a.value;
	
	//alert(e); //debug
	if(e == null || e == "")
	{
		alert("Please enter some value. This field cannot be left empty!!!");
		d = typeof chain;
		//alert(d);
		if(d == 'undefined')
			a.focus();
		return false;
	}
	return true;
}

function validate_num(a)
{
	e = a.value;
	//alert(e); //debug
	if(e == null || e == "")
	{
		alert("Please enter some value. This field cannot be left empty!!!");
		a.focus();
		return false;
	}
	if(e != null && isNaN(e))
	{
		alert("Please enter only numbers");
		a.focus();
		return false;
	}
	return true;
}

//use with onfocus event
function clear_this(a,c)
{
		e = a.value;
		if(e == c)
		{
			a.value = "";
			$(a).css('color','grey');
			return false;
		}
		else
			return true;
}

function refill_this(a,c)
{
		e = a.value;
		if(e == "" || e == null)
		{
			a.value = c;
			return true;
		}
		else
			return false;
}

//validating email
function validate_email(a)
{
	e = a.value;
	//debug
	//alert(e);
	
	//set flag
	valid = true;
	
	// check for @ sign
	// not required though as we are using expression
	if(e.indexOf('@') == -1)
	{
		valid = false;
		//alert('@ invalid');
	}
	
	// check for . sign
	// not required though as we are using expression 
	if(e.indexOf('.') == -1)
	{
		valid = false;
		//alert('. invalid');
	}
	
	// check if the string after last . sign is between 3 to 4 char size
	// not required though as we are using expression
	parts = e.split('.');
	noofparts = parts.length;
	lastpart = parts[noofparts-1];
	//alert(lastpart);
	if(lastpart.length > 4)
	{
		valid = false;
		//alert('. invalid');
	}
	
	// check the entered value against allowed expression
	//matchIt = /([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})/.test(e);
	matchIt = /[a-zA-Z0-9_.-]+[@]{1}[a-zA-Z0-9-.]+[.]{1}[a-zA-Z0-9]{2,4}/.test(e);
	if(!matchIt)
	{
		valid = false;	
		//alert('match invalid');
	}
	
	if(e == "")
	{
		valid = true;
	}
	
	//check the value to be valid or invalid
	if(valid == false)
	{
		alert("Please enter a valid email ID");
		a.focus();
		return false;
	}
	else
		return true;
}


function validate_phone(a)
{
	e = a.value;
	//alert(e); //debug

	if(e != null && e != "" && isNaN(e))
	{
		alert("Please enter only numbers");
		a.value = "";
		a.focus();
		return false;
	}
	if(e != null && e != "" && (e.length > 10 || e.length < 8))
	{
		alert("Please enter valid phone number");
		a.value = "";
		a.focus();
		return false;
	}	
	return true;
}

function validate_post(a)
{
	e = a.value;
	//alert(e); //debug

	if(e != null && e != "" && isNaN(e))
	{
		alert("Please enter only numbers");
		a.value = "";
		a.focus();
		return false;
	}
	if(e != null && e != "" && (e.length > 6 || e.length < 4))
	{
		alert("Invalid Postcode");
		a.value = "";
		a.focus();
		return false;
	}	
	return true;
}

function validateNsend()
{
	flag = 'no error';
	i_flag = 'selected';
	inter = $('input:checked').length;

	if(inter == 0)
	{
		$("#info_inter").css('color','red');
		flag = 'error';
		i_flag = "none";
	}
	else
	{
		$("#info_inter").css('color','grey');
	}
	
	if($("#name").val() == "NAME*")
	{
		$("#name").css('color','red');
		flag = 'error';
	}
	else
	{
		$("#name").css('color','grey');
	}
	
	/*if($("#phone").val() == "PHONE")
	{
		$("#phone").css('color','red');
		flag = 'error';
	}
	else
	{
		$("#phone").css('color','grey');
	}*/
	
	if($("#email").val() == "EMAIL*")
	{
		$("#email").css('color','red');
		flag = 'error';
	}
	else
	{
		$("#email").css('color','grey');
	}
	
	if($("#message").val() == "MESSAGE*")
	{
		$("#message").css('color','red');
		flag = 'error';
	}
	else
	{
		$("#message").css('color','grey');
	}
	
	if(flag == 'error')
	{
		e_message = "->Please correct the fields in red";
		if(i_flag == 'none')
		{
			e_message += "\n->Please select atleast one information you would like to receive from us.";
		}
		alert(e_message);
		return false;
	}
	else
	{
		//$ajax
		string = $('form').serialize();
		//alert(string);
		//alert('Thank You! \nYour Message has been successfully send!');
		$.post('include/interest_subscription.php',string,function(data){alert(data);});
		$('form').each(function(){
		this.reset();
		});
		return true;
	}
}


function validateNsend_shipping()
{
	flag = 'no error';
	
	//first name
	a = $("#fname").val();
	//alert(a);
	if(a == "" || !isNaN(a))
	{
		$("#fname").css('color','red');
		$("#fname").val('required');
		flag = 'error';
	}
	
	//last name
	a = $("#lname").val();
	if(a == "" || !isNaN(a))
	{
		$("#lname").css('color','red');
		$("#lname").val('required');
		flag = 'error';
	}
	
	//address line 1
	a = $("#aline1").val();
	if(a == "" || !isNaN(a))
	{
		$("#aline1").css('color','red');
		$("#aline1").val('required');
		flag = 'error';
	}
	
	//suburb
	a = $("#suburb").val();
	if(a == "" || !isNaN(a))
	{
		$("#suburb").css('color','red');
		$("#suburb").val('required');
		flag = 'error';
	}
	
	//postcode
	a = $("#postcode").val();
	if(a == "" || isNaN(a) || a.length < 4)
	{
		$("#postcode").css('color','red');
		$("#postcode").val('required');
		flag = 'error';
	}
	
	//email address
	a = $("#email").val();
	if(a == "")
	{
		$("#email").css('color','red');
		$("#email").val('required');
		flag = 'error';
	}
	
	if(flag == 'error')
	{
		return false;
	}
	else
	{
		//$ajax
		string = $('form').serialize();
		//alert(string);
		//alert('Thank You! \nYour Message has been successfully send!');
		$.post('include/cart_processing.php',string,function(data){
		decision = confirm(data);
		if(decision)
		{
			e = document.getElementById('sh_form');
			frm_elements = e.elements;
			for (i = 0; i < frm_elements.length; i++)
			{
				field_type = frm_elements[i].type.toLowerCase();
				switch (field_type)
				{
				case "text":
				case "password":
				case "textarea":
				case "hidden":
					frm_elements[i].value = "";
					break;
				case "radio":
				case "checkbox":
					if (frm_elements[i].checked)
					{
						frm_elements[i].checked = false;
					}
					break;
				case "select-one":
				case "select-multi":
					frm_elements[i].selectedIndex = 0;
					break;
				default:
					break;
				}
			}
			
			// because of location reload no need of the effects on the form element
			location.reload();
			
			//now slide up the shipping form
			if($.browser.mozilla)
				$('#sform_container').fadeOut('slow');
			else
				$('#sform_container').slideUp('slow');
			
			//change the content for sform controller ie change [-] sign to [+]
			$('#sform_control').html(' [+]');
			
			//now show the proceed button
			$('#proceed').show();

			return true;
		}
		else
			return false;
		});
		
	}
}

function id_check(a,c)
{
	e = a.value;
	if(e != "" || e != null)
	{
		switch(c)
		{
			case 'wh':
			send_data = 'wh_id='+e;
			break;
			case 'dis':
			send_data = 'dis_id='+e;
			break;
			case 'hos':
			send_data = 'hos_id='+e;
		}
		$.post('../include/id_check.php',send_data,
		   function(data){
			   	fragment = data.split("`s`");  //array
				check = fragment[0];
				switch(check)
				{
					case '1':
					{
						alert(fragment[1]);
						break;
					}
					case '2':
					{	
						/*************refill the form**********************/
						//fill the food name
						document.insert_form.food_name.value = fragment[1];
						
						//set the category
						switch(fragment[2])
						{
							case "nestar chocolates":
							{document.insert_form.food_cat.options[1].selected = true;break;}
							case "gluten free ovenly cookies":
							{document.insert_form.food_cat.options[2].selected = true;break;}
							case "coffee addict":
							{document.insert_form.food_cat.options[3].selected = true;break;}
							case "miss sweetie chocolates":
							{document.insert_form.food_cat.options[4].selected = true;break;}
							default:
							{document.insert_form.food_cat.options[0].selected = true;}
						}
						
						//set unit net weight
						document.insert_form.food_size.value = fragment[3];
						
						//set the measurement of unit for weight
						switch(fragment[4])
						{
							case "gram":
							{document.insert_form.food_unit.options[0].selected = true;break;}
							case "kg":
							{document.insert_form.food_unit.options[1].selected = true;break;}
							default:
							{document.insert_form.food_unit.options[0].selected = true;}
						}
	
						//set the value for product image that can be copied later to wholesalers product image folder
						document.insert_form.hidden_image.value = fragment[6];
						document.getElementById("show_on_call").innerHTML="Available Image:"+fragment[6];
						$("#show_on_call").show();
						
						//set the description field
						document.insert_form.food_desc.value = fragment[5];
						break;
					}
					case '3':
					{
						//do nothing
						break;
					}
					default:
					{
						//nothing
					}
				}
		   });
	}
	return;
}

function check_sl()
{
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#sl_user').val();
	if(a == "")
	{
		$('#sl_user').next().html('Please enter username');
		form_error++;
	}
	else
	{
		$('#sl_user').next().html('');
	}
	
	// text field
	a = $('#sl_pass').val();
	if(a == "")
	{
		$('#sl_pass').next().html('Please enter password');
		form_error++;
	}
	else
	{
		$('#sl_pass').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#u_login').serialize();
		//alert(string);
		$.post('include/check_sl_log.php',string,function(data){
		store = data.split(',');
		if(parseInt(store[0]) == 1)
		{
			$('#sl_pass').next().html(store[1]);
		}
		if(parseInt(store[0]) == 2)
		{
			$('#sl_user').next().html(store[1]);
		}
		if(parseInt(store[0]) == 3)
		{
			location.href = "admin/wh_main.php";
		}
		if(parseInt(store[0]) == 4)
		{
			location.href = "admin/dis_main.php";
		}
		if(parseInt(store[0]) == 5)
		{
			alert(store[1]);
		}
		if(parseInt(store[0]) == 6)
		{
			location.href = "admin/hos_main.php";
		}
		});
		return true;
	}
	else
	{
		return false;
	}
}

function change_pass(profile)
{
	//alert("profile="+profile);
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#oldpass').val();
	if(a == "")
	{
		$('#oldpass').next().html('Please enter old password');
		form_error++;
	}
	else
	{
		$('#oldpass').next().html('');
	}
	
	// text field
	a = $('#newpass').val();
	if(a == "")
	{
		$('#newpass').next().html('Please enter new password');
		form_error++;
	}
	else
	{
		if(a.length < 8)
		{
			$('#newpass').next().html('Password should be atleast 8 character long');
			form_error++;
		}
		else
			$('#newpass').next().html('');
	}
	
	// text field
	a = $('#repass').val();
	if(a == "")
	{
		$('#repass').next().html('Please re-enter new password');
		form_error++;
	}
	else
	{
		if(a.length < 8)
		{
			$('#repass').next().html('Password should be atleast 8 character long');
			form_error++;
		}
		else
			$('#repass').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#chpassform').serialize();
		//alert(string);
		$.post('../include/change_pass.php',string,function(data){
		//alert(data);
		store = data.split(',');
		if(parseInt(store[0]) == 1)
		{
			$('#oldpass').next().html(store[1]);
		}
		if(parseInt(store[0]) == 2)
		{
			$('#newpass').next().html(store[1]);
		}
		if(parseInt(store[0]) == 3)
		{
			$('#repass').next().html(store[1]);
		}
		if(parseInt(store[0]) == 4)
		{
			alert('Password Changed!');
			if(profile == 1)
				location.reload();
			else
			{
				//hide the blackboard and the div
				$('#change_pass').hide();
				$('#set_profile').show();
			}
		}
		});
		return true;
	}
	else
	{
		return false;
	}
}

function set_profile()
{
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#cname').val();
	if(a == "")
	{
		$('#cname').next().html('Please enter company name');
		form_error++;
	}
	else
	{
		$('#cname').next().html('');
	}
	
	
	// text field
	a = $('#fname').val();
	if(a == "")
	{
		$('#fname').next().html('Please enter first name');
		form_error++;
	}
	else
	{
		$('#fname').next().html('');
	}
	
	// text field
	a = $('#lname').val();
	if(a == "")
	{
		$('#lname').next().html('Please enter last name');
		form_error++;
	}
	else
	{
		$('#lname').next().html('');
	}
	
	// text field
	a = $('#addr1').val();
	if(a == "")
	{
		$('#addr1').next().html('Please enter address details like street no,street name');
		form_error++;
	}
	else
	{
		$('#addr1').next().html('');
	}
	
	// text field
	a = $('#suburb').val();
	if(a == "")
	{
		$('#suburb').next().html('Please enter suburb');
		form_error++;
	}
	else
	{
		$('#suburb').next().html('');
	}
	
	// text field
	a = $('#state').val();
	if(a == "default")
	{
		$('#state').next().html('Please select your state');
		form_error++;
	}
	else
	{
		$('#state').next().html('');
	}
	
	// text field
	a = $('#post').val();
	if(a == "")
	{
		$('#post').next().html('Please enter postcode');
		form_error++;
	}
	else
	{
		if(a.length > 4)
		{
			$('#post').next().html('Invalid postcode');
			form_error++;
		}
		else
			$('#post').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#setprofileform').serialize();
		//alert(string);
		$.post('../include/set_profile.php',string,function(data){
		alert(data);
		location.reload();
		});
		return true;
	}
	else
		return false;
}


function add_store(cat)
{
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#cname').val();
	if(a == "")
	{
		$('#cname').next().html('Please enter company name');
		form_error++;
	}
	else
	{
		$('#cname').next().html('');
	}
	
	// text field
	a = $('#addr1').val();
	if(a == "")
	{
		$('#addr1').next().html('Please enter address details like street no,street name');
		form_error++;
	}
	else
	{
		$('#addr1').next().html('');
	}
	
	// text field
	a = $('#suburb').val();
	if(a == "")
	{
		$('#suburb').next().html('Please enter suburb');
		form_error++;
	}
	else
	{
		$('#suburb').next().html('');
	}
	
	// text field
	a = $('#state').val();
	if(a == "default")
	{
		$('#state').next().html('Please select your state');
		form_error++;
	}
	else
	{
		$('#state').next().html('');
	}
	
	// text field
	a = $('#post').val();
	if(a == "")
	{
		$('#post').next().html('Please enter postcode');
		form_error++;
	}
	else
	{
		if(a.length > 4)
		{
			$('#post').next().html('Invalid postcode');
			form_error++;
		}
		else
			$('#post').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#setprofileform').serialize();
		//alert(string);
		$.post('../include/sl_add_store.php',string,function(data){
			piece = data.split('~~~');
			//piece 0 is success/failure message
			message = piece[0];
			//piece 1 is postcode
			postcode = piece[1];
			//piece 2 is suburb
			suburb = piece[2];
			//piece 3 is addr query
			addr_query = piece[3];
			//debug:alert(addr_query);
			if(piece[0] == 'success')
			{
  				if(geocoder)
				{	
					//this method retrieves lat and lon value for supplied address using google maps geocoder API service
					geocoder.geocode( { 'address': addr_query}, function(results, status) {
							if (status == google.maps.GeocoderStatus.OK) {
							store = String(results[0].geometry.location);
							sLength = store.length;
							trim = store.substring(1,sLength-1);
							points = trim.split(',');
							feed = 'lat='+points[0]+'&lon='+points[1]+'&sub='+suburb+'&post='+postcode;
							//debug:alert(feed);
								//use post method to feed all these details in the table
								$.post('../include/e_d_store.php',feed,function(res){
									ack = res;
									alert('Store Added!');
									//debug:alert(ack);
									redirect(cat);
								});
							} 
							else 
							{
								alert("Geocode was not successful for the following reason: " + status);
							}
						});
				}
			}
			
		});
		return true;
	}
	else
		return false;
}

function redirect(cats){
	if(cats == 'wh')
	{
		location.href = "wh_add_store.php#store_anchor";
		location.reload();
	}
	else
	{
		location.href = "dis_add_store.php#store_anchor";
		location.reload();
	}
}

function delete_sl_store(stno)
{
	//alert('i am in');
	string = "storeno="+stno;
	//alert(string);
	res = confirm('Do you really want to delete the store?');
	if(res)
	{
		//alert("in2");
		$.post('../include/e_d_store.php',string,function(data){
			alert(data);
			location.reload();
		});
		return true;
	}
	else
	{
		return false;
	}
}

function edit_sl_store(stno,cat)
{
	//alert('i am in');
	string = "editno="+stno+"&cat="+cat;
	//alert(string);

	$.post('../include/e_d_store.php',string,function(data){
		//alert(data);
		$('#edit_window').html(data);
		//center the box on the screen
		screenWidth = $(document).width();
		xPoint = (screenWidth - 700)/2;
		yPoint = $(document).scrollTop()+25;
		//debug
		//alert ("Screen width = "+screenWidth+"\n Screen Height = "+screenHeight+"\n xPoint = "+xPoint+"\n yPoint = "+yPoint);
		
		// hide scrollbars!
		//$('body').css('overflow-y', 'hidden');
		$(".blackout")
		.show()
		.css({'z-index':'2','opacity':'0'})
		.animate({'opacity': '0.60'}, 'slow');
		
		//alert(yPoint);
		$("#edit_window").css({left:xPoint,top:yPoint});
		$('#edit_window').show();
		return;
	});
}

function sl_user_delete(a,c)
{
	pa = a.replace('&','-^-');
	//alert(pa);
	string = 'sl_id=\"'+pa+'\"&cat='+c+'&del=1';
	//alert(string);
	response = confirm('Do you really want to delete this user?\nWARNING: This will completely remove all information about the user from the database!!!');
	if(response)
	{
		$.post('../include/e_d_sl_users.php',string,function(data){
			alert(data);
			location.reload();
		});
		return true;
	}
	else
	{
		return false;
	}
}

function sl_user_change_mail(a,c)
{
	pa = a.replace('&','-^-');
	//alert(pa);
	url = '../include/change_sl_email.php?user=\"'+pa+'\"&cat='+c;
	//alert(url);
	loaded_overlay('cp','fixedOverlay_s1',url,500,300,'fixed','black_board');
	return;
}

function display_pass_box(a,c)
{
	$("#admin").val(a);
	$("#cat").val(c);
	$("#black_board")
	.show()
	.css({'z-index':'2','opacity':'0'})
	.animate({'opacity': '0.60'}, 'slow');
	
	//center the box on the screen
	screenWidth = document.width;
	//this is the overhead that most of the browsers have
	toolbarspace = 70;  //asuming around 50 to 100
	screenHeight = screen.height - toolbarspace;
	
	//dW = document.width;
	//dH = document.height;
	//alert("screen height = "+screenHeight+" and screen width = "+screenWidth+"\n"+"document height = "+dH+"document width = "+dW);
	xPoint = (screenWidth - 600)/2;
	yPoint = $(document).scrollTop()+(screenHeight - 350)/2;
	
	//alert(yPoint);
	$("#change_pass").css({left:xPoint,top:yPoint});
	$('#change_pass').show();
}

function sl_pass_reset()
{
	form_error = 0;
	
	// text field
	a = $('#newpass').val();
	if(a == "")
	{
		$('#newpass').next().html('Please enter new password');
		form_error++;
	}
	else
	{
		if(a.length < 8)
		{
			$('#newpass').next().html('Password should be atleast 8 character long');
			form_error++;
		}
		else
			$('#newpass').next().html('');
	}
	
	// text field
	a = $('#repass').val();
	if(a == "")
	{
		$('#repass').next().html('Please re-enter new password');
		form_error++;
	}
	else
	{
		if(a.length < 8)
		{
			$('#repass').next().html('Password should be atleast 8 character long');
			form_error++;
		}
		else
			$('#repass').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $("#chpassform").serialize();
		//alert(string);
		$.post('../include/change_pass.php',string,function(data){
			//alert(data);
			store = data.split(',');
			if(parseInt(store[0]) == 3)
			{
				$('#repass').next().html(store[1]);
			}
			if(parseInt(store[0]) == 4)
			{
				alert(store[1]);
				location.reload();
			}
		});
		return true;
	}
	else
	{
		return false;
	}
}

function check_stores()
{
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#store_post').val();
	if(a == "" || a == "postcode")
	{
		b = $('#store_sub').val();
		if(b == "" || b == "suburb")
		{
			$('#store_post').next().html('Please enter the postcode');
			form_error++;
		}
		else
			$('#store_post').next().html('');
	}
	else
	{
		if(isNaN(a))
		{
			if(a != 'postcode')
			{
				$('#store_post').next().html('No alpabhets allowed in postcode');
				form_error++;
			}
		}
		else
		{
			if(a.length != 4)
			{
				$('#store_post').next().html('Invalid postcode');
				form_error++;
			}
			else
				$('#store_post').next().html('');
		}
	}
	
	// text field
	a = $('#store_sub').val();
	if(a == "" || a == "suburb")
	{
		b = $('#store_post').val();
		if(b == "" || b == "postcode")
		{
			$('#store_sub').next().html('Please enter the Suburb');
			form_error++;
		}
		else
			$('#store_sub').next().html('');
	}
	else
	{
		$('#store_sub').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#f_store').serialize();
		//alert(string);
		popup_list('include/check_stores.php?'+string,'Our Shops',970,567);
		return true;
	}
	else
	{
		return false;
	}
}


/* this function is used to open a lightbox window with the provided content c stands for content div, w and h stantds for width and height of the content and b stands for semi-transparent background */
function open_lightbox(c,w,h,b,p)
{
	$('#'+b)
	.show()
	.css({'z-index':'4','opacity':'0'})
	.animate({'opacity': '0.60'}, 'slow');
	
	screenWidth = screen.width;
	//alert('screen width = '+screenWidth+' \n screen height = '+screenHeight);
	docWidth = $(document).width();
	docHeight = $(document).height();
	//alert('document width='+docWidth+'document height='+docHeight);
	screenHeight = screen.height;
	if(docWidth > w)
	{
		xPoint = (docWidth - w)/2;
		if(p == '' || p == null)
			yPoint = $(document).scrollTop() + (screenHeight - h)/2;
		if(p == 'fixed')
			yPoint = ((screenHeight - 50) - h)/2;	// here 50 offset is introduced considering the browser's toolbar height
	}
	else
	{
		xPoint = 0;
		yPoint = 0;
	}
	//alert('xpoint='+xPoint+' and ypoint ='+yPoint);
	$("#"+c)
	.css({left:xPoint,top:yPoint})
	.show();
}

function close_lightbox(c,b,e)
{
	if(e != "" && e != null)
	{
		$(e).parent().parent().remove();
	}
	if(c != 'unknown')
		$("#"+c).hide();
	$("#"+b).hide();
	return;
}

function check_n_send()
{
	//set error flag
	form_error = 0;
	
	// text field
	a = $('#f_user').val();
	if(a == "")
	{
		$('#f_user').next().html('Please enter username');
		form_error++;
	}
	else
	{
		$('#f_user').next().html('');
	}
	
	if(form_error == 0)
	{
		string = $('#sendpass').serialize();
		//alert(string);
		$.post('include/check_sl_log.php',string,function(data){
		store = data.split(',');
		if(parseInt(store[0]) == 0)
		{
			$('#f_user').next().html(store[1]);
		}
		if(parseInt(store[0]) == 1)
		{
			$('#forgot').next().html(store[1]);
		}
		if(parseInt(store[0]) == 2)
		{
			$('#f_user').next().html(store[1]);
		}
		});
		return true;
	}
	else
	{
		return false;
	}
}

function createBubbleContent(bubbleId,bubbleClass,bubbleContent)
{
	$('<div></div>')
	.attr('id',bubbleId)
	.addClass(bubbleClass)
	.html(bubbleContent)
	.hide()
	.appendTo('body');
}

function destroyBubbleContent(bubbleId)
{
	$('#'+bubbleId).remove();
}
//*****************************************************************************************************************************//
// This is a generalized function to add a bubble to an element in case of the event triggered on that element 
// calling procedure "bubble(this,'shipCalBubble',vertical offset value,horizontal offset value,z-index value,'toggle');"
// The first parameter is the eventhandler i.e. this
// The second parameter is the id of the content bubble i.e. the element containing the content to be displayed inside the bubble
// 3rd and 4th parameter sets the vertical and horizontal offset of the bubble relative to the element on which event is performed
// 5th is z-index of the bubble  ::::: optional
// 6th is for display effects, default is toggling effect; can take 'slide','fade(slow|normal|fast)'  :::::: optional
// ****************************************************************************************************************************//
function bubble(eventHandler,contentBubble,verticalOffset,horizontalOffset,zIndex,toggleEffects)
{
	var offset = $(eventHandler).offset();
		//position for message
		info_top = offset.top + verticalOffset;
		info_left = offset.left + horizontalOffset;
		//set what should happens when the zindex value is not given
		if(zIndex == null || zIndex == 0)
		{
			zIndex = 5;
			//alert('box width is not set');
		}
		$('#'+ contentBubble).css({position:'absolute', left:info_left, top:info_top,'z-index':zIndex});
		
		//set what should happen when toggleEffect value is not valid
		switch(toggleEffects)
		{
			case 'slide':
			{
				$('#'+contentBubble).slideToggle();
				break;
			}
			case 'fade(slow)':
			{
				$('#'+contentBubble).toggle('slow');
				break;
			}
			case 'fade(normal)':
			{
				$('#'+contentBubble).toggle('normal');
				break;
			}
			case 'fade(fast)':
			{
				$('#'+contentBubble).toggle('fast');
				break;
			}
			default:
			{$('#'+ contentBubble).toggle();}
		}
		
		
}

// this function adds the wholesaler/distributor to the POWER table here e is this and t is [wh|dis]
function allow_mpo(e,t)
{
	if(e.checked == true)
	{
		allowed = 1;
	}
	else
		allowed = 0;
	
	a=e.value;
	pa = a.replace('&','-^-');
	//alert(pa);
	send_data = "user=\""+pa+"\"&allowed="+allowed;
	//alert(send_data);
	$.post('../include/e_d_sl_users.php',send_data,function(data){
		alert(data);
	});
	return false;
}

//************************************************************************************************************************//
// This is a generalized function written to handle lightbox popping with content loaded in it from remote document.
// overlay_src_url should contain some send data incase some processing is required.
// overlay_position can be either absolute or fixed
// This function also used open_lightbox function inside it so it is very important to include open_lightbox function
// For this function to work properly
//*************************************************************************************************************************//
function loaded_overlay(overlay_id,overlay_class,overlay_src_url,overlay_width,overlay_height,overlay_position,shadow_id)
{
		//create the div, fill it with content and append it to the body
		$('<div id = '+overlay_id+'><div id="lo_close_container"></div><div id="lo_loading_space"></div><div id="lo_return_message_space" style="font-size:12px; color:#2E87C8; font-family:arial; padding-top:15px; "></div></div>')
		.hide()
		.appendTo('body');
		
		//now append the close button to the overlay content
		$('<div style="position:absolute; top:5px; right:5px; cursor:pointer; z-index:10; color:#000; font-size:11px;" onClick="javascript:$(\'#'+overlay_id +'\').hide();$(\'#'+shadow_id +'\').hide();$(\'#'+overlay_id +'\').remove();$(\'body\').css(\'overflow-y\',\'auto\');">close &times;</div>').appendTo('#lo_close_container');
		
		$('#lo_loading_space')
		.load(overlay_src_url);
		
		$('#'+overlay_id)
		.addClass(overlay_class);
		
		//hide scroll bar
		$('body').css('overflow-y','hidden');
		
		//bubble(e,quan_bubble,0,40,12); /* calling procedure "bubble(this,'shipCalBubble',vertical offset value,horizontal offset value,z-index value,'toggle');" */
		open_lightbox(overlay_id,overlay_width,overlay_height,shadow_id,overlay_position);
		return;
}

function show_advert()
{
		res = checkCookie('nestar_ad_seen');
		if(!res)
		{
			loaded_overlay('advert_popup','advert_wrapper','advert/nestar_popup_add.html',700,400,'','shadow');
			setCookie('nestar_ad_seen','yes',1);
		}
		return;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie(c_name)
{
	var username=getCookie(c_name);
	if (username!=null && username!=""){
  		//alert("Ad already seen once in a day!");
  		return 1;
  	}
	else {return 0;}
}


