// JavaScript Document


function forget_password(email,action)
{
	var action = action;
	if(action=='forgotpass')
	{
			var email = email;
			
			var url = 'ajax.php?do=forget_password&email='+email+'&action='+action+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				$('fp_outer').show().update('please wait...');
				
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				$('fp_outer').innerHTML = dr;
			},
			onFailure: function(transport)
			{
				
			},
			onException: function(err)
			{
				
			}
			});
	}
}

function ChangeStatus(id ,status)
{
	var url = 'ajax.php?do=ChangeStatus&id='+id+'&status='+status+'&rnd='+Math.random();
	//alert(url);
	new Ajax.Request(url,{
     method: 'get',
     onLoading: function(transport)
     {
		 //	
     },
	 onSuccess: function(transport)
     {
		var dr = transport.responseText;
		$('status').innerHTML = dr;
		setTimeout("window.location.href = 'task_assignment.php';", 2000);
	 },
     onFailure: function(transport)
     {
         // when the request fails
         alert('The request failed..');
     },
     onException: function(err)
     {
         // When an exception is encountered while executing the callbacks
         alert('Exception');
     }
     });

}



function on_change()
{
	if($('chk_cus_del_info').checked==true)
	{
		//$('chk_cus_del_info').checked = true;
		//$j('#c_d_i').slideUp('slow');
		$('inp_delivery_cust_name').value = '';
		$('inp_delivery_cust_address').value = '';
		$('inp_delivery_cust_tel').value = '';
		$('inp_delivery_zip_code').value = '';
		$('inp_delivery_cust_state').value = '';
		$('inp_delivery_cust_city').value = '';	
		
		$('inp_delivery_cust_name').value = $('inp_billing_cust_name').value;
		$('inp_delivery_cust_address').value = $('inp_billing_cust_address').value;
		$('inp_delivery_cust_tel').value = $('inp_billing_cust_tel').value;
		$('inp_delivery_zip_code').value = $('inp_billing_zip_code').value;
		$('inp_delivery_cust_state').value = $('inp_billing_cust_state').value;
		$('inp_delivery_cust_city').value = $('inp_billing_cust_city').value;
		
		$('delivery_cust_name').value = $('inp_billing_cust_name').value;
		$('delivery_cust_address').value = $('inp_billing_cust_address').value;
		$('delivery_cust_tel').value = $('inp_billing_cust_tel').value;
		$('delivery_zip_code').value = $('inp_billing_zip_code').value;
		$('delivery_cust_state').value = $('inp_billing_cust_state').value;
		$('delivery_cust_city').value = $('inp_billing_cust_city').value;
		
	}
	if($('chk_cus_del_info').checked==false)
	{
		//$j('#c_d_i').slideDown('slow');	
		$('inp_delivery_cust_name').value = $('inp_billing_cust_name').value;
		$('inp_delivery_cust_address').value = $('inp_billing_cust_address').value;
		$('inp_delivery_cust_tel').value = $('inp_billing_cust_tel').value;
		$('inp_delivery_zip_code').value = $('inp_billing_zip_code').value;
		$('inp_delivery_cust_state').value = $('inp_billing_cust_state').value;
		$('inp_delivery_cust_city').value = $('inp_billing_cust_city').value;
	}
	
}

function update_delivery_information()
{
	if($('chk_cus_del_info').checked==true)
	{
		$j('#c_d_i').slideUp('slow');
		$('inp_delivery_cust_name').value = $('inp_billing_cust_name').value;
		$('inp_delivery_cust_address').value = $('inp_billing_cust_address').value;
		$('inp_delivery_cust_tel').value = $('inp_billing_cust_tel').value;
		$('inp_delivery_zip_code').value = $('inp_billing_zip_code').value;
		$('inp_delivery_cust_state').value = $('inp_billing_cust_state').value;
		$('inp_delivery_cust_city').value = $('inp_billing_cust_city').value;
		
		
		$('delivery_cust_name').value = $('inp_billing_cust_name').value;
		$('delivery_cust_address').value = $('inp_billing_cust_address').value;
		$('delivery_cust_tel').value = $('inp_billing_cust_tel').value;
		$('delivery_zip_code').value = $('inp_billing_zip_code').value;
		$('delivery_cust_state').value = $('inp_billing_cust_state').value;
		$('delivery_cust_city').value = $('inp_billing_cust_city').value;
		
	}
	else
	{
		$j('#c_d_i').slideDown('slow');
		$('inp_delivery_cust_name').value = '';
		$('inp_delivery_cust_address').value = '';
		$('inp_delivery_cust_tel').value = '';
		$('inp_delivery_zip_code').value = '';
		$('inp_delivery_cust_state').value = '';
		$('inp_delivery_cust_city').value = '';	
		
		
		$('delivery_cust_name').value = '';
		$('delivery_cust_address').value = '';
		$('delivery_cust_tel').value = '';
		$('delivery_zip_code').value = '';
		$('delivery_cust_state').value = '';
		$('delivery_cust_city').value = '';

	}
}

function sel(text, schoolid)
{
	$('auto_input').value = text;
	
	$('chosen_school_id').value = "b_school_details.php?b_school_id="+schoolid;
	
	$('sel_options').style.display = 'none';
	
	//$('sel_options').style.display = ;
}

