// JavaScript Document

function handle_selected_action(modeobj,obj,action)
{
	var mode = modeobj.value;		
	switch(mode)
	{
		case 'mass_delete':
			confirm_delete_sel(obj,action);
		break;
		
		case 'mass_restore':
			confirm_restore_sel(obj,action);
		break;
	}
	
	modeobj.selectedIndex="";
}

function handle_submit(formname,action,id)
{
	var obj = document.getElementById(formname);	
	if(obj != "" || obj != "undefined")
	{
		obj.action = action;
		if(isNaN(id) == false)
		{
			obj.id.value = id;
		}
			
		obj.submit();
	}
}

function handle_submit_by_mode(formname,action,id)
{	
	var obj = document.getElementById(formname);	
	
	if(obj != "" || obj != "undefined")
	{
		obj.mode.value = action;
		if(isNaN(id) == false)
		{
			obj.id.value = id;
		}
			
		obj.submit();
	}
}

function handle_redirect(url)
{
	if(url != "")
		window.location = url;
}

function confirm_delete(url){
var msg = "[ WARNING : Sending Record/s to Trash] \n\n Are you sure you want to send this item to trash?";
var conf = confirm(msg);

	if(conf)
	{
		handle_redirect(url);		
	}
}

function delete_perm(url){
var msg = "[ WARNING : Deleting Record/s Permanently] \n\n Are you sure you want to delete this record permanently?";
var conf = confirm(msg);

	if(conf)
	{
		handle_redirect(url);		
	}
}


function confirm_approve(obj,action){
	var id_arr = new Array();
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) 
	{
		if (allInputs[i].type == 'checkbox' && allInputs[i].name.substring(0,11) == "tablechoice") 
		{
			id_arr.push(allInputs[i]);
		}
	}
	if (isOneChecked(id_arr) == true)
	{
		var msg = "[ WARNING : Approving Record/s ] \n\n Are you sure you want to approve the Record/s?";
		var conf = confirm(msg);
		if(conf) 
		{
			handle_submit(obj, action);
		}
		else 
		{
			return false;
		}
	}
	else
	{
		alert("Please select the record to approve");
		return false;
	}
}

function confirm_delete_submit(formname,action,id){
var msg = "[ WARNING : Sending Record/s to Trash] \n\n Are you sure you want to send this item to trash?";
var conf = confirm(msg);

	if(conf)
	{
		handle_submit(formname,action,id);
	}
}


function confirm_send_new_password(formname,action,id){
var msg = "[ WARNING : Sending New Password ] \n\n Are you sure you want to send a new password?";
var conf = confirm(msg);
	if(conf)
	{
		handle_submit(formname,action,id);	
	}
}

function confirm_restore(url)
{
	var msg = "[WARNING] Are you sure you want to restore the record?";
	//var msg = "[ WARNING : Deleting Record/s ] \n\n Are you sure you want to Restore the selected Record/s?";
	var conf = confirm(msg);

	if(conf)
	{
		handle_redirect(url);
	}
}


function confirm_restore_submit(formname,action,id)
{
	var msg = "[WARNING] Are you sure you want to restore the record?";
	//var msg = "[ WARNING : Deleting Record/s ] \n\n Are you sure you want to Restore the selected Record/s?";
	var conf = confirm(msg);

	if(conf)
	{
		handle_submit(formname,action,id);
	}
}

function confirm_restore_sel(obj,action)
{
	var id_arr = new Array();
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) 
	{
		if (allInputs[i].type == 'checkbox' && allInputs[i].name.substring(0,11) == "tablechoice") 
		{
			id_arr.push(allInputs[i]);
		}
	}
	if (isOneChecked(id_arr) == true)
	{
		var msg = "[ WARNING : Restoring Record/s ] \n\n Are you sure you want to retore the selected Record/s?";
		var conf = confirm(msg);
		if(conf) 
		{			
			handle_submit(obj, action);
		}
		else 
		{
			return false;
		}
	}
	else
	{
		alert("Please select the record to restore");
		return false;
	}
}

function confirm_delete_sel(obj,action)
{
	var id_arr = new Array();
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) 
	{
		if (allInputs[i].type == 'checkbox' && allInputs[i].name.substring(0,11) == "tablechoice") 
		{
			id_arr.push(allInputs[i]);
		}
	}
	if (isOneChecked(id_arr) == true)
	{
		var msg = "[ WARNING : Deleting Record/s ] \n\n Are you sure you want to send the selected Record/s to trash?";
		var conf = confirm(msg);
		if(conf) 
		{
			handle_submit(obj, action);
		}
		else 
		{
			return false;
		}
	}
	else
	{
		alert("Please select the record to delete");
		return false;
	}
}