function fetch_autosuggestdata(searchtext, searchby)
{
	
	var url = 'ajax.php?do=fetch_autosuggestdata&searchtext='+searchtext+'&searchby='+searchby+'&rnd='+Math.random();
	new Ajax.Request(url,{
     method: 'get',
     onLoading: function(transport)
     {
		 //	
     },
	 onSuccess: function(transport)
     {
		var dr = transport.responseText;
		if(searchtext!='')		
			$('sel_options_div').innerHTML = dr;
		else
			$('sel_options_div').innerHTML = '';
	 },
     onFailure: function(transport)
     {
         // when the request fails
         alert('The request failed..');
     },
     onException: function(err)
     {
         // When an exception is encountered while executing the callbacks
         alert('Exception');
     }
     });
}

function onEnterKeyPress(e)
{
		var keycode;
		e = e || window.event;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		if (keycode == 13)
			return true;
		else
			return false;	
}

function GetKeyCode(e)
{
	if (e) {
		return e.charCode ? e.charCode : e.keyCode;
	}
	else {
		return window.event.charCode ? window.event.charCode : window.event.keyCode;
	}
}

function onDownArrowKeyPress(e)
{
		/*var keycode;
		e = e || window.event;
		if (window.event) 
		{
			keycode = window.event.keyCode;
		}
		else if (e)
		{
			keycode = e.which;
		}	
		else 
			return true;
		if (keycode == 0)
		{
			$('sel_options').options[0].selected = 'selected';
			
			$('sel_options').focus();
			$('auto_input').blur();
			return true;				
		}
		else
			return false;	*/
			
			
		var unicode = GetKeyCode(e);

		if (unicode == 40) {
			
				$('sel_options').options.selectedIndex = 0;
				$('sel_options').focus();
				return;
			
		}
		if (unicode == 38) {
			
				$('sel_options').options.selectedIndex = $('sel_options').options.length-1;
				$('sel_options').focus();
				return;
			
		}	
			
			
}


//b-school search start
var items_price_total = 0;
var cat_id_outer = '';
function select_all(cat_id, prod_id_list, display_hid, display_span)
	{
		
		var prod_id_arr = prod_id_list.split(',');
		if($(cat_id).checked)
		{
				items_price_total = 0;
				for(var i=0;i<prod_id_arr.length;i++)
				{
					$(cat_id+"_"+prod_id_arr[i]).checked = true;
					items_price_total = parseInt(items_price_total) + parseInt($(cat_id+"_"+prod_id_arr[i]).value);
				}
		}
		else
		{
				for(var i=0;i<prod_id_arr.length;i++)
				{
					$(cat_id+"_"+prod_id_arr[i]).checked = false;
					items_price_total = parseInt(items_price_total) - parseInt($(cat_id+"_"+prod_id_arr[i]).value);
				}
		}
		$(display_span).innerHTML = items_price_total;
		$(display_hid).value = items_price_total;
	}

function set_total(itemid, items_price, display_hid, display_span, cat_ids, prod_id_list, discounted_price, first_subitemid, hid_itemprice_id)
	{
		var cat_id;
		//alert($(hid_itemprice_id).value);
		
		items_price_total = $(hid_itemprice_id).value;
		
		if(cat_ids != cat_id_outer)
		{
			cat_id = cat_ids;
			cat_id_outer = cat_ids;	
		}
		else
		{
			cat_id = cat_id_outer;
		}
		var prod_id_arr = prod_id_list.split(',');
		var count = prod_id_arr.length;
		var count1 = 0;
		for(var i=first_subitemid;i<(parseInt(first_subitemid)+parseInt(prod_id_arr.length));i++)
		{
			
			if($(cat_id+"_"+i).checked==true)	
			{
				count1 = count1 + 1;
			}
		}
		
/*		if(count1==count)
		{
			$(cat_id).checked = true;
			$(display_hid).value = discounted_price;
			$(display_span).innerHTML = discounted_price;
		}
		else
		{*/
			$(cat_id).checked = false;
			
			if($(itemid).checked)
			{
				items_price_total = parseInt(items_price_total) + parseInt(items_price);
			}
			else
			{
				items_price_total = parseInt(items_price_total) - parseInt(items_price);
			}
			
			$(display_hid).value = items_price_total;
			$(display_span).innerHTML = items_price_total;
/*		}
*/		
		
	}
function showallcomments(tipid)
{
		var url = 'ajax.php?do=showallcomments&tipid='+tipid+'&rnd='+Math.random();
		//alert(url);
		new Ajax.Request(url,{
		 method: 'get',
		 onLoading: function(transport)
		{
			$('allcomments').show().update("loading...please wait");
		},
		 onSuccess: function(transport)
		 {
			var dr = transport.responseText;
			if(dr=='no_comments')
			{
				$('allcomments').innerHTML = 'No Comments Found';
				$('allcomments').innerHTML += '<br />Be The First To Comment';
			}
			else	
				$('allcomments').innerHTML = dr;
		},
		 onFailure: function(transport)
		 {
			 // when the request fails
			 alert('The request failed..');
		 },
		 onException: function(err)
		 {
			 // When an exception is encountered while executing the callbacks
			 //alert('Exception');
		 }
		 }); 
		return true;	
}
function moderate_review(str)
{
	var str = str;
	str = str.replace(/&/g, '^');
	str = str.replace(/'/g, '_');
	str = str.replace(/"/g, '~');
	//str = str.replace(/?/g, '`');
	
	return str;
}
function postReview(tip_id)
{
	var reviewTitle = $('review_title').value;
	var reviewText = $('review_text').value;
	
	reviewTitle = moderate_review(reviewTitle);
	reviewText = moderate_review(reviewText);
	
	var flag = true;
	
	if(reviewTitle=='')
	{
		alert('Please enter title.');
		$('review_title').focus();
		flag = false;
	}
	else if(reviewText=='')
	{
		alert('Review Text cannot be left blank');
		$('review_text').focus();
		flag = false;
	}
	else if(reviewText.length<10)
	{
		alert('Min. 10 characters for Review Text.');
		$('review_text').focus();
		flag = false;
	}
	else if($('hidden_rate_val'))
	{
		var rateValue = $('hidden_rate_val').value;
		if(rateValue==0)
		{
			alert('Please rate this tip.');
			flag = false;
		}
	}
	if(flag)
	{
		//$('restaurant_review_rating_input_div').style.display = 'none';
		var url = 'ajax.php?do=postReview&reviewTitle='+reviewTitle+'&reviewText='+reviewText+'&rateValue='+rateValue+'&tip_id='+tip_id+'&rnd='+Math.random();
		
		new Ajax.Request(url,{
		 method: 'get',
		 onLoading: function(transport)
		{
			$('restaurant_review_rating_input_div').show().update("processing...please wait");
		},
		 onSuccess: function(transport)
		 {
			var dr = transport.responseText;
			dr_arr = dr.split('#');
			$('restaurant_review_rating_input_div').style.display = 'block';
			if(dr_arr[0]=='comment_already_done')
				$('restaurant_review_rating_input_div').innerHTML = 'You Have Already Commented On This Tip Earlier.';
			else
			{
				$('restaurant_review_rating_input_div').innerHTML = 'Thanks For Your Comments';
				showallcomments(tip_id);	
			}
		},
		 onFailure: function(transport)
		 {
			 // when the request fails
			 alert('The request failed..');
		 },
		 onException: function(err)
		 {
			 // When an exception is encountered while executing the callbacks
			 //alert('Exception');
		 }
		 }); 
		}
}

function displayProductDetailsPanel(product_id)
{
	var url = 'ajax.php?do=displayProductDetailsPanel&product_id='+product_id+'&rnd='+Math.random();
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
		//$('comm_msg').show().update("processing...please wait");
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		var response = dr.split('#');
		if(response[0] == 'not_loggedin')
			showDiv('div_signin');
		else if(response[0] == 'product_purchased')
		{
			var msg = response[1];	
			$('displayProductDetailsPanel_msg_'+product_id).innerHTML = '<span style="color:#FF2A55;"><b>'+msg+'</b></span>';
			//$('displayProductDetailsPanel_msg').slideDown();
		}
	},
	onFailure: function(transport)
	{
	},
	onException: function(err)
	{
	}
	});
}
function showComments()
{
	if(document.getElementById('post_testimonial').style.display=='none')
	{
		document.getElementById('post_testimonial').style.display='block';
	}
	else
	{
		document.getElementById('post_testimonial').style.display='none';
	}
	document.getElementById('testimonial_msg').style.display='none';

	document.getElementById('sender_name').value = '';
	document.getElementById('sender_email').value = '';
	document.getElementById('sender_text').value = '';
	
}
function isEMailAddr(email) 
{
	
      var str = email;
      var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
       if (!str.match(re))
	    {
        return false;
        }
	   else
	   {
        return true;
       }
}
function postTestimonial()
{
	var sender_name = document.getElementById('sender_name').value;
	var sender_email = document.getElementById('sender_email').value;
	var sender_text = document.getElementById('sender_text').value;
	var flag = true;
	if((sender_name=='') || (sender_email=='') || (sender_text==''))
	{
		alert('all fields are mandatory!');
		flag = false;
	}
	else if(!isEMailAddr(document.getElementById('sender_email').value))
	{
		alert("Verify the email address format.");
		document.getElementById('sender_email').focus();
	   flag = false;
	}
	<!--else if(comm_text.indexOf('#')>0 || comm_text.indexOf('%')>0 || comm_text.indexOf('@')>0 || comm_text.indexOf('!')>0 || comm_text.indexOf('~')>0 || comm_text.indexOf('$')>0 || comm_text.indexOf('^')>0 || comm_text.indexOf('*')>0 || comm_text.indexOf('[')>0 || comm_text.indexOf(']')>0 || comm_text.indexOf('{')>0 || comm_text.indexOf('}')>0 || comm_text.indexOf('|')>0 || comm_text.indexOf('/')>0 || comm_text.indexOf('\\')>0 )
	//{
		//alert('special characters cannot used');
		//flag = false;
	//}-->
	if(flag==true)
	{
			var url = 'ajax.php?do=postTestimonial&sender_name='+sender_name+'&sender_email='+sender_email+'&sender_text='+sender_text+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				$('comm_msg').show().update("processing...please wait");
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				if(dr=='comment_posted_successfully')
				{//alert(dr)
					document.getElementById('testimonial_msg').style.display='block';
					document.getElementById('testimonial_msg').innerHTML = '<b style="color: #FF6600;">Your Testimonial Has Been Received Successfully ! <br />It would be posted soon.</b>';
					document.getElementById('post_testimonial').style.display = 'none';
					//tar_obj_id = 'post_comments_'+id;
					//tar_obj = $(tar_obj_id);
					//setTimeout("tar_obj.style.display='none';", 2000);
					
					//window.location.reload(false);
				}
				else
					document.getElementById('testimonial_msg').innerHTML = '<I>Error in Posting Comment...Post Again</I>';
					document.getElementById('post_testimonial').style.display = 'none';
			},
			onFailure: function(transport)
			{
			},
			onException: function(err)
			{
			}
			});
	}
}
function submit_practicemode_test()
{
	
    window.location='practicemode_res.php';
}
function update_practicemode_result(ans_elem_id, value)
{
	
	
    var url = 'ajax.php?do=update_practicemode_result&ans_elem_id='+ans_elem_id+'&value='+value+'&rnd='+Math.random();
//	alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function displayContent(file_name)
{
	
	var file_name = file_name;
	
    var url = 'ajax.php?do=displayContent&file_name='+file_name+'&rnd='+Math.random();
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		$('display_file').innerHTML = dr;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function fetchfile(topic_id)
{
	
	var topic_id = topic_id;
	
    var url = 'ajax.php?do=selectfile&topic_id='+topic_id+'&rnd='+Math.random();
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		$('filename_span').innerHTML = dr;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
		
}
function selecttype(sub_id)
{
	
	var subject_id = sub_id;

	var url = 'ajax.php?do=selecttopic&subject_id='+subject_id+'&rnd='+Math.random();
	
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		$('topic_span').innerHTML = dr;
	},
	onFailure: function(transport)
	{
		
	},
	onException: function(err)
	{
		
	}
	});

}
function showDiv(str)
{
		var str_arr = str.split('_');
		if(str_arr[1]=='signin')
		{
			$('div_signin').style.display='block';
			$('div_signup').style.display='none';
			$('div_forgetpass').style.display='none';
		}
		if(str_arr[1]=='signinshop')
		{
			$('div_signinshop').style.display='block';
			$('div_signup').style.display='none';
		}
		if(str_arr[1]=='signup')
		{
			$('div_signup').style.display='block';
			$('div_signin').style.display='none';
			$('div_signinshop').style.display='none';
			$('div_forgetpass').style.display='none';
		}
		if(str_arr[1]=='forgetpass')
		{
			$('div_forgetpass').style.display='block';
			$('div_signup').style.display='none';
			$('div_signin').style.display='none';
			$('div_signinshop').style.display='none';
		}
		
		
		$('fade').style.display='block';
}
function closeDiv(str)
{
		var str_arr = str.split('_');
		if(str_arr[1]=='signin')
		{
			$('div_signin').style.display='none';
		}
		if(str_arr[1]=='signinshop')
		{
			$('div_signinshop').style.display='none';
		}
		if(str_arr[1]=='signup')
		{
			$('div_signup').style.display='none';
		}
		if(str_arr[1]=='forgetpass')
		{
			$('div_forgetpass').style.display='none';
		}
		$('fade').style.display='none';
}
function hideLightBox(obj)
{
	obj.style.display='none';
	// close other lightbox elements
	$('div_signin').style.display='none';
	$('div_signup').style.display='none';
	$('div_forgetpass').style.display='none';
}