function confirm_update_sel(obj,action)
{
	var id_arr = new Array();
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) 
	{
		if (allInputs[i].type == 'checkbox' && allInputs[i].name.substring(0,11) == "tablechoice") 
		{
			id_arr.push(allInputs[i]);
		}
	}
	if (isOneChecked(id_arr) == true)
	{
		var msg = "[ WARNING : Updating Record/s ] \n\n Are you sure you want to update the selected Record/s?";
		var conf = confirm(msg);
		if(conf) 
		{
			handle_submit(obj, action);
		}
		else 
		{
			return false;
		}
	}
	else
	{
		alert("Please select the record to update");
		return false;
	}
}

function isOneChecked(CheckboxArray) 
{
	for (var i = 0; i < CheckboxArray.length; i++) 
	{
		if (CheckboxArray[i].checked)
		{
			return true;
		}
	}
	return false;
}

// Active/Inactive record
function change_active(url ,value)
{
        
	    if( value == 0 )
		{ 
        var msg = "[WARNING] Are you sure you want to make this record inactive?";
		}
		else
		{
		var msg = "[WARNING] Are you sure you want to make this record active?";
		}
		
		
		if( confirm(msg) )
		{
			handle_redirect(url);		 
		}
}

// Active/Inactive record
function change_hide_client(url ,value)
{
        
	    if( value == 0 )
		{ 
        var msg = "[WARNING] Are you sure you want to make this page visible to client?";
		}
		else
		{
		var msg = "[WARNING] Are you sure you want to make this page invisible to client?";
		}
		
		
		if( confirm(msg) )
		{
			handle_redirect(url);		 
		}
}
// featured / remove featured
function change_featured(url ,value)
{
        
	    if( value == 0 )
		{ 
        var msg = "[WARNING] Are you sure you want to make this record non featured?";
		}
		else
		{
		var msg = "[WARNING] Are you sure you want to make this record featured?";
		}
		
		
		if( confirm(msg) )
		{
			handle_redirect(url);		 
		}
}

// featured / remove featured
function change_approved(url ,value)
{
        
	    if( value == 0 )
		{ 
        var msg = "[WARNING] Are you sure you want to make this record unapproved?";
		}
		else
		{
		var msg = "[WARNING] Are you sure you want to make this record approved?";
		}
		
		
		if( confirm(msg) )
		{
			handle_redirect(url);		 
		}
}



// Change the status
function change_tstatus(url)
{
		var msg = "[WARNING] Are you sure you want to change the status?";

		if( confirm(msg) )
		{
			handle_redirect(url);		 
		}
}

function change_active_submit(formname,action,id,value)
{
        
	    if( value == 0 )
		{ 
        var msg = "[WARNING] Are you sure you want to make this record inactive?";
		}
		else
		{
		var msg = "[WARNING] Are you sure you want to make this record active?";
		}
		
		
		if( confirm(msg) )
		{
			handle_submit(formname,action,id);	 
		}
}

// fade in & fade out
function show_div_info_slow()
{
	//window.onload = function()
	//{
		//options: slow, fast and time
		$("div#div_info").show("slow");
	//}	
	setTimeout("hide_div_info_slow()",20000);
}
function hide_div_info_slow()
{
	$("div#div_info").hide("slow");	
}

function show_div_msg_slow()
{	
	$("div#div_msg").show("slow");	
	setTimeout("hide_div_msg_slow()",20000);
}

function hide_div_msg_slow()
{
	$("div#div_msg").hide("slow");	
}

function show_div_error_slow()
{
	//window.onload = function()
	//{
		//options: slow, fast and time	
		$("div#div_error").show("slow");
	//}
	setTimeout("hide_div_error_slow()",20000);
}

function hide_div_error_slow()
{
	$("div#div_error").hide("slow");	
}
/*********************************************************************************/
//This functions are used for changing the rank
function change_rank(id,crank,total,formname,action) 
{ 		
	var form_obj = document.getElementById(formname);
	if(form_obj != "" || form_obj != "undefined")
	{
		if(total > 1)
		{
			var nrank = prompt("Please Enter Rank Value [ 1 - "+total+" ] ",""); 
			if(ver_rank(nrank,crank,total))
			{ 
				if(nrank > crank)
				{ 			
				   form_obj.r_mode.value='decrease'; 
				} 
				else
				{ 
				   form_obj.r_mode.value='increase'; 
				}
				form_obj.mode.value='change_rank'; 
				form_obj.new_rank.value=nrank; 
				form_obj.curr_rank.value=crank; 					
				form_obj.id.value=id; 
				form_obj.action = action;
				form_obj.submit(); 
			}
			
		} 
		else
		{ 
			alert("Only 1 Record Present Can't change rank."); 
		} 
	}
}