function signup(first_name,email,pass_word,contact_no,highest_education,currently_in,country,city,country_other,city_other,gerder,age)
{
	
	var first_name = first_name;
	var email = email;
	var username = email;
	var pass_word = pass_word;
	var contact_no = contact_no;
	var highest_education = highest_education;
	var currently_in = currently_in;
	var country = country;
	var city = city;
	var country_other = country_other;
	var city_other = city_other;
	var gerder = gerder;
	var age = age;
	
	
	var url = 'ajax.php?do=signup&first_name='+first_name+'&gerder='+gerder+'&age='+age+'&username='+username+'&pass_word='+pass_word+'&contact_no='+contact_no+'&email='+email+'&highest_education='+highest_education+'&currently_in='+currently_in+'&country='+country+'&city='+city+'&country_other='+country_other+'&city_other='+city_other+'&rnd='+Math.random();
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
		$j('#register_inner').slideUp("slow");
		$('register_outer').show().update('processing...please wait.');
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		
		var dr1 = dr.split("###");
		
		if(dr1[0]=='success')
		{
			//alert(dr1[1]);
			$('register_outer').innerHTML = dr1[1];
			setTimeout("closeDiv('div_signup');", 2000);
		}
		if(dr1[0]=='error')
		{
			$j('#register_inner').slideDown("slow");
			$('register_outer').innerHTML = dr1[1];
		}					
	},
	onFailure: function(transport)
	{
		
	},
	onException: function(err)
	{
		
	}
	});
}

function signin_signout(user_name, pass_word, action)
{
	
	var action = action;
	if(action=='signin')
	{
			var user_name = user_name;
			var pass_word = pass_word;
			
			var url = 'ajax.php?do=signin_signout&user_name='+user_name+'&pass_word='+pass_word+'&action='+action+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				$('login_outer').show().update('please wait...');
				$j('#login_inner').slideUp("slow");
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				responsearray = dr.split("###");
				dr1 = responsearray[0];
				dr2 = responsearray[1];
				
				if(dr1=='Login_Successfull')
				{
					$('login_outer').show().update('successfully loggedin. Redirecting...');
					
					var url = "" + window.location;
					if(url.indexOf('verify') >0)
						setTimeout("closeDiv('div_signin'); window.location.href = 'myprofile.php';", 2000);
					else if(url.indexOf('index.php') >0)
						setTimeout("closeDiv('div_signin'); window.location.href = 'index.php';", 2000);
					else
						setTimeout("closeDiv('div_signin'); window.location.reload();", 2000);
					//setTimeout("closeDiv('div_signin');window.location.href = 'myprofile.php';", 2000);
					
					
				}				
				if(dr1=='User_Not_Verified')
					$('login_outer').show().update('your account is not yet verified. please verify your account by clicking on the link send to your email address: '+dr2);					
					
				if(dr1=='Invalid_Username_Password')
				{
					$j('#login_inner').slideDown("slow");
					$('login_outer').show().update('Invalid username / password');
				}
			},
			onFailure: function(transport)
			{
				
			},
			onException: function(err)
			{
				
			}
			});
	}
	if(action=='signout')
	{
			var url = 'ajax.php?do=signin_signout&action='+action+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				//
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				if(dr=='successfully_loggedout')
				{
					$('logout_div').show().update('you are logged out!');
					$('login_div').style.display = 'block';
					if($('login_div_loginmsg'))
						$('login_div_loginmsg').style.display='none';
					if($('login_div_login'))
						$('login_div_login').style.display='block';
					if($('login_div_loginmsg'))
					{
						$('login_div_loginmsg').innerHTML = '<span id="login_div_loginmsg_logout"><a style="color:#FFFFFF;" href="javascript:void(0);" onclick="javascript:signin_signout(\'\', \'\', \'\', \'signout\');">logout</a></span>';
					}
				}
			},
			onFailure: function(transport)
			{
			},
			onException: function(err)
			{
			}
			});
	}
}

function subject(val)
{
	var Cookies = new CookieHandler();
	var subid = Cookies.getCookie('subid'); // get cookie 'name'
	if(val == -1)
	{
		if(subid == null)
		 subid = 32;
		if(subid != null)
		{
			var id_sub = 0;
			if(subid ==32)
				id_sub = 0;
			
				if(subid ==33)
				id_sub = 1;
				if(subid ==34)
				id_sub = 2;
				if(subid ==36)
				id_sub = 3;
				if(subid ==37)
				id_sub = 4;

			var myselect=document.getElementById("subject_name")
			myselect.options[id_sub].selected=true;

		}
	
	}
	else
	 subid = val; 
	 
	Cookies.setCookie('subid', subid, 1*60*60);
	//alert(subid+' '+val);
	var url = 'ajax.php?do=subject&sub='+subid;
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
		$('show_second').show().update("<div align='center' style='padding-top:100px;'><img src='images/ajax-loader.gif' border='0' /></div>");
		
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		document.getElementById("show_second").innerHTML=dr;
	},
	onFailure: function(transport)
	{
	},
	onException: function(err)
	{
	}
	});
}