function ver_rank(nr,cr,tr)
{    
   if(isNaN(nr))
   { 
      alert("Please enter only numbers"); 
      return false; 
   }
   else
   {
   		var str = new String(nr);
		arr = str.split(".");
		
		if( arr.length > 1 )
		{
			alert("Only integer values supported");
			return false;
		}
   }
   if(nr == '')
   { 
      alert("Please enter rank"); 
      return false; 
   } 
   if(nr == cr)
   { 
      alert("Current & New rank is same"); 
      return false; 
   } 
   if(nr == null){
   		return false; 
   }
   if(nr<1)
   {
	  alert("New rank cannot be less than one"); 
      return false; 
   }
   
   if(Number(nr)>Number(tr))
   {
	  alert("New rank cannot be more than total rank"); 
      return false; 
   } 
   
   return true; 
}




/*********************************************************************************/
/**
	AJAX function
	@author  - Dhaval K 16th Jan, 2009
	@param   - processing script URL
	@param   - form name to be posted
	@param   - div id where contents loaded
	@example - ajaxCall("includes/searchProcessor.php", "frmName", "divid");
 */
function ajaxCall(ajax_url, frm, div, data_values)
{
		
   var formValues = "";
   formValues = $('form#'+frm).serializeArray();
   $.ajax({
   type: "POST",
   url: ajax_url,
   data: formValues,
   beforeSend: function(){ 
			{    
//			 document.getElementById(div).innerHTML = '<img src="'+base_url+'images/ajax-loader.gif" />';
			}
		},
   success: function(msg){ 
			 $('#'+div).html(msg);
		   }	
	   });
}

/*********************************************************************************/
/**
	AJAX function
	@author  - Archana Naik 16th Jan, 2009
	@param   - processing script URL	
	@param   - banner id to be pasased
	@param   - ajax url to be pasased
	@example - update_click("ajax_call/update_click", "bannerid");
 */
function update_click(ajax_url, data_values, url)
{

    var formValues = "";
   	formValues = data_values;
	$.ajax({		
		type: "POST",
		url: ajax_url,
		data: formValues ,
		 success: function(url){ 
			 	window.location = url;
		   }	
   });
}
 
 
 
 
/**
	AJAX function pass data
	@author  - Dhaval K 16th Jan, 2009
	@param   - processing script URL
	@param   - form name to be posted
	@param   - div id where contents loaded
	@example - ajaxCall("includes/searchProcessor.php", "frmName", "divid");
 */
function ajaxCallPassData(ajax_url, div, data_values)
{
		
   var formValues = "";
   formValues = data_values;
   
   $.ajax({
   type: "POST",
   url: ajax_url,
   data: formValues,
   beforeSend: function(){ 
			{    
			 document.getElementById(div).innerHTML = '<img src="images/ajax-loader.gif" />';
			}
		},
   success: function(msg){ 
			 $('#'+div).html(msg);
		   }	
	   });
}


		
/**		
function confirm_send_reply(url){
var msg = "[ WARNING : Sending New Password ] \n\n Are you sure you want to send a reply?";
var conf = confirm(msg);
	if(conf)
	{
		handle_redirect(url);		
	}
}**/

function confirm_send_reply(module,submit_name){
var msg = "[ WARNING : Sending Reply ] \n\n Are you sure you want to send a reply?";
var conf = confirm(msg);
	if(conf)
	{
		handle_submit(module,submit_name);			
	}
}

function dropDownSelect(selectID,optionValue)
{
   selObj = document.getElementById(selectID);
   for(i=0;i<selObj.length;i++)
   {
        if(selObj.options[i].value == optionValue) selObj.options[i].selected = true;
   } 
}//dropDownSelect()






//added for products preview

//<![CDATA[