function update_ans(opt,ques,ans,level,sub_id)
{
    var url = 'ajax.php?do=update_ans&opt='+opt+'&question='+ques+'&answer='+ans+'&level='+level+'&sub_id='+sub_id;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);return false;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function update_ans_test(opt,ques,ans,test_id,sec)
{
	var time=document.basic_quest.clock.value;
    var url = 'ajax.php?do=update_ans_test&opt='+opt+'&question='+ques+'&answer='+ans+'&sec='+sec+'&test_id='+test_id+'&time_taken='+time;
	//alert(url);return false;
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
		//return false;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function submit_ask(ques_id,key)
 {
	var ask=document.getElementById("ask_doubt_"+key).value;
	
    var url = 'ajax.php?do=ask_doubt&doubt='+ask+'&question='+ques_id+'&key='+key;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		document.getElementById("ask_button_"+dr).style.display='';
		document.getElementById('ask_'+dr).style.display='none';
		alert("Your doubt is submited successfully.");
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
 }
function update_ans_game(opt,ques,ans,dat)
{
    var url = 'ajax.php?do=update_ans_game&opt='+opt+'&question='+ques+'&answer='+ans+'&pub_date='+dat;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function update_ansin_game(opt,ques,ans,dat)
{
    var url = 'ajax.php?do=index_game&opt='+opt+'&question='+ques+'&answer='+ans+'&pub_date='+dat;
	//alert(url);return false;
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}

function show_div_test(str)
 {
	  if(str=='qa')
	   {
		    document.getElementById("view_qa").style.display='';
			document.getElementById("view_va").style.display='none';
			document.getElementById("view_da").style.display='none';
			document.getElementById("link_qa").className="braj";
			document.getElementById("link_va").className="b";
			document.getElementById("link_da").className="b";
	   }
	   else if(str=='va')
	    {
		    document.getElementById("view_qa").style.display='none';
			document.getElementById("view_va").style.display='';
			document.getElementById("view_da").style.display='none';
			document.getElementById("link_qa").className="b";
			document.getElementById("link_va").className="braj";
			document.getElementById("link_da").className="b";
		}
	   else if(str=='da')
	    {
		    document.getElementById("view_qa").style.display='none';
			document.getElementById("view_va").style.display='none';
			document.getElementById("view_da").style.display='';
			document.getElementById("link_qa").className="b";
			document.getElementById("link_va").className="b";
			document.getElementById("link_da").className="braj";
		}
 }
 function show_next_time()
  {
	    var clock_val=document.getElementById("clock_control").value;
	   if(clock_val==1)
	   {
		   document.getElementById("clock_second").style.display='';
		   document.getElementById("clock_control").value=2;
	   }
	   else if(clock_val==2)
	    {
		   document.getElementById("clock_second").style.display='none';
		   document.getElementById("clock_control").value=1;
		}
  }
  
  function show_giv_ans(ques,ans_give,data_set)
  	{

		var url = 'ajax.php?do=show_giv_ans&ques_id='+ques+'&ans_give='+ans_give;
		//alert(url);return false;
		new Ajax.Request(url,{
		method: 'get',
		onLoading: function(transport)
		{
		},
		onSuccess: function(transport)
		{
			var dr = transport.responseText;
			document.getElementById('show_ex').innerHTML=dr;
		},
		onFailure: function(transport)
		{	
		},
		onException: function(err)
		{	
		}
		});
	}
	  function show_giv_test_ans(ques,ans_give,data_set)
  	{

		var url = 'ajax.php?do=show_giv_test_ans&ques_id='+ques+'&ans_give='+ans_give;
		//alert(url);return false;
		new Ajax.Request(url,{
		method: 'get',
		onLoading: function(transport)
		{
		},
		onSuccess: function(transport)
		{
			var dr = transport.responseText;
			document.getElementById('show_ex').innerHTML=dr;
		},
		onFailure: function(transport)
		{	
		},
		onException: function(err)
		{	
		}
		});
	}

function update_ans_section(opt,ques,ans,sec_id)
{
    var url = 'ajax.php?do=update_ans_sec&opt='+opt+'&question='+ques+'&answer='+ans+'&sec_id='+sec_id;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);return false;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function less_count(val)
{
	 if(val=='Prev1')
	 {
	  document.basic_quest.start_count.value=document.basic_quest.start_count.value-(1+1*5);
	  document.basic_quest.submit();
	 }
	 	 if(val=='Prev2')
	 {
	  document.basic_quest.start_count1.value=document.basic_quest.start_count1.value-(1+1*5);
	 // alert(document.basic_quest.start_count.value+"\n"+document.basic_quest.start_count1.value+"\n"+document.basic_quest.start_count2.value);return false;
	  document.basic_quest.submit();
	 }
	 if(val=='Prev3')
	 {
	  document.basic_quest.start_count2.value=document.basic_quest.start_count2.value-(1+1*5);
	  document.basic_quest.submit();
	 }

}
function choose_user(val)
{
	var drop=document.getElementById('test_sel').value;
    var url = 'ajax.php?do=choose_user&user_val='+val+'&test_se='+drop;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		document.getElementById('show_sel').innerHTML=dr;
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function show_sel_test(val)
{
    var url = 'ajax.php?do=selected_test&user_val_send='+val;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
		var str_com=dr.split('*');
		document.getElementById('selected_user_test').innerHTML=str_com[0];
		var str_sec=str_com[1].split('@');
		for(var i=0; i<=str_sec.length;i++)
		 {  
		   if(i!=2&&i!=3)
		  {
			  var var_color=str_sec[i].split('#');
			  if(var_color[1]=='green')
			  {
			 	 var show="<font color='#669900'><br />("+var_color[0]+"%)</font>";
			  }
			  else
			  {
			 	 var show="<font color='#FF0000'><br />("+var_color[0]+"%)</font>";
			  }
			  document.getElementById('per_show_'+i).innerHTML=show;
		   }
		 }
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
}
function signin_signout_1(user_name, pass_word, action)
{
	
	var action = action;
	if(action=='signin')
	{
			var user_name = user_name;
			var pass_word = pass_word;
			
			var url = 'ajax.php?do=signin_signout&user_name='+user_name+'&pass_word='+pass_word+'&action='+action+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				$('login_outer_1').show().update('please wait...');
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				responsearray = dr.split("###");
				dr1 = responsearray[0];
				dr2 = responsearray[1];
				
				if(dr1=='Login_Successfull')
				{
					$('login_outer_1').show().update('successfully loggedin. Redirecting...');
					setTimeout("closeDiv('div_signin');window.location.href = 'myprofile.php';", 2000);
				}				
				if(dr1=='User_Not_Verified')
					$('login_outer_1').show().update('your account is not yet verified. please verify your account by clicking on the link send to your email address: '+dr2);					
					
				if(dr1=='Invalid_Username_Password')
				{
					$('login_outer_1').show().update('Invalid username / password');
				}
			},
			onFailure: function(transport)
			{
				
			},
			onException: function(err)
			{
				
			}
			});
	}
}

function signin_signout_shop(user_name, pass_word, action)
{
	var action = action;
	//alert(action)
	if(action=='signin')
	{
			var user_name = user_name;
			var pass_word = pass_word;
			
			var url = 'ajax.php?do=signin_signout&user_name='+user_name+'&pass_word='+pass_word+'&action='+action+'&rnd='+Math.random();
			new Ajax.Request(url,{
			method: 'get',
			onLoading: function(transport)
			{
				$('login_outer_1_shop').show().update('please wait...');
			},
			onSuccess: function(transport)
			{
				var dr = transport.responseText;
				responsearray = dr.split("###");
				dr1 = responsearray[0];
				dr2 = responsearray[1];
				
				if(dr1=='Login_Successfull')
				{
					$('login_outer_1_shop').show().update('successfully loggedin. Redirecting...');
					setTimeout("closeDiv('div_signin_shop');window.location.href = 'product.php';", 2000);
				}				
				if(dr1=='User_Not_Verified')
					$('login_outer_1_shop').show().update('your account is not yet verified. please verify your account by clicking on the link send to your email address: '+dr2);					
					
				if(dr1=='Invalid_Username_Password')
				{
					$('login_outer_1_shop').show().update('Invalid username / password');
				}
			},
			onFailure: function(transport)
			{
				
			},
			onException: function(err)
			{
				
			}
			});
	}
	
}

function store_billing_shipping_info(	billing_cust_name, billing_cust_address, billing_cust_country, billing_cust_tel, billing_cust_email, billing_zip_code, billing_cust_state, billing_cust_city, delivery_cust_name, delivery_cust_address, delivery_cust_tel, delivery_zip_code, delivery_cust_state, delivery_cust_city	)
{
	
		var url = 'ajax.php?do=store_billing_shipping_info&billing_cust_name='+billing_cust_name+'&billing_cust_address='+billing_cust_address+'&billing_cust_country='+billing_cust_country+'&billing_cust_tel='+billing_cust_tel+'&billing_cust_email='+billing_cust_email+'&billing_zip_code='+billing_zip_code+'&billing_cust_state='+billing_cust_state+'&billing_cust_city='+billing_cust_city+'&delivery_cust_name='+delivery_cust_name+'&delivery_cust_address='+delivery_cust_address+'&delivery_cust_tel='+delivery_cust_tel+'&delivery_zip_code='+delivery_zip_code+'&delivery_cust_state='+delivery_cust_state+'&delivery_cust_city='+delivery_cust_city+'&rnd='+Math.random();
		
		new Ajax.Request(url,{
		method: 'get',
		onLoading: function(transport)
		{
			//$('login_outer_1_shop').show().update('please wait...');
		},
		onSuccess: function(transport)
		{
			var dr = transport.responseText;
		
		},
		onFailure: function(transport)
		{
			
		},
		onException: function(err)
		{
			
		}
		});
	
}


function check_buy(a,b,c,d)
 {
//alert(a+"\n"+b+"\n"+c+"\n"+d);return false;
    var url = 'ajax.php?do=check_purchase_cm&item='+a+'&subitem='+b+'&title='+c+'&sub_nm='+d;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		//alert("bhusan");return false;
		var dr = transport.responseText;
		//alert(dr);
		var dd=dr.split('*');
         if(dd[0]=='grant')
		  {
			   if(dd[1]=='score')
			   	window.location.href='score.php?subj=a'+'&item='+b+'&level='+c+'&su_nm='+d; 
			   else
			    window.location.href='question_show.php?subj=a'+'&item='+b+'&level='+c+'&su_nm='+d;
		  }
		  else
		   {
			    if(dd[0]=='nolog')
				 {
					  var login_start=window.confirm("If you are a registered user then login otherwise register to access this chapter");
					  if(login_start==true)
					   {
						    showDiv('div_signinshop');
					   }
				 }
				 else if(dd[0]=='other')
				 {
					 var mess=window.confirm("Go to our product page and purchase to access this product.");
					 if(mess==true)
					 {
						  window.location='product.php?prod='+a;
					 }
				 }
		   }
	},
	onFailure: function(transport)
	{	
	},
	onException: function(err)
	{	
	}
	});
 }