function print_friendly()
{
var sOption="toolbar=no,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=900,height=600,left=100,top=25"; 

   var sWinHTML = document.getElementById('print_friendly_div').innerHTML; 
   
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><link href='"+base_url+"/css/frontend/main.css' rel='stylesheet'><body onload=document.getElementById('print_wrap').style.display='block';window.print();>"); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('<\/body><\/html>'); 
       winprint.document.close(); 
       winprint.focus(); 

}
//]]>

    
//added for the pagination of image gallery -   start
 $(document).ready(function(){  


        //added for the onfocus of image gallery - start
        $('.big_img').hover(
        function(){
            $('.lt_arr, .rt_arr').show()                  
        },
        function(){
        $('.lt_arr, .rt_arr').hide();      
        });
        //added for the onfocus of image gallery - end
     
         //added for showing hiding divs -start
        $('#image_gallery').click(function(){
            $('#general_desc, #technical_details, #videos, #downloads, #related_products').css('display', 'none');
            $('#content').css('display', 'block');
        });
        
        $('.gen').click(function(){
            $('#content, #technical_details, #videos, #downloads, #related_products').css('display', 'none');
            $('#general_desc').css('display', 'block');
        });
        
         $('.td').click(function(){
            $('#content, #general_desc,#videos, #downloads,#related_products').css('display', 'none');
            $('#technical_details').css('display', 'block');
        });
        
        $('.arp').click(function(){
            $('#content, #general_desc,#videos , #downloads, #technical_details').css('display', 'none');
            $('#related_products').css('display', 'block');
        });
        
         $('.dl').click(function(){
            $('#content, #general_desc,#videos, #technical_details, #related_products').css('display', 'none');
            $('#downloads').css('display', 'block');
        });
        
        $('.vid').click(function(){
            $('#content, #general_desc,#downloads, #technical_details, #related_products').css('display', 'none');
            $('#videos').css('display', 'block');
        });
        //added for showing hiding divs -end
     
     
     var globalIndex = 0;
     
      $('.thumb_img a img').click(function(){
        var str = $(this).attr('src');
        globalIndex = $('.thumb_img a img').index(this);
        var src = str.replace('thumb', 'normal');
        $('#gallery_image').attr('src', src);
        //$('#enlarge_image').attr('href', src);
        
        
        
        var rel_id =  $(this).parent().attr('rel');
        $('#enlarge_image').attr('rel', rel_id);
        
   
        
     });
     
     $('#enlarge_image').click(function(){
       $('#'+$(this).attr('rel')).click();
     });
     
     $('.rt_arr').click(function(){
         imgVal = $('#content p img').eq(++globalIndex).attr('src');
         if(imgVal == 'undefined' || imgVal == '' || imgVal == undefined)
         {
            globalIndex--;
            return false;
         }
         var src = imgVal.replace('thumb', 'normal');
         $('#gallery_image').attr('src',src); 
         //$('#enlarge_image').attr('href', src);
     });
     
     $('.lt_arr').click(function(){
         imgVal = $('#content p img').eq(--globalIndex).attr('src');
         
         if(imgVal == 'undefined' || imgVal == '' || imgVal == undefined)
         {
             globalIndex++;
         
            return false;
         }
         var src = imgVal.replace('thumb', 'normal');
         $('#gallery_image').attr('src',src); 
         //$('#enlarge_image').attr('href', src);
     });
     
     
     //how much items per page to show  
     var show_per_page = 9;  
 
     //getting the amount of elements inside content div  
     var number_of_items = $('#content > p').size();  
 
     //calculate the number of pages we are going to have  
     var number_of_pages = Math.ceil(number_of_items/show_per_page);  
 
     //set the value of our hidden input fields  
     $('#current_page').val(0);  
     $('#show_per_page').val(show_per_page);  
   
     //now when we got all we need for the navigation let's make it '  
   
     /* 
     what are we going to have in the navigation? 
         - link to previous page 
         - links to specific pages 
         - link to next page 
     */  
     
     var navigation_html = '';  
     var current_link = 0;  
     while(number_of_pages > current_link){  
         navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';  
         current_link++;  
     }  
   
     $('#page_navigation').html(navigation_html);  
   
     //add active_page class to the first page link  
     $('#page_navigation .page_link:first').addClass('active_page');  
   
     //hide all the elements inside content div  
     $('#content > p').css('display', 'none');  
   
     //and show the first n (show_per_page) elements  
     $('#content > p').slice(0, show_per_page).css('display', 'block');  
   
 });  
   
 function previous(){  
   
     new_page = parseInt($('#current_page').val()) - 1;  
     //if there is an item before the current active link run the function  
     if($('.active_page').prev('.page_link').length==true){  
         go_to_page(new_page);  
     }  
   
 }  
   
 function next(){  
     new_page = parseInt($('#current_page').val()) + 1;  
     //if there is an item after the current active link run the function  
     if($('.active_page').next('.page_link').length==true){  
         go_to_page(new_page);  
     }  
   
 }  
 function go_to_page(page_num){  
     //get the number of items shown per page  
     var show_per_page = parseInt($('#show_per_page').val());  
   
     //get the element number where to start the slice from  
     start_from = page_num * show_per_page;  
   
     //get the element number where to end the slice  
     end_on = start_from + show_per_page;  
   
     //hide all children elements of content div, get specific items and show them  
     $('#content > p').css('display', 'none').slice(start_from, end_on).css('display', 'block');  

     /*get the page link that has longdesc attribute of the current page and add active_page class to it 
     and remove that class from previously active page link*/  
     $('.page_link[longdesc=' + page_num +']').addClass('active').siblings('.active').removeClass('active');  

   
     //update the current page input field  
     $('#current_page').val(page_num);  
 } 
//added for the pagination of image gallery -   start