function previous_view(valshow)
 {
	  if(valshow=='prev1')
	  {
		 if(document.basic_quest.start_count.value==1)
		 {
			  document.basic_quest.start_count.value='';
		 }
		 else
		 {
		 document.basic_quest.start_count.value=document.basic_quest.start_count.value-2;
		 }
	  }
	  if(valshow=='prev2')
	  {
		 if(document.basic_quest.start_count1.value==1)
		 {
			  document.basic_quest.start_count1.value='';
		 }
		 else
		 {
		 document.basic_quest.start_count1.value=document.basic_quest.start_count1.value-2;
		 }
	  }
	  if(valshow=='prev3')
	  {
		 if(document.basic_quest.start_count2.value==1)
		 {
			  document.basic_quest.start_count2.value='';
		 }
		 else
		 {
		 document.basic_quest.start_count2.value=document.basic_quest.start_count2.value-2;
		 }
	  }
 }
 function previous_view_sec()
  {
		 if(document.basic_quest.start_count.value==1)
		 {
			  document.basic_quest.start_count.value='';
		 }
		 else
		 {
		 document.basic_quest.start_count.value=document.basic_quest.start_count.value-2;
		 }
  }
   function previous_view_basic()
  {
		 if((document.getElementById('start_count_basic').value==1) || (document.getElementById('start_count_basic').value==2))
		 {
			  document.getElementById('start_count_basic').value='';
		 }
		 else
		 {
		 document.getElementById('start_count_basic').value=document.getElementById('start_count_basic').value-2;
		 }
  }
   function previous_view_cat()
  {
		 if((document.getElementById('start_count_cat').value==1) || (document.getElementById('start_count_cat').value==2))
		 {
			  document.getElementById('start_count_cat').value='';
		 }
		 else
		 {
		 document.getElementById('start_count_cat').value=document.getElementById('start_count_cat').value-2;
		 }
  }
   function previous_view_solve()
  {
		 if((document.getElementById('start_count_solve').value==1) || (document.getElementById('start_count_solve').value==2))
		 {
			  document.getElementById('start_count_solve').value='';
		 }
		 else
		 {
		 document.getElementById('start_count_solve').value=document.getElementById('start_count_solve').value-2;
		 }
  }
  function show_other(val)
   {
	   if(val=='Other')
	   	{
			document.getElementById('other_country_reg').style.display='';
			document.getElementById('city').style.display='none';
		}
	   else
	   	{
			document.getElementById('other_country_reg').style.display='none';
			document.getElementById('city').style.display='';
		}
   }
   function check_val()
    {
		 if(document.register.first_name.value.search(/\S/)==-1)
		  {
			   alert("Please give your name");
			   document.register.first_name.focus();
			   return false;
		  }
		 if(document.register.email.value.search(/\S/)==-1)
		  {
			   alert("Please give your email here");
			   document.register.email.focus();
			   return false;
		  }

		 if(document.register.pass_word.value.search(/\S/)==-1)
		  {
			   alert("Please give your Password");
			   document.register.pass_word.focus();
		  }

		 if(document.register.contact_no.value.search(/\S/)==-1)
		  {
			   alert("Please give your contact number");
			   document.register.contact_no.focus();
			   return false;
		  }
		 <!--if(document.register.highest_education.value.search(/\S/)==-1)-->
		  <!--{
			  <!-- alert("Please give your highest Education");
			  <!-- document.register.highest_education.focus();
			   <!--return false;
		  <!--}
		<!-- if(document.register.country.value.search(/\S/)==-1)
		  <!--{
			   <!--alert("Please give your country");
			   <!--document.register.country.focus();
			   <!--return false;
		  <!--}
		<!-- if(document.register.city.value.search(/\S/)==-1)
		  <!--{
			   <!--alert("Please give your city of residence");
			   <!--document.register.city.focus();
			   <!--return false;
		  <!--}
		<!-- if(document.register.age.value.search(/\S/)==-1)
		  <!--{
			   <!--alert("Please give your age");
			  <!-- document.register.age.focus();
			 <!--  return false;
		<!-- }
return true;
	}
	function gettime(val_time)
	 {
		//  alert(val_time+"bhusan");
		
	var url = 'ajax.php?do=time_fetch&val_time='+val_time;
	
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
		
		$('clock').value = dr;
		var time_cal=dr.split(':');
		var again_time=parseInt(time_cal[0])*3600+parseInt(time_cal[1])*60+parseInt(time_cal[2])+1;
		//alert(again_time);
		setTimeout("gettime('"+again_time+"')",1000);
	},
	onFailure: function(transport)
	{
		
	},
	onException: function(err)
	{
		
	}
	});
   
	 }
	 
	function getsectime(val_time)
	 {
		 // alert(val_time+"bhusan");
		
	var url = 'ajax.php?do=time_sec_fetch&valsec_time='+val_time;
	//alert(url);
	new Ajax.Request(url,{
	method: 'get',
	onLoading: function(transport)
	{
	},
	onSuccess: function(transport)
	{
		var dr = transport.responseText;
		//alert(dr);
		
		$('clock_sec').value = dr;
		var time_cal=dr.split(':');
		var again_time=parseInt(time_cal[0])*3600+parseInt(time_cal[1])*60+parseInt(time_cal[2])+1;
		//alert(again_time);
		setTimeout("getsectime('"+again_time+"')",1000);
	},
	onFailure: function(transport)
	{
		
	},
	onException: function(err)
	{
		
	}
	});
   
	 }
	 function last_time_taken(var_test_id)
	  {
		   var mess=window.confirm("Submit your answers now?");
					 if(mess==true)
					 {
						var get_last_time=document.getElementById('clock').value;
		  				//window.location='myprofile.php?save_time_fnd='+get_last_time+'&test_id='+var_test_id+'&do=ins_fin_time';
							var url = 'ajax.php?save_time_fnd='+get_last_time+'&test_id='+var_test_id+'&do=ins_fin_time';
							//alert(url);
							new Ajax.Request(url,{
							method: 'get',
							onLoading: function(transport)
							{
							},
							onSuccess: function(transport)
							{
								var dr = transport.responseText;
								alert('Your answer has been submitted. Redirecting to profile page');
								
								setTimeout("window.location.href = 'myprofile.php';", 200);
							},
							onFailure: function(transport)
							{
								
							},
							onException: function(err)
							{
								
							}
							});

					 }
	  }

	 function last_time_taken_sec()
	  {
		   var mess=window.confirm("Submit your answers now?");
					 if(mess==true)
					 {
						 //alert('hh');
						var get_last_time=document.getElementById('clock_sec').value;
						//alert(get_last_time);
		  				//window.location='myprofile.php?save_time_fnd='+get_last_time+'&test_id='+var_test_id+'&do=ins_fin_time';
							var url = 'ajax.php?save_time_fnd='+get_last_time+'&do=ins_fin_time_sec';
							//alert(url);
							new Ajax.Request(url,{
							method: 'get',
							onLoading: function(transport)
							{
							},
							onSuccess: function(transport)
							{
								var dr = transport.responseText;
								alert('Your answer has been submitted. Redirecting to profile page');
								
								setTimeout("window.location.href = 'myprofile.php';", 200);
							},
							onFailure: function(transport)
							{
								
							},
							onException: function(err)
							{
								
							}
							});

					 }
	  }



function CookieHandler() {

	this.setCookie = function (name, value, seconds) {

		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}

		document.cookie = name+"="+value+expires+"; path=/";
	}

	this.getCookie = function (name) {

		name = name + "=";
		var carray = document.cookie.split(';');

		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}

		return null;
	}

	this.deleteCookie = function (name) {
		this.setCookie(name, "", -1);
	}

}
var show_hide = 0;
function show_hide_exp(val)
{
	//alert(val);
	if(show_hide == 0)
	{
		document.getElementById('ans_ex_'+val).style.display='';
		document.getElementById('show_hide_'+val).value='Hide Explaination';
		show_hide = 1;
	}
	else
	{
		document.getElementById('ans_ex_'+val).style.display='none';
		document.getElementById('show_hide_'+val).value='Show Explaination';
		show_hide = 0;
	}
	
}
